Overview

The action taken by the overflow exception handler subroutine depends upon the requirements of the system. For systems running larger or more complex code, the overflow and underflow handlers can implement a virtual register file that extends beyond the limits of the physical register file. When an overflow occurs, such an overflow handler might (for example) reload the entire contents of the physical register file from the stack and restart CWP back at LO_LIMIT. Many embedded systems, on the other hand, might wish to tightly control stack usage and subroutine call depth. Such systems might implement an overflow handler that prints an error message and exits the program.

The programmer determines the nature of and actions taken by the register window overflow exception handler. The Nios SDK automatically installs by default a register window overflow handler which virtualizes the register file using the stack.

A register window overflow exception can only be generated by a RESTORE instruction. Directly writing CWP (via a WRCTL instruction) to a value greater than HI_LIMIT will not cause a register window overflow exception. Executing a RESTORE instruction when CWP is already above HI_LIMIT will not generate a register window overflow exception.

Direct Software Exceptions (TRAP Instructions)

Software can directly request that control be transferred to an exception handler by issuing a TRAP instruction. The IMM6 field of the instruction gives the exception number. TRAP instructions are always processed, regardless of the setting of the IE or IPRI bits. TRAP instructions do not have a delay slot. The instruction immediately following a TRAP is not executed before control is transferred to the indicated exception-handler. A reference to the instruction following TRAP will be saved in %o7, so that a TRET instruction will transfer control back to the instruction following TRAP at the conclusion of exception processing.

Exception Processing Sequence

When an exception is processed from any of the sources mentioned above, the following sequence occurs:

1.The contents of the STATUS register are copied into the ISTATUS register.

2.CWP is decremented, opening a new window for use by the exception-handler routine (This is not the case for register window underflow exceptions, where CWP was already decremented by the SAVE instruction that caused the exception).

1

Overview

Altera Corporation

19

Page 31
Image 31
Excalibur electronic A-MNL-NIOSPROG-01.1 manual Direct Software Exceptions Trap Instructions, Exception Processing Sequence