PIC32MX Exceptions: Processor Initialization
Starting Up
From a software perspective, Reset is almost the same as a general exception, although it is one from which we're not going to return.
The CPU responds to Reset by entering what's called "bootstrap" mode, starting by fetching instructions from 0xBFC00000. This corresponds (via the MMU) to the physical address 0x1FC00000 in the uncached KSEG1 region.
Following this, only enough of the CPU's control register state (CP0 registers) is defined so that the CPU can execute uncached instructions.
"Enough state" is interpreted minimally, i.e. only 3 things are guaranteed in the CP0 Status register:
- The CPU is in Kernel Mode (StatusEXL=1)
- Interrupt exceptions are disabled (StatusIE=0)
- Bootstrap exceptions (i.e. exceptions occurring during reset) will vector through uncached entry points (StatusBEV=1)
Furthermore, the caches will be in a random, unusable state, as will the memory management unit (MMU).
MPLAB® XC32 Start-Up Code
The job of modifying this initial CPU state to a state that will run your main() code falls to a small assembly language code stub that is automatically inserted by the MPLAB® XC32 compiler.
CPU State on Entry to main()
PIC32MX CP0 and Interrupt Controller registers are initialized by hardware and MPLAB XC32 Compiler start-up code placing the CPU in the following state upon entry to your main() function:
- Ebase = _ebase_address (= 0x9FC01000 for PIC32MX795F512L)
- IntCtlVS<4:0> = 0x01 (Vector spacing is initialized to 32 (0x20) bytes (8 words) between entry points)
- StatusBEV = 0 (Exception vector entry points changed from the "bootstrap" location to the "normal" location)
- General Exceptions: Ebase (= 0x9FC01000) + 0x180
- Interrupt Exceptions: Ebase + 0x200 + (VectNumber * IntCtlVS)
- StatusIE = 0 (Interrupt Exceptions Disabled)
- StatusIPL<2:0> = 0 (CPU running @ priority level 0)
- INTCONMVEC = 0 (Interrupt controller configured for single-vector mode)
- Prefetch Cache is disabled
- KSEG0 cacheability is disabled
- PFM Wait States = 7 (max. setting)
- Data Ram Wait States = 1 (max. setting)