2 ; * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 ; * SPDX-License-Identifier: MIT
7 ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ; * this software and associated documentation files (the "Software"), to deal in
9 ; * the Software without restriction, including without limitation the rights to
10 ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 ; * the Software, and to permit persons to whom the Software is furnished to do so,
12 ; * subject to the following conditions:
14 ; * The above copyright notice and this permission notice shall be included in all
15 ; * copies or substantial portions of the Software.
17 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 ; * https://www.FreeRTOS.org
25 ; * https://github.com/FreeRTOS
29 EXTERN vTaskSwitchContext
30 EXTERN ulCriticalNesting
32 EXTERN ulPortTaskHasFPUContext
33 EXTERN ulAsmAPIPriorityMask
35 portSAVE_CONTEXT macro
37 ; Save the LR and SPSR onto the system mode stack before switching to
38 ; system mode to save the remaining system mode registers
43 ; Push the critical nesting count
44 LDR R2, =ulCriticalNesting
48 ; Does the task have a floating point context that needs saving? If
49 ; ulPortTaskHasFPUContext is 0 then no.
50 LDR R2, =ulPortTaskHasFPUContext
54 ; Save the floating point context, if any
60 ; Save ulPortTaskHasFPUContext itself
63 ; Save the stack pointer in the TCB
70 ; /**********************************************************************/
72 portRESTORE_CONTEXT macro
74 ; Set the SP to point to the stack of the task being restored.
79 ; Is there a floating point context to restore? If the restored
80 ; ulPortTaskHasFPUContext is zero then no.
81 LDR R0, =ulPortTaskHasFPUContext
86 ; Restore the floating point context, if any
92 ; Restore the critical section nesting depth
93 LDR R0, =ulCriticalNesting
97 ; Ensure the priority mask is correct for the critical nesting depth
98 LDR R2, =portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS
101 LDRNE R4, =( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT )
104 ; Restore all system mode registers other than the SP (which is already
108 ; Return to the task code, loading CPSR on the way.