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