2 EXTERN ulCriticalNesting
\r
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
5 ; Context save and restore macro definitions
\r
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
8 portSAVE_CONTEXT MACRO
\r
10 ; Push R0 as we are going to use the register.
\r
13 ; Set R0 to point to the task stack pointer.
\r
19 ; Push the return address onto the stack.
\r
22 ; Now we have saved LR we can use it instead of R0.
\r
25 ; Pop R0 so we can save it onto the system mode stack.
\r
28 ; Push all the system mode registers onto the task stack.
\r
33 ; Push the SPSR onto the task stack.
\r
37 LDR R0, =ulCriticalNesting
\r
41 ; Store the new top of stack for the task.
\r
42 LDR R1, =pxCurrentTCB
\r
49 portRESTORE_CONTEXT MACRO
\r
51 ; Set the LR to the task stack.
\r
52 LDR R1, =pxCurrentTCB
\r
56 ; The critical nesting depth is the first item on the stack.
\r
57 ; Load it into the ulCriticalNesting variable.
\r
58 LDR R0, =ulCriticalNesting
\r
62 ; Get the SPSR from the stack.
\r
66 ; Restore all system mode registers for the task.
\r
70 ; Restore the return address.
\r
73 ; And return - correcting the offset in the LR to obtain the
\r