PIC32MZ Coprocessors
The MIPS® standard register set omits many features needed for a real Microcontroller (MCU) (i.e. exception handling), however, op-codes are reserved and instruction fields are defined for up to 4 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.
- Coprocessor 2 (CP2) is available for specific implementations.
- Coprocessor 3 (CP3) is reserved for the Floating Point Unit (FPU) in Release 1 implementations of the MIPS64® Architecture and in all Release 2 (and subsequent releases) implementations of the architecture.
PIC32MZ Coprocessor 0 (CP0) Registers
The PIC32MZ 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:
- Translation Lookaside Buffer (TLB)
- 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:
mtc0 zero, Count
mtc0 a0, Compare
The following example reads the value of the exception cause register into s0:
mfc0 s0, Cause
Table 50-23 in the PIC32MZ Family Reference Manual Section 50. CPU for Devices with MIPS32® microAptiv™ and M-Class Cores outlines the CP0 registers found on PIC32MZ devices and is the accompanying images.
Which CP0 Registers Are Relevant When?
After power-up:
- You'll need to set up 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.
PIC32MZ Coprocessor 1 (CP1) Registers
There are five Coprocessor 1 (CP1) registers, also referred to as FPU Control Registers (FCRs), that are used to control the FPU. These registers are 32 bits wide: FIR, FCCR, FEXR, FENR, FCSR. Three of these registers: FCCR, FEXR, and FENR will select subsets of the FCSR, the floating point Control/Status register.
The CP1 registers are summarized in Table 50-32 in Section 50. CPU for Devices with MIPS32® microAptiv™ and M-Class Cores and are reproduced in the accompanying image: