PIC32MX Coprocessors
The MIPS® standard register set omits many features needed for a real MCU (i.e. exception handling), however, op-codes are reserved and instruction fields are defined for up to four coprocessors which may be included in a MIPS implementation:
- Coprocessor 0 (CP0) is incorporated on the CPU chip and supports the virtual memory system and exception handling. CP0 is also referred to as the System Control Coprocessor.
- Coprocessor 1 (CP1) is reserved for the floating-point coprocessor, the FPU.
- Coprocessor 2 (CP2) is available for specific implementations.
- Coprocessor 3 (CP3) is reserved for the floating-point unit in Release 1 implementations of the MIPS64® Architecture and in all Release 2 (and subsequent releases) implementations of the architecture.
PIC32MX Coprocessor 0 (CP0) Registers
The MIPS M4K® CPU in the PIC32MX uses a special register interface to communicate status and control information between system software and the CPU. This interface is called Coprocessor 0, or CP0. The features of the CPU that are visible and controllable through the Coprocessor 0 register interface are:
- Core timer
- Interrupt and exception control
- Virtual memory configuration
- Shadow register set control
- Processor identification
- Debugger control
- Performance counters
System software accesses the registers in CP0 using coprocessor instructions such as mfc0 (move from coprocessor 0 register) and mtc0 (move to coprocessor 0 register).
The following example clears the core timer counter register and initializes its period register with the value in a0:
2
mtc0 a0, Compare
The following example reads the value of the exception cause register into s0:
Which CP0 Registers Are Relevant When?
After power-up:
- You'll need to setup Statusxxx bits to get the CPU into a workable state for the rest of the bootstrap procedure.
- The first Config register has a few writable bits which you may need to set in order for anything to work.
- Handling an exception:
- On entry, no program registers have been saved, only the restart address in EPC.
- Handler code must save EPC and Status context for nested interrupt operation.
- For general exceptions, consult the Cause register to find out what kind of exception it was and dispatch accordingly.
- Returning from exception:
- Control must eventually be returned to the value stored in EPC on entry.
- The Status register must be adjusted on exit, restoring the user-privilege CPU state (if required) and re-enabling exceptions respectively.
- Interrupt exceptions:
- StatusIE: acts as the master enable for hardware/software interrupt exceptions.
- StatusIPL: contains the current CPU priority level. Software can write to these bits at any time, changing the priority of the CPU.