Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

8.6.1. Writing an Instruction-Related Exception Handler

The prototype for an instruction-related exception handler is as follows:
alt_exception_result handler ( 
 alt_exception_cause cause,
 alt_u32 addr,
 alt_u32 bad_addr );

The instruction-related exception handler’s return value is a flag requesting that the HAL either re-execute the instruction, or skip it.

The HAL exception funnel calls the instruction-related exception handler with the following arguments:

  • cause—A value representing the exception type, as shown in the "Nios II Exception Cause Codes" table (Table 8–4)
  • addr—Instruction address at which exception occurred
  • bad_addr—Bad address register (if implemented)

Include the following header file in your instruction-related exception handler code:

#include “sys/alt_exceptions.h”

alt_exceptions.h provides type macro definitions required to interface your instruction-related exception handler to the HAL, including the cause codes shown in the "Nios II Exception Cause Codes" table (Table 8–4).

The API function alt_exception_cause_generated_bad_addr() is provided by the HAL, for the use of the instruction-related exception handler. This function parses the cause argument and determines if bad_addr contains the exception-causing address.

For more information about Nios II processor exception causes, refer to “Exception Processing” in the "Programming Model" chapter of the Nios II Processor Reference Handbook.