]> begriffs open source - cmsis-freertos/blob - Source/portable/IAR/ARM_CM4F/portasm.s
Sources updated to FreeRTOS 10.2.0
[cmsis-freertos] / Source / portable / IAR / ARM_CM4F / portasm.s
1 /*
2  * FreeRTOS Kernel V10.2.0
3  * Copyright (C) 2019 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  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #include <FreeRTOSConfig.h>
29
30         RSEG    CODE:CODE(2)
31         thumb
32
33         EXTERN pxCurrentTCB
34         EXTERN vTaskSwitchContext
35
36         PUBLIC xPortPendSVHandler
37         PUBLIC vPortSVCHandler
38         PUBLIC vPortStartFirstTask
39         PUBLIC vPortEnableVFP
40
41
42 /*-----------------------------------------------------------*/
43
44 xPortPendSVHandler:
45         mrs r0, psp
46         isb
47         /* Get the location of the current TCB. */
48         ldr     r3, =pxCurrentTCB
49         ldr     r2, [r3]
50
51         /* Is the task using the FPU context?  If so, push high vfp registers. */
52         tst r14, #0x10
53         it eq
54         vstmdbeq r0!, {s16-s31}
55
56         /* Save the core registers. */
57         stmdb r0!, {r4-r11, r14}
58
59         /* Save the new top of stack into the first member of the TCB. */
60         str r0, [r2]
61
62         stmdb sp!, {r0, r3}
63         mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
64         msr basepri, r0
65         dsb
66         isb
67         bl vTaskSwitchContext
68         mov r0, #0
69         msr basepri, r0
70         ldmia sp!, {r0, r3}
71
72         /* The first item in pxCurrentTCB is the task top of stack. */
73         ldr r1, [r3]
74         ldr r0, [r1]
75
76         /* Pop the core registers. */
77         ldmia r0!, {r4-r11, r14}
78
79         /* Is the task using the FPU context?  If so, pop the high vfp registers
80         too. */
81         tst r14, #0x10
82         it eq
83         vldmiaeq r0!, {s16-s31}
84
85         msr psp, r0
86         isb
87         #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */
88                 #if WORKAROUND_PMU_CM001 == 1
89                         push { r14 }
90                         pop { pc }
91                 #endif
92         #endif
93
94         bx r14
95
96
97 /*-----------------------------------------------------------*/
98
99 vPortSVCHandler:
100         /* Get the location of the current TCB. */
101         ldr     r3, =pxCurrentTCB
102         ldr r1, [r3]
103         ldr r0, [r1]
104         /* Pop the core registers. */
105         ldmia r0!, {r4-r11, r14}
106         msr psp, r0
107         isb
108         mov r0, #0
109         msr     basepri, r0
110         bx r14
111
112 /*-----------------------------------------------------------*/
113
114 vPortStartFirstTask
115         /* Use the NVIC offset register to locate the stack. */
116         ldr r0, =0xE000ED08
117         ldr r0, [r0]
118         ldr r0, [r0]
119         /* Set the msp back to the start of the stack. */
120         msr msp, r0
121         /* Clear the bit that indicates the FPU is in use in case the FPU was used
122         before the scheduler was started - which would otherwise result in the
123         unnecessary leaving of space in the SVC stack for lazy saving of FPU
124         registers. */
125         mov r0, #0
126         msr control, r0
127         /* Call SVC to start the first task. */
128         cpsie i
129         cpsie f
130         dsb
131         isb
132         svc 0
133
134 /*-----------------------------------------------------------*/
135
136 vPortEnableVFP:
137         /* The FPU enable bits are in the CPACR. */
138         ldr.w r0, =0xE000ED88
139         ldr     r1, [r0]
140
141         /* Enable CP10 and CP11 coprocessors, then save back. */
142         orr     r1, r1, #( 0xf << 20 )
143         str r1, [r0]
144         bx      r14
145
146
147
148         END
149