]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/Tasking/ARM_CM4F/port_asm.asm
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Source / portable / Tasking / ARM_CM4F / port_asm.asm
1 ;/*\r
2 ; * FreeRTOS Kernel V10.0.0\r
3 ; * Copyright (C) 2017 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. If you wish to use our Amazon\r
14 ; * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15 ; *\r
16 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 ; *\r
23 ; * http://www.FreeRTOS.org\r
24 ; * http://aws.amazon.com/freertos\r
25 ; *\r
26 ; * 1 tab == 4 spaces!\r
27 ; */\r
28 \r
29 \r
30         .extern pxCurrentTCB\r
31         .extern vTaskSwitchContext\r
32         .extern ulMaxSyscallInterruptPriorityConst\r
33 \r
34         .global _vector_14\r
35         .global _lc_ref__vector_pp_14\r
36         .global SVC_Handler\r
37         .global vPortStartFirstTask\r
38         .global vPortEnableVFP\r
39         .global ulPortSetInterruptMask\r
40         .global vPortClearInterruptMask\r
41 \r
42 ;-----------------------------------------------------------\r
43 \r
44         .section .text\r
45         .thumb\r
46         .align 4\r
47 _vector_14: .type func\r
48 \r
49         mrs r0, psp\r
50         isb\r
51 \r
52         ;Get the location of the current TCB.\r
53         ldr.w   r3, =pxCurrentTCB\r
54         ldr     r2, [r3]\r
55 \r
56         ;Is the task using the FPU context?  If so, push high vfp registers.\r
57         tst r14, #0x10\r
58         it eq\r
59         vstmdbeq r0!, {s16-s31}\r
60 \r
61         ;Save the core registers.\r
62         stmdb r0!, {r4-r11, r14}\r
63 \r
64         ;Save the new top of stack into the first member of the TCB.\r
65         str r0, [r2]\r
66 \r
67         stmdb sp!, {r0, r3}\r
68         ldr.w r0, =ulMaxSyscallInterruptPriorityConst\r
69         ldr r0, [r0]\r
70         msr basepri, r0\r
71         bl vTaskSwitchContext\r
72         mov r0, #0\r
73         msr basepri, r0\r
74         ldmia sp!, {r0, r3}\r
75 \r
76         ;The first item in pxCurrentTCB is the task top of stack.\r
77         ldr r1, [r3]\r
78         ldr r0, [r1]\r
79 \r
80         ;Pop the core registers.\r
81         ldmia r0!, {r4-r11, r14}\r
82 \r
83         ;Is the task using the FPU context?  If so, pop the high vfp registers too.\r
84         tst r14, #0x10\r
85         it eq\r
86         vldmiaeq r0!, {s16-s31}\r
87 \r
88         msr psp, r0\r
89         isb\r
90         bx r14\r
91 \r
92         .size   _vector_14, $-_vector_14\r
93         .endsec\r
94 \r
95 ;-----------------------------------------------------------\r
96 \r
97 ; This function is an XMC4000 silicon errata workaround.  It will get used when\r
98 ; the SILICON_BUG_PMC_CM_001 linker macro is defined.\r
99         .section .text\r
100         .thumb\r
101         .align 4\r
102 _lc_ref__vector_pp_14: .type func\r
103 \r
104         mrs r0, psp\r
105         isb\r
106 \r
107         ;Get the location of the current TCB.\r
108         ldr.w   r3, =pxCurrentTCB\r
109         ldr     r2, [r3]\r
110 \r
111         ;Is the task using the FPU context?  If so, push high vfp registers.\r
112         tst r14, #0x10\r
113         it eq\r
114         vstmdbeq r0!, {s16-s31}\r
115 \r
116         ;Save the core registers.\r
117         stmdb r0!, {r4-r11, r14}\r
118 \r
119         ;Save the new top of stack into the first member of the TCB.\r
120         str r0, [r2]\r
121 \r
122         stmdb sp!, {r3}\r
123         ldr.w r0, =ulMaxSyscallInterruptPriorityConst\r
124         ldr r0, [r0]\r
125         msr basepri, r0\r
126         bl vTaskSwitchContext\r
127         mov r0, #0\r
128         msr basepri, r0\r
129         ldmia sp!, {r3}\r
130 \r
131         ;The first item in pxCurrentTCB is the task top of stack.\r
132         ldr r1, [r3]\r
133         ldr r0, [r1]\r
134 \r
135         ;Pop the core registers.\r
136         ldmia r0!, {r4-r11, r14}\r
137 \r
138         ;Is the task using the FPU context?  If so, pop the high vfp registers too.\r
139         tst r14, #0x10\r
140         it eq\r
141         vldmiaeq r0!, {s16-s31}\r
142 \r
143         msr psp, r0\r
144         isb\r
145         push { lr }\r
146         pop { pc } ; XMC4000 specific errata workaround.  Do not used "bx lr" here.\r
147 \r
148         .size   _lc_ref__vector_pp_14, $-_lc_ref__vector_pp_14\r
149         .endsec\r
150 \r
151 ;-----------------------------------------------------------\r
152 \r
153         .section .text\r
154         .thumb\r
155         .align 4\r
156 SVC_Handler: .type func\r
157         ;Get the location of the current TCB.\r
158         ldr.w   r3, =pxCurrentTCB\r
159         ldr r1, [r3]\r
160         ldr r0, [r1]\r
161         ;Pop the core registers.\r
162         ldmia r0!, {r4-r11, r14}\r
163         msr psp, r0\r
164         isb\r
165         mov r0, #0\r
166         msr     basepri, r0\r
167         bx r14\r
168         .size   SVC_Handler, $-SVC_Handler\r
169         .endsec\r
170 \r
171 ;-----------------------------------------------------------\r
172 \r
173         .section .text\r
174         .thumb\r
175         .align 4\r
176 vPortStartFirstTask .type func\r
177         ;Use the NVIC offset register to locate the stack.\r
178         ldr.w r0, =0xE000ED08\r
179         ldr r0, [r0]\r
180         ldr r0, [r0]\r
181         ;Set the msp back to the start of the stack.\r
182         msr msp, r0\r
183         ;Call SVC to start the first task.\r
184         cpsie i\r
185         cpsie f\r
186         dsb\r
187         isb\r
188         svc 0\r
189         .size   vPortStartFirstTask, $-vPortStartFirstTask\r
190         .endsec\r
191 \r
192 ;-----------------------------------------------------------\r
193 \r
194         .section .text\r
195         .thumb\r
196         .align 4\r
197 vPortEnableVFP .type func\r
198         ;The FPU enable bits are in the CPACR.\r
199         ldr.w r0, =0xE000ED88\r
200         ldr     r1, [r0]\r
201 \r
202         ;Enable CP10 and CP11 coprocessors, then save back.\r
203         orr     r1, r1, #( 0xf << 20 )\r
204         str r1, [r0]\r
205         bx      r14\r
206         .size   vPortEnableVFP, $-vPortEnableVFP\r
207         .endsec\r
208 \r
209 ;-----------------------------------------------------------\r
210 \r
211         .section .text\r
212         .thumb\r
213         .align 4\r
214 ulPortSetInterruptMask:\r
215         mrs r0, basepri\r
216         ldr.w r1, =ulMaxSyscallInterruptPriorityConst\r
217         ldr r1, [r1]\r
218         msr basepri, r1\r
219         bx r14\r
220         .size   ulPortSetInterruptMask, $-ulPortSetInterruptMask\r
221         .endsec\r
222 \r
223 ;-----------------------------------------------------------\r
224 \r
225         .section .text\r
226         .thumb\r
227         .align 4\r
228 vPortClearInterruptMask:\r
229         msr basepri, r0\r
230         bx r14\r
231         .size   vPortClearInterruptMask, $-vPortClearInterruptMask\r
232         .endsec\r
233 \r
234 ;-----------------------------------------------------------\r
235 \r
236         .end\r
237 \r