PIC32MX Exception Entry Points
Contents
The Reset, Soft Reset, and NMI exceptions are always vectored to location 0xBFC00000 (uncached, start-up safe KSEG1 region). Addresses for all other exceptions are a combination of a vector base address and a vector offset.
Exception Vector "Base" Addresses
In MIPS32® Release 2 and higher architectures, the software is allowed to specify the vector base address via the CP0 Ebase register for exceptions that occur when CP0 StatusBEV equals 0.
The following table gives the vector base address as a function of the exception and whether the BEV bit is set in the Status register:
Vector "Offsets"
Next, we have fixed vector offsets, which are added to the above exception base addresses as a function of the exception:
"Final" Entry Point Addresses
PIC32MX interrupt exception vector addresses have an additional computed offset component, which is added to Ebase and the fixed offset (0x200).
- Computed Offset = Interrupt Vector Number (0-63) * Interrupt Vector Spacing (as defined by CP0 register/bitfield IntCtlVS)
We can now list the complete vector addresses for the most common exceptions (not incl. EJTAG or TLB exceptions):
Interrupt Exception Vectors
As discussed above, PIC32MX interrupt controllers operating in Multi-Vector Mode implement a "computed offset" mode for calculating the final interrupt vector address:
- Interrupt Exception Vector Final Address = Ebase + 0x200 + (VectNum * IntCtlVS)
The MPLAB XC32 Compiler calculates & initializes the vector address for each defined application interrupt service routine (see Table 7.1 in the PIC32MX datasheet for a listing of vector numbers assigned to each interrupt source).
Example
The following example illustrates how the Timer 2 Interrupt Vector Entry Point is calculated/initialized.
Ebase
- 0x9FC01000 (initialized by the C-Run-time startup)
IntCtlVS
- 0x01 (Interrupt Vector Spacing = 32 bytes (0x20) - initialized by the default C-Run-time startup code)
Timer 2 Interrupt Vector Number
- 8 (from Table 7.1)
Timer 2 Interrupt Exception Vector Final Address
- 0x9FC01000 + 0x200 + (8 * 32) = 0x9FC01300
In most cases, since the spacing between interrupt exception vectors is insufficient to hold the entire handler routine, the compiler will insert an unconditional jump to the start address of the handler routine as shown in this example:
An interrupt handler function can be associated with an interrupt vector either as the target of a dispatch function located at the exception vector address (as shown in the above example) or as being located directly at the exception vector address.
Handler functions that are linked directly to the vector will be executed faster. Although the vector spacing can be adjusted, there is limited space between vectors, and linking a substantial handler function directly at a vector may cause it to overlap the higher vector locations, preventing their use. In such situations, using a dispatch function is a safer option.
MPLAB XC32 start-up code initializes IntCtlVS to the value defined by the symbol _vector_spacing in the PIC32MX device linker script (for PIC32MX795F512L, _vector_spacing = 0x00000001, which corresponds to the spacing of 32 bytes or eight words), however, by using function attributes, a handler can be located directly at the vector address. See the MPLAB XC32 User's Manual for details.