Nios® V Processor Software Developer Handbook

ID 743810
Date 4/07/2025
Public
Document Table of Contents

9.2.2.2.3. Exception Dispatcher

Upon an exception, the CLINT-Vectored passes control to the exception dispatcher in vector table. As stated in the RISC-V specification, the exception dispatcher is at the vector table base address.

The exception dispatcher performs the following tasks:
  • Switches to the separate exception stack (if enabled)
  • Stores register values onto the stack
    • Stores all register values if the shadow register is disabled
    • Stores the lower 16 general-purpose registers only if the shadow register is enabled. (This is not implemented in Altera HAL firmware.)
  • Checks for a registered instruction-related exception handler.
  • If an instruction-related handler is registered, the exception dispatcher calls it, then restores context and returns.
  • If no instruction-related exception handler is registered,
    • If processor debug module is enabled, the processor enters Debug Mode using the ebreak instruction. Allowing the debugger to take control.
    • If there is no debug module, the processor enters an infinite loop.

Once the exception is serviced, and the exception handler returns to the exception dispatcher, it performs the following tasks:

  • Restores the registers from the stack
    • Restores all the registers if the shadow register is disabled
    • Restores the lower 16 general-purpose registers only if the shadow register is enabled. (This is not implemented in Altera HAL firmware.)
  • Restores the stack pointer (if a separate exception stack is used)
  • Exits by issuing an MRET (exception return in machine mode) instruction
Figure 22. Exception Dispatcher

For more information on registering an instruction-related exception handler, refer to the Instruction-Related Exception Handler chapter.

For more information about the RISCV-based processor EBREAK instruction, refer to the The RISC-V Instruction Set Manual in RISC-V International website.