]> begriffs open source - freertos/blob - portable/CCS/ARM_Cortex-R4/portASM.asm
Remove "1 tab == 4 spaces!" line from files that still contain it.
[freertos] / portable / CCS / ARM_Cortex-R4 / portASM.asm
1 ;/*\r
2 ; * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3 ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4 ; *\r
5 ; * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6 ; * this software and associated documentation files (the "Software"), to deal in\r
7 ; * the Software without restriction, including without limitation the rights to\r
8 ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9 ; * the Software, and to permit persons to whom the Software is furnished to do so,\r
10 ; * subject to the following conditions:\r
11 ; *\r
12 ; * The above copyright notice and this permission notice shall be included in all\r
13 ; * copies or substantial portions of the Software.\r
14 ; *\r
15 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21 ; *\r
22 ; * https://www.FreeRTOS.org\r
23 ; * https://github.com/FreeRTOS\r
24 ; *\r
25 ; */\r
26 \r
27         .text\r
28         .arm\r
29         .ref vTaskSwitchContext\r
30         .ref xTaskIncrementTick\r
31         .ref ulTaskHasFPUContext\r
32                 .ref pxCurrentTCB\r
33 \r
34 ;/*-----------------------------------------------------------*/\r
35 ;\r
36 ; Save Task Context\r
37 ;\r
38 portSAVE_CONTEXT .macro\r
39                 DSB\r
40 \r
41                 ; Push R0 as we are going to use it\r
42                 STMDB   SP!, {R0}\r
43 \r
44                 ; Set R0 to point to the task stack pointer.\r
45                 STMDB   SP,{SP}^\r
46                 SUB     SP, SP, #4\r
47                 LDMIA   SP!,{R0}\r
48 \r
49                 ; Push the return address onto the stack.\r
50                 STMDB   R0!, {LR}\r
51 \r
52                 ; Now LR has been saved, it can be used instead of R0.\r
53                 MOV     LR, R0\r
54 \r
55                 ; Pop R0 so it can be saved onto the task stack.\r
56                 LDMIA   SP!, {R0}\r
57 \r
58                 ; Push all the system mode registers onto the task stack.\r
59                 STMDB   LR,{R0-LR}^\r
60                 SUB     LR, LR, #60\r
61 \r
62                 ; Push the SPSR onto the task stack.\r
63                 MRS     R0, SPSR\r
64                 STMDB   LR!, {R0}\r
65 \r
66     .if (__TI_VFP_SUPPORT__)\r
67                 ;Determine if the task maintains an FPU context.\r
68                 LDR     R0, ulFPUContextConst\r
69                 LDR     R0, [R0]\r
70 \r
71                 ; Test the flag\r
72                 CMP             R0, #0\r
73 \r
74                 ; If the task is not using a floating point context then skip the\r
75                 ; saving of the FPU registers.\r
76                 BEQ             $+16\r
77                 FSTMDBD LR!, {D0-D15}\r
78                 FMRX    R1,  FPSCR\r
79                 STMFD   LR!, {R1}\r
80 \r
81                 ; Save the flag\r
82                 STMDB   LR!, {R0}\r
83         .endif\r
84 \r
85                 ; Store the new top of stack for the task.\r
86                 LDR     R0, pxCurrentTCBConst\r
87                 LDR     R0, [R0]\r
88                 STR     LR, [R0]\r
89 \r
90         .endm\r
91 \r
92 ;/*-----------------------------------------------------------*/\r
93 ;\r
94 ; Restore Task Context\r
95 ;\r
96 portRESTORE_CONTEXT .macro\r
97                 LDR             R0, pxCurrentTCBConst\r
98                 LDR             R0, [R0]\r
99                 LDR             LR, [R0]\r
100 \r
101         .if (__TI_VFP_SUPPORT__)\r
102                 ; The floating point context flag is the first thing on the stack.\r
103                 LDR             R0, ulFPUContextConst\r
104                 LDMFD   LR!, {R1}\r
105                 STR             R1, [R0]\r
106 \r
107                 ; Test the flag\r
108                 CMP             R1, #0\r
109 \r
110                 ; If the task is not using a floating point context then skip the\r
111                 ; VFP register loads.\r
112                 BEQ             $+16\r
113 \r
114                 ; Restore the floating point context.\r
115                 LDMFD   LR!, {R0}\r
116                 FLDMIAD LR!, {D0-D15}\r
117                 FMXR    FPSCR, R0\r
118         .endif\r
119 \r
120                 ; Get the SPSR from the stack.\r
121                 LDMFD   LR!, {R0}\r
122                 MSR             SPSR_CSXF, R0\r
123 \r
124                 ; Restore all system mode registers for the task.\r
125                 LDMFD   LR, {R0-R14}^\r
126 \r
127                 ; Restore the return address.\r
128                 LDR             LR, [LR, #+60]\r
129 \r
130                 ; And return - correcting the offset in the LR to obtain the\r
131                 ; correct address.\r
132                 SUBS    PC, LR, #4\r
133         .endm\r
134 \r
135 ;/*-----------------------------------------------------------*/\r
136 ; Start the first task by restoring its context.\r
137 \r
138         .def vPortStartFirstTask\r
139 \r
140 vPortStartFirstTask:\r
141         portRESTORE_CONTEXT\r
142 \r
143 ;/*-----------------------------------------------------------*/\r
144 ; Yield to another task.\r
145 \r
146         .def vPortYieldProcessor\r
147 \r
148 vPortYieldProcessor:\r
149                 ; Within an IRQ ISR the link register has an offset from the true return\r
150                 ; address.  SWI doesn't do this. Add the offset manually so the ISR\r
151                 ; return code can be used.\r
152         ADD     LR, LR, #4\r
153 \r
154         ; First save the context of the current task.\r
155         portSAVE_CONTEXT\r
156 \r
157         ; Select the next task to execute. */\r
158         BL      vTaskSwitchContext\r
159 \r
160         ; Restore the context of the task selected to execute.\r
161         portRESTORE_CONTEXT\r
162 \r
163 ;/*-----------------------------------------------------------*/\r
164 ; Yield to another task from within the FreeRTOS API\r
165 \r
166                 .def vPortYeildWithinAPI\r
167 \r
168 vPortYeildWithinAPI:\r
169                 ; Save the context of the current task.\r
170 \r
171         portSAVE_CONTEXT\r
172                 ; Clear SSI flag.\r
173                 MOVW    R0, #0xFFF4\r
174                 MOVT    R0, #0xFFFF\r
175                 LDR     R0, [R0]\r
176 \r
177                 ; Select the next task to execute. */\r
178         BL      vTaskSwitchContext\r
179 \r
180         ; Restore the context of the task selected to execute.\r
181         portRESTORE_CONTEXT\r
182 \r
183 ;/*-----------------------------------------------------------*/\r
184 ; Preemptive Tick\r
185 \r
186         .def vPortPreemptiveTick\r
187 \r
188 vPortPreemptiveTick:\r
189 \r
190                 ; Save the context of the current task.\r
191         portSAVE_CONTEXT\r
192 \r
193         ; Clear interrupt flag\r
194         MOVW    R0, #0xFC88\r
195         MOVT    R0, #0xFFFF\r
196         MOV     R1, #1\r
197         STR     R1, [R0]\r
198 \r
199         ; Increment the tick count, making any adjustments to the blocked lists\r
200         ; that may be necessary.\r
201         BL      xTaskIncrementTick\r
202 \r
203         ; Select the next task to execute.\r
204         CMP     R0, #0\r
205         BLNE    vTaskSwitchContext\r
206 \r
207         ; Restore the context of the task selected to execute.\r
208         portRESTORE_CONTEXT\r
209 \r
210 ;-------------------------------------------------------------------------------\r
211 \r
212         .if (__TI_VFP_SUPPORT__)\r
213 \r
214                 .def vPortInitialiseFPSCR\r
215 \r
216 vPortInitialiseFPSCR:\r
217 \r
218                 MOV             R0, #0\r
219                 FMXR    FPSCR, R0\r
220                 BX              LR\r
221 \r
222         .endif ;__TI_VFP_SUPPORT__\r
223 \r
224 \r
225 pxCurrentTCBConst       .word   pxCurrentTCB\r
226 ulFPUContextConst       .word   ulTaskHasFPUContext\r
227 ;-------------------------------------------------------------------------------\r
228 \r