1.2 T32-only execution and core registers
Armv8-M executes only T32 (Thumb) instructions. A32 state does not exist. The architecture still keeps a Thumb state bit, EPSR.T. It must be 1 whenever an instruction executes. If T is 0 when the core tries to execute an instruction, the result is an INVSTATE UsageFault (Mainline) or a HardFault (Baseline, which has no UsageFault).
T is written by:
- interworking branches, from bit[0] of the target address:
BX,BLX, andPOP/LDM/LDRinto PC - vector table fetches on exception entry and on reset, from bit[0] of the vector entry
- exception return, which restores EPSR.T from bit[24] of the stacked xPSR
For example, if a vector table entry has bit[0] clear, the exception entry itself completes and the core branches to the handler with T = 0. The fault happens when it tries to execute the handler’s first instruction. UsageFault is disabled out of reset (SHCSR.USGFAULTENA = 0), so on Mainline this fault escalates to HardFault.
Core registers
R0-R12are general purpose. Many 16-bit encodings can only reachR0-R7.R13= SP. It is banked: MSP and PSP, and with the Security Extension a Secure and a Non-secure copy of each.R14= LR. On exception entry the hardware loads it with an EXC_RETURN value instead of a real return address.R15= PC.
xPSR is three views of one register:
APSR : N Z C V, Q (Main Ext), GE[3:0] (DSP Ext)
IPSR : exception number of the active exception (0 = Thread mode)
EPSR : T bit, ICI/IT state (v8.1-M adds further execution-state fields)
MRS can read APSR, IPSR or the combined views. EPSR fields read as zero through MRS, and MSR writes to them are ignored. Software therefore cannot read T or write it with MSR. Only interworking branches, exception entry and exception return change it.
Coming from A-profile: In AArch64, saved PSTATE lives in SPSR_ELx and the syndrome in ESR_ELx, and there is no interworking. On M-profile, bit[0] of every code pointer matters. A vector address with bit[0] clear is not an alignment hint. It is a fault waiting to happen.
Checkpoint
Q1.2.1 On a Mainline core straight out of reset, the SysTick vector entry holds 0x00001200 (bit[0] clear). SysTick fires. What happens?
- A. The handler runs correctly. The hardware ignores bit[0] of vector entries.
- B. The exception entry is aborted and the core enters Lockup.
- C. The core switches to A32 state and executes the handler as A32 code.
- D. The core enters the handler with EPSR.T = 0, and its first instruction raises an INVSTATE UsageFault. UsageFault is disabled at reset, so this escalates to HardFault.
Answer
D. Vector fetches copy bit[0] into EPSR.T. Entry completes, and the fault happens when the core attempts the handler’s first instruction. UsageFault is disabled by default, so it escalates to HardFault. There is no A32 state on M-profile. Lockup would only follow if the HardFault vector were also broken, or if the fault happened at HardFault/NMI priority.
Read more: Armv8-M ARM (DDI0553), Exception entry: vector table and EPSR.T; UsageFault INVSTATE
Q1.2.2 A debug routine runs MRS r0, XPSR from C to check that the core is in Thumb state, by testing bit 24 (EPSR.T). What does it observe?
- A. Bit 24 reads 0, because EPSR fields read as zero through MRS.
- B. Bit 24 reads 1, because the core is always in Thumb state.
- C. The MRS instruction faults, because EPSR is accessible only to a debugger.
- D. Bit 24 reflects the Thumb state only in Handler mode.
Answer
A. The architecture defines EPSR bits as reading as zero when accessed with MRS, so software cannot observe T this way. It is tempting to expect 1 because the core is in fact executing T32. A debugger can see the real value through the debug register interface, and stacked xPSR values in an exception frame also contain T.
Read more: Armv8-M ARM (DDI0553), xPSR / EPSR description and MRS pseudocode
Q1.2.3 On exception entry, what does LR hold when the handler starts?
- A. The address of the interrupted instruction
- B. An EXC_RETURN value that encodes return information such as mode, stack and security state. Loading it into PC performs the exception return.
- C. Zero. The return address is only on the stack.
- D. The vector table address of the handler
Answer
B. The hardware writes an EXC_RETURN value (top byte 0xFF) into LR. Writing it to PC in Handler mode (BX LR, or POP {pc}) triggers the exception return sequence. The real return address is in the stacked frame, so expecting it in LR (the ELR-like assumption) is wrong.
Read more: Armv8-M ARM (DDI0553), EXC_RETURN