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