18.2.1 Switch to the Selected Instruction Set (ISA) Mode

Some PIC32 MCUs support both the MIPS32 and microMIPS Instruction Set Architecture (ISA) modes. The microMIPS instruction set delivers the same functionality as the MIPS32 ISA, with the added benefit of smaller code size.

Devices that support both the MIPS32 and microMIPS ISA modes use the BOOTISA configuration bit in a device Configuration Word to determine the ISA mode on boot. The device can be configured to boot to either the MIPS32 or the microMIPS ISA mode. See the target-device data sheet for more information on the BOOTISA bit.

The microMIPS ISA supplies assembler-source code compatibility with MIPS32 instead of binary compatibility. Because of this, the XC32 toolchain provides a copy of the runtime start-up code compiled for the MIPS32 ISA as well as a copy compiled for the microMIPS ISA. The toolchain determines which copy to link based on the presence of the -mmicromips command-line option. In the MPLAB X IDE project properties, select xc32-ld >Option category: Libraries> "Link microMIPS compressed startup code and libraries" to get the -mmicromips option.

For added flexibility, the default start-up code attempts to ensure that the linked Precompiled mode matches the current ISA mode at runtime. To enable this, a binary code sequence is required that can be run in either instruction set and change code paths, depending on the instruction set that is being used.

The following binary sequence achieves this goal:

  0x1000wxyz  // where w,x,y,z represent hexadecimal digits
  0x00000000

For the MIPS32 instruction set, this binary sequence is interpreted as:

  // branch to location of more MIPS32 instructions 
  BEQ $0, $0, wxyz 
  NOP 

For the microMIPS instruction set, this binary sequence is interpreted as:

  ADDI32 $0, $0, wxyz // do nothing
  NOP                 // fall through to more microMIPS instructions

In the default runtime startup-code, we place this binary sequence at the _reset symbol, which is then located at the reset vector by the default linker script. We follow this binary sequence with a jal _startup to jump to the remainder of the startup code.

This sequence is included only for devices that support both the MIPS32 and microMIPS ISA modes.

On PIC32M devices, bit 0 of the address indicates the ISA mode. When this bit is clear, the device is running in MIPS32 Mode. When this bit is set, the device is running in either MIPS16 or microMIPS mode, depending on the device core. This means that if you execute a hard-coded jump, bit 0 must be set to the appropriate value for your target function. Hard-coded jumps are most commonly seen when jumping from a bootloader to a bootloaded application.