]> begriffs open source - cmsis-freertos/blob - Source/portable/RVDS/ARM_CA9/portmacro.inc
Update FreeRTOS-Kernel to v10.6.2
[cmsis-freertos] / Source / portable / RVDS / ARM_CA9 / portmacro.inc
1 ;/*
2 ; * FreeRTOS Kernel V10.6.2
3 ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4 ; *
5 ; * SPDX-License-Identifier: MIT
6 ; *
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:
13 ; *
14 ; * The above copyright notice and this permission notice shall be included in all
15 ; * copies or substantial portions of the Software.
16 ; *
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.
23 ; *
24 ; * https://www.FreeRTOS.org
25 ; * https://github.com/FreeRTOS
26 ; *
27 ; */
28
29 SYS_MODE            EQU     0x1f
30 SVC_MODE            EQU     0x13
31 IRQ_MODE            EQU     0x12
32
33     IMPORT  ulCriticalNesting
34     IMPORT  pxCurrentTCB
35     IMPORT  ulPortTaskHasFPUContext
36     IMPORT  ulAsmAPIPriorityMask
37     IMPORT  ulICCPMR
38
39
40     MACRO
41     portSAVE_CONTEXT
42
43     ; Save the LR and SPSR onto the system mode stack before switching to
44     ; system mode to save the remaining system mode registers
45     SRSDB   sp!, #SYS_MODE
46     CPS     #SYS_MODE
47     PUSH    {R0-R12, R14}
48
49     ; Push the critical nesting count
50     LDR     R2, =ulCriticalNesting
51     LDR     R1, [R2]
52     PUSH    {R1}
53
54     ; Does the task have a floating point context that needs saving?  If
55     ; ulPortTaskHasFPUContext is 0 then no.
56     LDR     R2, =ulPortTaskHasFPUContext
57     LDR     R3, [R2]
58     CMP     R3, #0
59
60     ; Save the floating point context, if any
61     FMRXNE  R1,  FPSCR
62     VPUSHNE {D0-D15}
63     VPUSHNE {D16-D31}
64     PUSHNE  {R1}
65
66     ; Save ulPortTaskHasFPUContext itself
67     PUSH    {R3}
68
69     ; Save the stack pointer in the TCB
70     LDR     R0, =pxCurrentTCB
71     LDR     R1, [R0]
72     STR     SP, [R1]
73
74     MEND
75
76 ; /**********************************************************************/
77
78     MACRO
79     portRESTORE_CONTEXT
80
81     ; Set the SP to point to the stack of the task being restored.
82     LDR     R0, =pxCurrentTCB
83     LDR     R1, [R0]
84     LDR     SP, [R1]
85
86     ; Is there a floating point context to restore?  If the restored
87     ; ulPortTaskHasFPUContext is zero then no.
88     LDR     R0, =ulPortTaskHasFPUContext
89     POP     {R1}
90     STR     R1, [R0]
91     CMP     R1, #0
92
93     ; Restore the floating point context, if any
94     POPNE   {R0}
95     VPOPNE  {D16-D31}
96     VPOPNE  {D0-D15}
97     VMSRNE  FPSCR, R0
98
99     ; Restore the critical section nesting depth
100     LDR     R0, =ulCriticalNesting
101     POP     {R1}
102     STR     R1, [R0]
103
104     ; Ensure the priority mask is correct for the critical nesting depth
105     LDR     R2, =ulICCPMR
106     CMP     R1, #0
107     MOVEQ   R4, #255
108     LDRNE   R4, =ulAsmAPIPriorityMask
109     STR     R4, [r2]
110
111     ; Restore all system mode registers other than the SP (which is already
112     ; being used)
113     POP     {R0-R12, R14}
114
115     ; Return to the task code, loading CPSR on the way.
116     RFEIA   sp!
117
118     MEND
119
120     END