2.4 Tail-chaining, late-arrival and lazy FP state preservation
Tail-chaining: a handler executes its exception return, and at that point a pending exception has a group priority higher than the execution priority of the context being returned to. The architecture permits the PE to enter the new handler directly, without unstacking the frame and stacking it again. The frame on the stack still describes the original interrupted context. Cortex-M implementations do this.
Late-arrival: a higher-priority exception arrives while the PE is still stacking for a lower-priority one. The PE can keep the frame being stacked and fetch the vector of the higher-priority exception. The lower-priority exception stays pending and is usually tail-chained afterwards.
Lazy FP preservation (Floating-point Extension, which requires the Main Extension). The controls are in FPCCR, some of whose bits are banked per Security state:
ASPEN: when 1, executing an FP instruction setsCONTROL.FPCA. With FPCA = 1 at entry, the PE builds an extended frame (EXC_RETURN.FType = 0). If ASPEN = 0, software manages FPCA and FP context itself.LSPEN: when 1 (and FPCA = 1 at entry), the PE reserves space for S0-S15 and FPSCR in the frame but does not write them. It records that address inFPCARand setsLSPACT = 1.- If the handler then executes an FP instruction while LSPACT = 1, the PE first stores the interrupted context’s FP registers into the reserved space. It then clears LSPACT, and the instruction proceeds.
- On return with an extended frame: if LSPACT is still 1, the FP registers were never saved and still hold the interrupted context’s values. The PE clears LSPACT and does not reload them. Otherwise it unstacks them from the frame.
Integer-only handlers therefore pay for the reserved stack space but not for the memory traffic. The interrupted stack must still have room for the extended frame.
Coming from A-profile: In A-profile, lazy FP/SIMD switching is an OS policy that traps FP accesses through CPACR_EL1.FPEN and handles the trap in software. On M-profile the PE does it in hardware, within the exception entry and return, using FPCAR and LSPACT.
Checkpoint
Q2.4.1 FPCCR.ASPEN = 1, LSPEN = 1. A Thread executed a VADD.F32 (so CONTROL.FPCA = 1) and is interrupted by an IRQ whose handler uses no FP instructions. What happens to S0-S15 and FPSCR?
- A. They are written to the stack on entry and read back on return
- B. They are not preserved at all, because the handler does not use FP
- C. Space is reserved in an extended frame, FPCAR points to it and LSPACT is set. The registers are never written, and on return LSPACT is cleared without reloading them
- D. They are copied to a dedicated FP shadow bank inside the FPU
Answer
C. With LSPEN = 1, entry only reserves space and arms LSPACT. Because the handler never touched FP, the live registers still hold the Thread’s values, and the return only clears LSPACT. Eager save and restore is what happens with LSPEN = 0. The ‘not preserved’ option ignores that FPCA = 1 still forces an extended frame.
Read more: Armv8-M ARM (DDI0553), Lazy Floating-point context preservation; FPCCR, FPCAR
Q2.4.2 In the same setup, the IRQ handler later executes a VMUL.F32. What happens immediately before that instruction executes?
- A. The PE stores the interrupted context’s FP registers into the space at FPCAR and clears LSPACT, then executes the VMUL
- B. A NOCP UsageFault is raised so that software can save the FP context
- C. Nothing, because the handler simply overwrites the Thread’s S registers
- D. The PE writes the handler’s FP registers to FPCAR
Answer
A. The first FP instruction executed while LSPACT = 1 triggers the deferred save of the interrupted context, then the instruction executes. Faulting so that software saves the context is the A-profile trap-and-save model; NOCP on M-profile indicates the coprocessor is disabled or inaccessible, not a lazy-save trap.
Read more: Armv8-M ARM (DDI0553), Lazy Floating-point context preservation; UFSR.NOCP
Q2.4.3 Handler A (group priority 0x40) interrupted Thread mode and is now returning. IRQ B (group priority 0x80) is pending, and no masks are set. What happens?
- A. B waits until at least one Thread instruction has executed
- B. B is taken by tail-chaining: the PE enters B’s handler without unstacking and restacking the Thread’s frame
- C. B is not taken, because 0x80 is lower priority than the returning handler A
- D. The Thread’s frame is unstacked, then a new frame is stacked for B
Answer
B. At the return, B is compared with the execution priority of the context being returned to, which is Thread mode with no boost. B beats that, so it is tail-chained and reuses the existing frame. Comparing against A is the tempting mistake, because A is no longer active at that point.
Read more: Armv8-M ARM (DDI0553), Exception return; tail-chaining