]> begriffs open source - freertos/blob - portable/CCS/ARM_CM4F/portasm.asm
Add SPDX-License-Identifier: MIT to MIT licensed files.
[freertos] / portable / CCS / ARM_CM4F / portasm.asm
1 ;/*\r
2 ; * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3 ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4 ; *\r
5 ; * SPDX-License-Identifier: MIT
6 ; *
7 ; * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8 ; * this software and associated documentation files (the "Software"), to deal in\r
9 ; * the Software without restriction, including without limitation the rights to\r
10 ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11 ; * the Software, and to permit persons to whom the Software is furnished to do so,\r
12 ; * subject to the following conditions:\r
13 ; *\r
14 ; * The above copyright notice and this permission notice shall be included in all\r
15 ; * copies or substantial portions of the Software.\r
16 ; *\r
17 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23 ; *\r
24 ; * https://www.FreeRTOS.org\r
25 ; * https://github.com/FreeRTOS\r
26 ; *\r
27 ; */\r
28 \r
29         .thumb\r
30 \r
31         .ref pxCurrentTCB\r
32         .ref vTaskSwitchContext\r
33         .ref ulMaxSyscallInterruptPriority\r
34 \r
35         .def xPortPendSVHandler\r
36         .def ulPortGetIPSR\r
37         .def vPortSVCHandler\r
38         .def vPortStartFirstTask\r
39         .def vPortEnableVFP\r
40 \r
41 NVICOffsetConst:                                        .word   0xE000ED08\r
42 CPACRConst:                                                     .word   0xE000ED88\r
43 pxCurrentTCBConst:                                      .word   pxCurrentTCB\r
44 ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority\r
45 \r
46 ; -----------------------------------------------------------\r
47 \r
48         .align 4\r
49 ulPortGetIPSR: .asmfunc\r
50         mrs r0, ipsr\r
51         bx r14\r
52         .endasmfunc\r
53  ; -----------------------------------------------------------\r
54 \r
55         .align 4\r
56 vPortSetInterruptMask: .asmfunc\r
57         push {r0}\r
58         ldr r0, ulMaxSyscallInterruptPriorityConst\r
59         msr basepri, r0\r
60         pop {r0}\r
61         bx r14\r
62         .endasmfunc\r
63 ; -----------------------------------------------------------\r
64 \r
65         .align 4\r
66 xPortPendSVHandler: .asmfunc\r
67         mrs r0, psp\r
68         isb\r
69 \r
70         ;/* Get the location of the current TCB. */\r
71         ldr     r3, pxCurrentTCBConst\r
72         ldr     r2, [r3]\r
73 \r
74         ;/* Is the task using the FPU context?  If so, push high vfp registers. */\r
75         tst r14, #0x10\r
76         it eq\r
77         vstmdbeq r0!, {s16-s31}\r
78 \r
79         ;/* Save the core registers. */\r
80         stmdb r0!, {r4-r11, r14}\r
81 \r
82         ;/* Save the new top of stack into the first member of the TCB. */\r
83         str r0, [r2]\r
84 \r
85         stmdb sp!, {r0, r3}\r
86         ldr r0, ulMaxSyscallInterruptPriorityConst\r
87         ldr r1, [r0]\r
88         msr basepri, r1\r
89         dsb\r
90         isb\r
91         bl vTaskSwitchContext\r
92         mov r0, #0\r
93         msr basepri, r0\r
94         ldmia sp!, {r0, r3}\r
95 \r
96         ;/* The first item in pxCurrentTCB is the task top of stack. */\r
97         ldr r1, [r3]\r
98         ldr r0, [r1]\r
99 \r
100         ;/* Pop the core registers. */\r
101         ldmia r0!, {r4-r11, r14}\r
102 \r
103         ;/* Is the task using the FPU context?  If so, pop the high vfp registers\r
104         ;too. */\r
105         tst r14, #0x10\r
106         it eq\r
107         vldmiaeq r0!, {s16-s31}\r
108 \r
109         msr psp, r0\r
110         isb\r
111         bx r14\r
112         .endasmfunc\r
113 \r
114 ; -----------------------------------------------------------\r
115 \r
116         .align 4\r
117 vPortSVCHandler: .asmfunc\r
118         ;/* Get the location of the current TCB. */\r
119         ldr     r3, pxCurrentTCBConst\r
120         ldr r1, [r3]\r
121         ldr r0, [r1]\r
122         ;/* Pop the core registers. */\r
123         ldmia r0!, {r4-r11, r14}\r
124         msr psp, r0\r
125         isb\r
126         mov r0, #0\r
127         msr     basepri, r0\r
128         bx r14\r
129         .endasmfunc\r
130 \r
131 ; -----------------------------------------------------------\r
132 \r
133         .align 4\r
134 vPortStartFirstTask: .asmfunc\r
135         ;/* Use the NVIC offset register to locate the stack. */\r
136         ldr r0, NVICOffsetConst\r
137         ldr r0, [r0]\r
138         ldr r0, [r0]\r
139         ;/* Set the msp back to the start of the stack. */\r
140         msr msp, r0\r
141         ;/* Clear the bit that indicates the FPU is in use in case the FPU was used\r
142         ;before the scheduler was started - which would otherwise result in the\r
143         ;unnecessary leaving of space in the SVC stack for lazy saving of FPU\r
144         ;registers. */\r
145         mov r0, #0\r
146         msr control, r0\r
147         ;/* Call SVC to start the first task. */\r
148         cpsie i\r
149         cpsie f\r
150         dsb\r
151         isb\r
152         svc #0\r
153         .endasmfunc\r
154 \r
155 ; -----------------------------------------------------------\r
156 \r
157         .align 4\r
158 vPortEnableVFP: .asmfunc\r
159         ;/* The FPU enable bits are in the CPACR. */\r
160         ldr.w r0, CPACRConst\r
161         ldr     r1, [r0]\r
162 \r
163         ;/* Enable CP10 and CP11 coprocessors, then save back. */\r
164         orr     r1, r1, #( 0xf << 20 )\r
165         str r1, [r0]\r
166         bx      r14\r
167         .endasmfunc\r
168 \r
169         .end\r
170 \r
171 ; -----------------------------------------------------------\r
172 \r