NIOS II: Internals

Internals

.section .exceptions.irqhandler, "xa"
/*
 * Now that all necessary registers have been preserved, call 
 * alt_irq_handler() to process the interrupts.
 */

call alt_irq_handler
/*
 * Prepare to service unimplemtned instructions or traps,
 * each of which is optionally inked into section .exceptions.soft,
 * which will preceed .exceptions.unknown below.
 *
 * Unlike interrupts, we want to skip the exception-causing instructon
 * upon completion, so we write ea (address of instruction *after*
 * the one where the exception occured) into 72(sp). The actual
 * instruction that caused the exception is written in r2, which these
 * handlers will utilize.
 */
stw   ea,  72(sp)  /* Don't re-issue */
ldw   r2, -4(ea)   /* Instruction that caused exception */
/*
 * The C-based HAL routine alt_instruction_exception_entry() will
 * attempt to service the exception by calling a user-registered
 * exception handler using alt_instruction_exception_register().
 * If no handler was registered it will either break (if the
 * debugger is present) or go into an infinite loop since the
 * handling behavior is undefined; in that case we will not return here.
 */

/* Load exception-causing address as first argument (r4) */
addi   r4, ea, -4

/* Call the instruction-exception entry */
call   alt_instruction_exception_entry
/*
 * This is the entry point for instruction-generated exceptions handling.
 * This routine will be called by alt_exceptions_entry.S, after it determines
 * that an exception could not be handled by handlers that preceed that
 * of instruction-generated exceptions (such as interrupts).
 *
 * For this to function properly, you must register an exception handler
 * using alt_instruction_exception_register(). This routine will call
 * that handler if it has been registered. Absent a handler, it will
 * break break or hang as discussed below.
 */
int alt_instruction_exception_entry (alt_u32 exception_pc)
{
  alt_u32 cause, badaddr;
/*
 * Catch any unhandled exception from the HAL layer.
 */

#include <stdint.h>

#include <system.h>
#include <sys/alt_exceptions.h>

#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API

unsigned int spurious_ints;

static alt_exception_result
unhandled_exception (alt_exception_cause cause,
                     uint32_t exception_pc,
                     uint32_t bad_addr)
{
  ++spurious_ints;
  return NIOS2_EXCEPTION_RETURN_REISSUE_INST;
}

#endif

void
init_uhe (void)
{
#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API
  alt_instruction_exception_register (unhandled_exception);
#endif
}

Leave a Reply

Your email address will not be published. Required fields are marked *