]> begriffs open source - freertos/blob - portable/CCS/ARM_CM4F/portasm.asm
Update SMP branch readme for port migration (#999)
[freertos] / portable / CCS / ARM_CM4F / portasm.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         .thumb
29
30         .ref pxCurrentTCB
31         .ref vTaskSwitchContext
32         .ref ulMaxSyscallInterruptPriority
33
34         .def xPortPendSVHandler
35         .def ulPortGetIPSR
36         .def vPortSVCHandler
37         .def vPortStartFirstTask
38         .def vPortEnableVFP
39
40 NVICOffsetConst:                                        .word   0xE000ED08
41 CPACRConst:                                                     .word   0xE000ED88
42 pxCurrentTCBConst:                                      .word   pxCurrentTCB
43 ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority
44
45 ; -----------------------------------------------------------
46
47         .align 4
48 ulPortGetIPSR: .asmfunc
49         mrs r0, ipsr
50         bx r14
51         .endasmfunc
52  ; -----------------------------------------------------------
53
54         .align 4
55 vPortSetInterruptMask: .asmfunc
56         push {r0}
57         ldr r0, ulMaxSyscallInterruptPriorityConst
58         msr basepri, r0
59         pop {r0}
60         bx r14
61         .endasmfunc
62 ; -----------------------------------------------------------
63
64         .align 4
65 xPortPendSVHandler: .asmfunc
66         mrs r0, psp
67         isb
68
69         ;/* Get the location of the current TCB. */
70         ldr     r3, pxCurrentTCBConst
71         ldr     r2, [r3]
72
73         ;/* Is the task using the FPU context?  If so, push high vfp registers. */
74         tst r14, #0x10
75         it eq
76         vstmdbeq r0!, {s16-s31}
77
78         ;/* Save the core registers. */
79         stmdb r0!, {r4-r11, r14}
80
81         ;/* Save the new top of stack into the first member of the TCB. */
82         str r0, [r2]
83
84         stmdb sp!, {r0, r3}
85         ldr r0, ulMaxSyscallInterruptPriorityConst
86         ldr r1, [r0]
87         msr basepri, r1
88         dsb
89         isb
90         bl vTaskSwitchContext
91         mov r0, #0
92         msr basepri, r0
93         ldmia sp!, {r0, r3}
94
95         ;/* The first item in pxCurrentTCB is the task top of stack. */
96         ldr r1, [r3]
97         ldr r0, [r1]
98
99         ;/* Pop the core registers. */
100         ldmia r0!, {r4-r11, r14}
101
102         ;/* Is the task using the FPU context?  If so, pop the high vfp registers
103         ;too. */
104         tst r14, #0x10
105         it eq
106         vldmiaeq r0!, {s16-s31}
107
108         msr psp, r0
109         isb
110         bx r14
111         .endasmfunc
112
113 ; -----------------------------------------------------------
114
115         .align 4
116 vPortSVCHandler: .asmfunc
117         ;/* Get the location of the current TCB. */
118         ldr     r3, pxCurrentTCBConst
119         ldr r1, [r3]
120         ldr r0, [r1]
121         ;/* Pop the core registers. */
122         ldmia r0!, {r4-r11, r14}
123         msr psp, r0
124         isb
125         mov r0, #0
126         msr     basepri, r0
127         bx r14
128         .endasmfunc
129
130 ; -----------------------------------------------------------
131
132         .align 4
133 vPortStartFirstTask: .asmfunc
134         ;/* Use the NVIC offset register to locate the stack. */
135         ldr r0, NVICOffsetConst
136         ldr r0, [r0]
137         ldr r0, [r0]
138         ;/* Set the msp back to the start of the stack. */
139         msr msp, r0
140         ;/* Clear the bit that indicates the FPU is in use in case the FPU was used
141         ;before the scheduler was started - which would otherwise result in the
142         ;unnecessary leaving of space in the SVC stack for lazy saving of FPU
143         ;registers. */
144         mov r0, #0
145         msr control, r0
146         ;/* Call SVC to start the first task. */
147         cpsie i
148         cpsie f
149         dsb
150         isb
151         svc #0
152         .endasmfunc
153
154 ; -----------------------------------------------------------
155
156         .align 4
157 vPortEnableVFP: .asmfunc
158         ;/* The FPU enable bits are in the CPACR. */
159         ldr.w r0, CPACRConst
160         ldr     r1, [r0]
161
162         ;/* Enable CP10 and CP11 coprocessors, then save back. */
163         orr     r1, r1, #( 0xf << 20 )
164         str r1, [r0]
165         bx      r14
166         .endasmfunc
167
168         .end
169
170 ; -----------------------------------------------------------
171