ARM Cortex-M3 Technical Reference Manual page 111

Hide thumbs Also See for Cortex-M3:
Table of Contents

Advertisement

ARM DDI 0337B
Example 5-5 shows how to implement a simple context switcher after the switch to
Thread on PSP.
; Example Context Switch (Assumes Thread is already on PSP)
MRS r12, PSP
STMDB r12!, {r4-r11}
LDR r0, =OldPSPValue
STR r12, [r0]
LDR r0, =NewPSPValue
LDR r12, [r0]
LDMIA r12!, {r4-r11}
MSR PSP, r12
BX lr
Note
For Example 5-4 on page 5-24 and Example 5-5 the only time the decision to move
Thread from MSP to PSP can be made, or the non-stacked registers can be guaranteed
not to have been modified by a stacked Handler, is when there is only one ISR/Handler
active.
Copyright © 2005, 2006 ARM Limited. All rights reserved.
Example 5-5 Implement a simple context switcher
; Recover PSP into R12
; Push non-stack registers
; Get pointer to old Thread Control Block
; Store SP into Thread Control Block
; Get pointer to new Thread Control Block
; Acquire new Process SP
; Restore non-stacked registers
; Set PSP to R12
; Return back to Thread
Exceptions
5-25

Advertisement

Table of Contents
loading

Table of Contents