]> begriffs open source - freertos/blob - portable/CCS/ARM_CM3/portasm.asm
Update SMP branch readme for port migration (#999)
[freertos] / portable / CCS / ARM_CM3 / 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
39 NVICOffsetConst:                                        .word   0xE000ED08
40 CPACRConst:                                                     .word   0xE000ED88
41 pxCurrentTCBConst:                                      .word   pxCurrentTCB
42 ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority
43
44 ; -----------------------------------------------------------
45
46         .align 4
47 ulPortGetIPSR: .asmfunc
48         mrs r0, ipsr
49         bx r14
50         .endasmfunc
51  ; -----------------------------------------------------------
52
53         .align 4
54 vPortSetInterruptMask: .asmfunc
55         push {r0}
56         ldr r0, ulMaxSyscallInterruptPriorityConst
57         msr basepri, r0
58         pop {r0}
59         bx r14
60         .endasmfunc
61 ; -----------------------------------------------------------
62
63         .align 4
64 xPortPendSVHandler: .asmfunc
65         mrs r0, psp
66         isb
67
68         ;/* Get the location of the current TCB. */
69         ldr     r3, pxCurrentTCBConst
70         ldr     r2, [r3]
71
72         ;/* Save the core registers. */
73         stmdb r0!, {r4-r11}
74
75         ;/* Save the new top of stack into the first member of the TCB. */
76         str r0, [r2]
77
78         stmdb sp!, {r3, r14}
79         ldr r0, ulMaxSyscallInterruptPriorityConst
80         ldr r1, [r0]
81         msr basepri, r1
82         dsb
83         isb
84         bl vTaskSwitchContext
85         mov r0, #0
86         msr basepri, r0
87         ldmia sp!, {r3, r14}
88
89         ;/* The first item in pxCurrentTCB is the task top of stack. */
90         ldr r1, [r3]
91         ldr r0, [r1]
92
93         ;/* Pop the core registers. */
94         ldmia r0!, {r4-r11}
95
96         msr psp, r0
97         isb
98         bx r14
99         .endasmfunc
100
101 ; -----------------------------------------------------------
102
103         .align 4
104 vPortSVCHandler: .asmfunc
105         ;/* Get the location of the current TCB. */
106         ldr     r3, pxCurrentTCBConst
107         ldr r1, [r3]
108         ldr r0, [r1]
109         ;/* Pop the core registers. */
110         ldmia r0!, {r4-r11}
111         msr psp, r0
112         isb
113         mov r0, #0
114         msr     basepri, r0
115         orr r14, #0xd
116         bx r14
117         .endasmfunc
118
119 ; -----------------------------------------------------------
120
121         .align 4
122 vPortStartFirstTask: .asmfunc
123         ;/* Use the NVIC offset register to locate the stack. */
124         ldr r0, NVICOffsetConst
125         ldr r0, [r0]
126         ldr r0, [r0]
127         ;/* Set the msp back to the start of the stack. */
128         msr msp, r0
129         ;/* Clear the bit that indicates the FPU is in use in case the FPU was used
130         ;before the scheduler was started - which would otherwise result in the
131         ;unnecessary leaving of space in the SVC stack for lazy saving of FPU
132         ;registers. */
133         mov r0, #0
134         msr control, r0
135         ;/* Call SVC to start the first task. */
136         cpsie i
137         cpsie f
138         dsb
139         isb
140         svc #0
141         .endasmfunc
142
143 ; -----------------------------------------------------------
144