]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Tasking/ARM_CM4F/port_asm.asm
9d9c42074348f255fc739800dced3fd52f892b8f
[freertos] / FreeRTOS / Source / portable / Tasking / ARM_CM4F / port_asm.asm
1 ;/*\r
2 ;    FreeRTOS V7.5.3 - Copyright (C) 2013 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 \r
56         .extern pxCurrentTCB\r
57         .extern vTaskSwitchContext\r
58         .extern ulMaxSyscallInterruptPriorityConst\r
59 \r
60         .global _vector_14\r
61         .global _lc_ref__vector_pp_14\r
62         .global SVC_Handler\r
63         .global vPortStartFirstTask\r
64         .global vPortEnableVFP\r
65         .global ulPortSetInterruptMask\r
66         .global vPortClearInterruptMask\r
67         \r
68 ;-----------------------------------------------------------\r
69 \r
70         .section .text\r
71         .thumb\r
72         .align 4\r
73 _vector_14: .type func\r
74 \r
75         mrs r0, psp\r
76 \r
77         ;Get the location of the current TCB.\r
78         ldr.w   r3, =pxCurrentTCB\r
79         ldr     r2, [r3]\r
80 \r
81         ;Is the task using the FPU context?  If so, push high vfp registers.\r
82         tst r14, #0x10\r
83         it eq\r
84         vstmdbeq r0!, {s16-s31}\r
85 \r
86         ;Save the core registers.\r
87         stmdb r0!, {r4-r11, r14}\r
88 \r
89         ;Save the new top of stack into the first member of the TCB.\r
90         str r0, [r2]\r
91 \r
92         stmdb sp!, {r3, r14}\r
93         ldr.w r0, =ulMaxSyscallInterruptPriorityConst\r
94         msr basepri, r0\r
95         bl vTaskSwitchContext\r
96         mov r0, #0\r
97         msr basepri, r0\r
98         ldmia sp!, {r3, r14}\r
99 \r
100         ;The first item in pxCurrentTCB is the task top of stack.\r
101         ldr r1, [r3]\r
102         ldr r0, [r1]\r
103 \r
104         ;Pop the core registers.\r
105         ldmia r0!, {r4-r11, r14}\r
106 \r
107         ;Is the task using the FPU context?  If so, pop the high vfp registers too.\r
108         tst r14, #0x10\r
109         it eq\r
110         vldmiaeq r0!, {s16-s31}\r
111 \r
112         msr psp, r0\r
113         bx r14\r
114 \r
115         .size   _vector_14, $-_vector_14\r
116         .endsec\r
117 \r
118 ;-----------------------------------------------------------\r
119 \r
120 ; This function is an XMC4000 silicon errata workaround.  It will get used when\r
121 ; the SILICON_BUG_PMC_CM_001 linker macro is defined.\r
122         .section .text\r
123         .thumb\r
124         .align 4\r
125 _lc_ref__vector_pp_14: .type func\r
126 \r
127         mrs r0, psp\r
128 \r
129         ;Get the location of the current TCB.\r
130         ldr.w   r3, =pxCurrentTCB\r
131         ldr     r2, [r3]\r
132 \r
133         ;Is the task using the FPU context?  If so, push high vfp registers.\r
134         tst r14, #0x10\r
135         it eq\r
136         vstmdbeq r0!, {s16-s31}\r
137 \r
138         ;Save the core registers.\r
139         stmdb r0!, {r4-r11, r14}\r
140 \r
141         ;Save the new top of stack into the first member of the TCB.\r
142         str r0, [r2]\r
143 \r
144         stmdb sp!, {r3, r14}\r
145         ldr.w r0, =ulMaxSyscallInterruptPriorityConst\r
146         msr basepri, r0\r
147         bl vTaskSwitchContext\r
148         mov r0, #0\r
149         msr basepri, r0\r
150         ldmia sp!, {r3, r14}\r
151 \r
152         ;The first item in pxCurrentTCB is the task top of stack.\r
153         ldr r1, [r3]\r
154         ldr r0, [r1]\r
155 \r
156         ;Pop the core registers.\r
157         ldmia r0!, {r4-r11, r14}\r
158 \r
159         ;Is the task using the FPU context?  If so, pop the high vfp registers too.\r
160         tst r14, #0x10\r
161         it eq\r
162         vldmiaeq r0!, {s16-s31}\r
163 \r
164         msr psp, r0\r
165         push { lr }\r
166         pop { pc } ; XMC4000 specific errata workaround.  Do not used "bx lr" here.\r
167 \r
168         .size   _lc_ref__vector_pp_14, $-_lc_ref__vector_pp_14\r
169         .endsec\r
170 \r
171 ;-----------------------------------------------------------\r
172 \r
173         .section .text\r
174         .thumb\r
175         .align 4\r
176 SVC_Handler: .type func\r
177         ;Get the location of the current TCB.\r
178         ldr.w   r3, =pxCurrentTCB\r
179         ldr r1, [r3]\r
180         ldr r0, [r1]\r
181         ;Pop the core registers.\r
182         ldmia r0!, {r4-r11, r14}\r
183         msr psp, r0\r
184         mov r0, #0\r
185         msr     basepri, r0\r
186         bx r14\r
187         .size   SVC_Handler, $-SVC_Handler\r
188         .endsec\r
189 \r
190 ;-----------------------------------------------------------\r
191 \r
192         .section .text\r
193         .thumb\r
194         .align 4\r
195 vPortStartFirstTask .type func\r
196         ;Use the NVIC offset register to locate the stack.\r
197         ldr.w r0, =0xE000ED08\r
198         ldr r0, [r0]\r
199         ldr r0, [r0]\r
200         ;Set the msp back to the start of the stack.\r
201         msr msp, r0\r
202         ;Call SVC to start the first task.\r
203         cpsie i\r
204         svc 0\r
205         .size   vPortStartFirstTask, $-vPortStartFirstTask\r
206         .endsec\r
207 \r
208 ;-----------------------------------------------------------\r
209 \r
210         .section .text\r
211         .thumb\r
212         .align 4\r
213 vPortEnableVFP .type func\r
214         ;The FPU enable bits are in the CPACR.\r
215         ldr.w r0, =0xE000ED88\r
216         ldr     r1, [r0]\r
217 \r
218         ;Enable CP10 and CP11 coprocessors, then save back.\r
219         orr     r1, r1, #( 0xf << 20 )\r
220         str r1, [r0]\r
221         bx      r14\r
222         .size   vPortEnableVFP, $-vPortEnableVFP\r
223         .endsec\r
224 \r
225 ;-----------------------------------------------------------\r
226 \r
227         .section .text\r
228         .thumb\r
229         .align 4\r
230 ulPortSetInterruptMask:\r
231         mrs r0, basepri\r
232         ldr.w r1, =ulMaxSyscallInterruptPriorityConst\r
233         msr basepri, r1\r
234         bx r14\r
235         .size   ulPortSetInterruptMask, $-ulPortSetInterruptMask\r
236         .endsec\r
237 \r
238 ;-----------------------------------------------------------\r
239 \r
240         .section .text\r
241         .thumb\r
242         .align 4\r
243 vPortClearInterruptMask:\r
244         msr basepri, r0\r
245         bx r14\r
246         .size   vPortClearInterruptMask, $-vPortClearInterruptMask\r
247         .endsec\r
248 \r
249 ;-----------------------------------------------------------\r
250 \r
251         .end\r
252         \r