Exception Mechanism

On MIPS-based CPUs, such as the PIC32MX family of processors, peripheral/external interrupts, traps, system calls, and everything else that can disrupt the normal flow of execution are called "exceptions" and are handled by a single mechanism.

exception-block-diagram.png

Exceptions are classified into two major types: expected and unexpected:

  • Expected - Resulting from normal (i.e., expected) operations, such as:
    • Peripheral/External Interrupts
    • WDT wakeup
    • Debug breakpoints
    • System calls
  • Unexpected - Resulting from error (i.e., unexpected) conditions such as:
    • Hardware-detected errors, such as integer overflow or divide-by-zero
    • Illegal user-mode operations
    • Bus error (addresses generated beyond physically implemented memory)

The main difference between expected/unexpected exceptions is that an unexpected exception cannot be enabled/disabled (similar to a traditional Non-Maskable Interrupt (NMI)), while an expected exception can be.

Unexpected exceptions resulting directly from the execution of the program are referred to as execution exceptions, or simply as "traps". For example:

  • execution of instruction causing integer overflow or undefined result (ex., divide by 0)
  • execution of the "trap" instruction
  • a reserved or undefined opcode is executed

All exceptions are handled similarly, in that, the current instruction flow is changed temporarily to execute special procedures to handle the exception.

When an exception is detected, the CPU Execution Unit does the following:

  • The address of the next instruction to execute after the handler returns is saved into the EPC register of Coprocessor0 (CP0).
  • The CP0 CauseEXCCODE bit-field is updated to reflect the reason for exception or interrupt.
  • The CP0 StatusEXL or StatusERL bit is set to cause Kernel mode execution.
  • An exception handler entry point address is obtained based on the type of exception and the current state of the processor (CP0 Statusxxx bits).
  • Processor starts execution from the exception handler's entry point address.

The exception handler routine must generate a prologue and an epilogue to configure, save and restore all of the core registers, along with the CPU General Purpose Registers (if not using a shadow register set).

Interrupt Controller

The PIC32MX hardware generates interrupt exception requests in response to interrupt events coming from the peripheral modules of the CPU Core (Core Timer, Performance Counter, Fast Debug Channel).

The Interrupt Controller module exists external to the CPU Execution Unit and prioritizes the interrupt requests before presenting one of them to the CPU. The module includes the following features:

  • Up to 96 interrupt sources
  • Up to 64 interrupt vectors
  • Single and Multi-Vector mode operations
  • Up to five external interrupts with edge polarity control
  • Interrupt proximity timer
  • Seven user-selectable priority levels for each vector
  • Four user-selectable sub-priority levels within each priority
  • Dedicated shadow register set for user-selected priority level (this feature is not available on all devices; refer to the “Interrupt Controller” chapter in the specific device data sheet for availability)
  • Software can generate any interrupt
  • User-configurable Interrupt Vector Table (IVT) location
  • User-configurable interrupt vector spacing

Exception system configuration is managed through two sets of control registers:

  • One in the Interrupt Controller,
  • And the other in the CPU Coprocessor0 (CP0) register set.


To avoid confusion, The PIC32MX family documentation provides a typographic distinction for these registers:

  • Interrupt Controller register names are signified by upper-case letters only (i.e. INTSTAT, INTCON)
  • CP0 register names are signified by upper and lower-case letters (i.e., IntCtl, Ebase)
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.