]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/CCS/ARM_Cortex-R4/portASM.asm
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / CCS / ARM_Cortex-R4 / portASM.asm
1 ;/*\r
2 ;    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3 ;    All rights reserved\r
4 ;\r
5 ;\r
6 ;    ***************************************************************************\r
7 ;     *                                                                       *\r
8 ;     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
9 ;     *    Complete, revised, and edited pdf reference manuals are also       *\r
10 ;     *    available.                                                         *\r
11 ;     *                                                                       *\r
12 ;     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
13 ;     *    ensuring you get running as quickly as possible and with an        *\r
14 ;     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
15 ;     *    the FreeRTOS project to continue with its mission of providing     *\r
16 ;     *    professional grade, cross platform, de facto standard solutions    *\r
17 ;     *    for microcontrollers - completely free of charge!                  *\r
18 ;     *                                                                       *\r
19 ;     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
20 ;     *                                                                       *\r
21 ;     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
22 ;     *                                                                       *\r
23 ;    ***************************************************************************\r
24 ;\r
25 ;\r
26 ;    This file is part of the FreeRTOS distribution.\r
27 ;\r
28 ;    FreeRTOS is free software; you can redistribute it and/or modify it under\r
29 ;    the terms of the GNU General Public License (version 2) as published by the\r
30 ;    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
31 ;    >>>NOTE<<< The modification to the GPL is included to allow you to\r
32 ;    distribute a combined work that includes FreeRTOS without being obliged to\r
33 ;    provide the source code for proprietary components outside of the FreeRTOS\r
34 ;    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
35 ;    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
36 ;    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
37 ;    more details. You should have received a copy of the GNU General Public\r
38 ;    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
39 ;    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
40 ;    by writing to Richard Barry, contact details for whom are available on the\r
41 ;    FreeRTOS WEB site.\r
42 ;\r
43 ;    1 tab == 4 spaces!\r
44 ;\r
45 ;    http://www.FreeRTOS.org - Documentation, latest information, license and\r
46 ;    contact details.\r
47 ;\r
48 ;    http://www.SafeRTOS.com - A version that is certified for use in safety\r
49 ;    critical systems.\r
50 ;\r
51 ;    http://www.OpenRTOS.com - Commercial support, development, porting,\r
52 ;    licensing and training services.\r
53 ;*/\r
54 \r
55         .text\r
56         .arm\r
57         .ref vTaskSwitchContext\r
58         .ref xTaskIncrementTick\r
59         .ref ulTaskHasFPUContext\r
60                 .ref pxCurrentTCB\r
61 \r
62 ;/*-----------------------------------------------------------*/\r
63 ;\r
64 ; Save Task Context\r
65 ;\r
66 portSAVE_CONTEXT .macro\r
67                 DSB\r
68 \r
69                 ; Push R0 as we are going to use it\r
70                 STMDB   SP!, {R0}\r
71 \r
72                 ; Set R0 to point to the task stack pointer.\r
73                 STMDB   SP,{SP}^\r
74                 SUB     SP, SP, #4\r
75                 LDMIA   SP!,{R0}\r
76 \r
77                 ; Push the return address onto the stack.\r
78                 STMDB   R0!, {LR}\r
79 \r
80                 ; Now LR has been saved, it can be used instead of R0.\r
81                 MOV     LR, R0\r
82 \r
83                 ; Pop R0 so it can be saved onto the task stack.\r
84                 LDMIA   SP!, {R0}\r
85 \r
86                 ; Push all the system mode registers onto the task stack.\r
87                 STMDB   LR,{R0-LR}^\r
88                 SUB     LR, LR, #60\r
89 \r
90                 ; Push the SPSR onto the task stack.\r
91                 MRS     R0, SPSR\r
92                 STMDB   LR!, {R0}\r
93 \r
94     .if (__TI_VFP_SUPPORT__)\r
95                 ;Determine if the task maintains an FPU context.\r
96                 LDR     R0, ulFPUContextConst\r
97                 LDR     R0, [R0]\r
98 \r
99                 ; Test the flag\r
100                 CMP             R0, #0\r
101 \r
102                 ; If the task is not using a floating point context then skip the\r
103                 ; saving of the FPU registers.\r
104                 BEQ             $+16\r
105                 FSTMDBD LR!, {D0-D15}\r
106                 FMRX    R1,  FPSCR\r
107                 STMFD   LR!, {R1}\r
108 \r
109                 ; Save the flag\r
110                 STMDB   LR!, {R0}\r
111         .endif\r
112 \r
113                 ; Store the new top of stack for the task.\r
114                 LDR     R0, pxCurrentTCBConst\r
115                 LDR     R0, [R0]\r
116                 STR     LR, [R0]\r
117 \r
118         .endm\r
119 \r
120 ;/*-----------------------------------------------------------*/\r
121 ;\r
122 ; Restore Task Context\r
123 ;\r
124 portRESTORE_CONTEXT .macro\r
125                 LDR             R0, pxCurrentTCBConst\r
126                 LDR             R0, [R0]\r
127                 LDR             LR, [R0]\r
128 \r
129         .if (__TI_VFP_SUPPORT__)\r
130                 ; The floating point context flag is the first thing on the stack.\r
131                 LDR             R0, ulFPUContextConst\r
132                 LDMFD   LR!, {R1}\r
133                 STR             R1, [R0]\r
134 \r
135                 ; Test the flag\r
136                 CMP             R1, #0\r
137 \r
138                 ; If the task is not using a floating point context then skip the\r
139                 ; VFP register loads.\r
140                 BEQ             $+16\r
141 \r
142                 ; Restore the floating point context.\r
143                 LDMFD   LR!, {R0}\r
144                 FLDMIAD LR!, {D0-D15}\r
145                 FMXR    FPSCR, R0\r
146         .endif\r
147 \r
148                 ; Get the SPSR from the stack.\r
149                 LDMFD   LR!, {R0}\r
150                 MSR             SPSR_CSXF, R0\r
151 \r
152                 ; Restore all system mode registers for the task.\r
153                 LDMFD   LR, {R0-R14}^\r
154 \r
155                 ; Restore the return address.\r
156                 LDR             LR, [LR, #+60]\r
157 \r
158                 ; And return - correcting the offset in the LR to obtain the\r
159                 ; correct address.\r
160                 SUBS    PC, LR, #4\r
161         .endm\r
162 \r
163 ;/*-----------------------------------------------------------*/\r
164 ; Start the first task by restoring its context.\r
165 \r
166         .def vPortStartFirstTask\r
167 \r
168 vPortStartFirstTask:\r
169         portRESTORE_CONTEXT\r
170 \r
171 ;/*-----------------------------------------------------------*/\r
172 ; Yield to another task.\r
173 \r
174         .def vPortYieldProcessor\r
175 \r
176 vPortYieldProcessor:\r
177                 ; Within an IRQ ISR the link register has an offset from the true return\r
178                 ; address.  SWI doesn't do this. Add the offset manually so the ISR\r
179                 ; return code can be used.\r
180         ADD     LR, LR, #4\r
181 \r
182         ; First save the context of the current task.\r
183         portSAVE_CONTEXT\r
184 \r
185         ; Select the next task to execute. */\r
186         BL      vTaskSwitchContext\r
187 \r
188         ; Restore the context of the task selected to execute.\r
189         portRESTORE_CONTEXT\r
190 \r
191 ;/*-----------------------------------------------------------*/\r
192 ; Yield to another task from within the FreeRTOS API\r
193 \r
194                 .def vPortYeildWithinAPI\r
195 \r
196 vPortYeildWithinAPI:\r
197                 ; Save the context of the current task.\r
198 \r
199         portSAVE_CONTEXT\r
200                 ; Clear SSI flag.\r
201                 MOVW    R0, #0xFFF4\r
202                 MOVT    R0, #0xFFFF\r
203                 LDR     R0, [R0]\r
204 \r
205                 ; Select the next task to execute. */\r
206         BL      vTaskSwitchContext\r
207 \r
208         ; Restore the context of the task selected to execute.\r
209         portRESTORE_CONTEXT\r
210 \r
211 ;/*-----------------------------------------------------------*/\r
212 ; Preemptive Tick\r
213 \r
214         .def vPortPreemptiveTick\r
215 \r
216 vPortPreemptiveTick:\r
217 \r
218                 ; Save the context of the current task.\r
219         portSAVE_CONTEXT\r
220 \r
221         ; Clear interrupt flag\r
222         MOVW    R0, #0xFC88\r
223         MOVT    R0, #0xFFFF\r
224         MOV     R1, #1\r
225         STR     R1, [R0]\r
226 \r
227         ; Increment the tick count, making any adjustments to the blocked lists\r
228         ; that may be necessary.\r
229         BL      xTaskIncrementTick\r
230 \r
231         ; Select the next task to execute.\r
232         CMP     R0, #0\r
233         BLNE    vTaskSwitchContext\r
234 \r
235         ; Restore the context of the task selected to execute.\r
236         portRESTORE_CONTEXT\r
237 \r
238 ;-------------------------------------------------------------------------------\r
239 \r
240         .if (__TI_VFP_SUPPORT__)\r
241 \r
242                 .def vPortInitialiseFPSCR\r
243 \r
244 vPortInitialiseFPSCR:\r
245 \r
246                 MOV             R0, #0\r
247                 FMXR    FPSCR, R0\r
248                 BX              LR\r
249 \r
250         .endif ;__TI_VFP_SUPPORT__\r
251 \r
252 \r
253 pxCurrentTCBConst       .word   pxCurrentTCB\r
254 ulFPUContextConst       .word   ulTaskHasFPUContext\r
255 ;-------------------------------------------------------------------------------\r
256 \r