| |||
| Home > VFP System Initialization > Set up the undefined mode stack | |||
As at least some of the VFP Support Code executes in undefined instruction mode, it is necessary to have an undefined mode stack set up. In a fully embedded system that runs from reset, then this is likely to have been done within the initialization code.
VFP Support Code is not needed in VFPv3-based systems.
In the case of early development code downloaded via a debugger, then a simple function can be called to set up the stack. The following assembler code example shows how this can be done. Note that this must be executed in a privileged mode.
Mode_UNDEF EQU 0x1B ; bit pattern for undefined mode IF :DEF: SETUP_UNDEF_STACK EXPORT Setup_Undef_Stack Setup_Undef_Stack FUNCTION ; Now set up a stack for undefined mode MRS r0, CPSR ; get CPSR value MOV r1, r0 ; take a working copy ORR r1,r1, #Mode_UNDEF ; set mode bits for Undefined mode MSR CPSR_c, r1 ; change to undefined mode IF :DEF: RWPI LDR r2, UNDEF_Stack_Offset ADD SP, r2, r9 ELSE LDR SP, =UNDEF_Stack ; set up the stack pointer ENDIF MSR CPSR_c, r0 ; change back to the original mode BX LR ; return from subroutine ENDFUNC IF :DEF: RWPI UNDEF_Stack_Offset DCDO UNDEF_Stack ENDIF ENDIF IF :DEF: SETUP_UNDEF_STACK ; Location for undefined-mode stack AREA UNDEF_STACK, NOINIT, ALIGN=3 % 8 ; Only two words will be used UNDEF_Stack EQU . ENDIF END
The support code runs largely in SVC mode and only a small amount of stack space is required for undefined mode operation. This means that you also have to ensure that you have the SVC mode stack set up (though this is normally the case). See section 7 for more details.