]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/ARM_CM4F_MPU/portasm.s
Roll up the minor changes checked into svn since V10.0.0 into new V10.0.1 ready for...
[freertos] / FreeRTOS / Source / portable / IAR / ARM_CM4F_MPU / portasm.s
1 /*\r
2  * FreeRTOS Kernel V10.0.1\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 #include <FreeRTOSConfig.h>\r
29 \r
30         RSEG    CODE:CODE(2)\r
31         thumb\r
32 \r
33         EXTERN pxCurrentTCB\r
34         EXTERN vTaskSwitchContext\r
35         EXTERN vPortSVCHandler_C\r
36 \r
37         PUBLIC xPortPendSVHandler\r
38         PUBLIC vPortSVCHandler\r
39         PUBLIC vPortStartFirstTask\r
40         PUBLIC vPortEnableVFP\r
41         PUBLIC vPortRestoreContextOfFirstTask\r
42         PUBLIC xPortRaisePrivilege\r
43 \r
44 /*-----------------------------------------------------------*/\r
45 \r
46 xPortPendSVHandler:\r
47         mrs r0, psp\r
48         isb\r
49         /* Get the location of the current TCB. */\r
50         ldr     r3, =pxCurrentTCB\r
51         ldr     r2, [r3]\r
52 \r
53         /* Is the task using the FPU context?  If so, push high vfp registers. */\r
54         tst r14, #0x10\r
55         it eq\r
56         vstmdbeq r0!, {s16-s31}\r
57 \r
58         /* Save the core registers. */\r
59         mrs r1, control\r
60         stmdb r0!, {r1, r4-r11, r14}\r
61 \r
62         /* Save the new top of stack into the first member of the TCB. */\r
63         str r0, [r2]\r
64 \r
65         stmdb sp!, {r0, r3}\r
66         mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
67         msr basepri, r0\r
68         dsb\r
69         isb\r
70         bl vTaskSwitchContext\r
71         mov r0, #0\r
72         msr basepri, r0\r
73         ldmia sp!, {r0, r3}\r
74 \r
75         /* The first item in pxCurrentTCB is the task top of stack. */\r
76         ldr r1, [r3]\r
77         ldr r0, [r1]\r
78         /* Move onto the second item in the TCB... */\r
79         add r1, r1, #4\r
80         /* Region Base Address register. */\r
81         ldr r2, =0xe000ed9c\r
82         /* Read 4 sets of MPU registers. */\r
83         ldmia r1!, {r4-r11}\r
84         /* Write 4 sets of MPU registers. */\r
85         stmia r2!, {r4-r11}\r
86         /* Pop the registers that are not automatically saved on exception entry. */\r
87         ldmia r0!, {r3-r11, r14}\r
88         msr control, r3\r
89 \r
90         /* Is the task using the FPU context?  If so, pop the high vfp registers\r
91         too. */\r
92         tst r14, #0x10\r
93         it eq\r
94         vldmiaeq r0!, {s16-s31}\r
95 \r
96         msr psp, r0\r
97         isb\r
98 \r
99         bx r14\r
100 \r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 vPortSVCHandler:\r
105         #ifndef USE_PROCESS_STACK       /* Code should not be required if a main() is using the process stack. */\r
106                 tst lr, #4\r
107                 ite eq\r
108                 mrseq r0, msp\r
109                 mrsne r0, psp\r
110         #else\r
111                 mrs r0, psp\r
112         #endif\r
113                 b vPortSVCHandler_C\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 vPortStartFirstTask\r
118         /* Use the NVIC offset register to locate the stack. */\r
119         ldr r0, =0xE000ED08\r
120         ldr r0, [r0]\r
121         ldr r0, [r0]\r
122         /* Set the msp back to the start of the stack. */\r
123         msr msp, r0\r
124         /* Clear the bit that indicates the FPU is in use in case the FPU was used\r
125         before the scheduler was started - which would otherwise result in the\r
126         unnecessary leaving of space in the SVC stack for lazy saving of FPU\r
127         registers. */\r
128         mov r0, #0\r
129         msr control, r0\r
130         /* Call SVC to start the first task. */\r
131         cpsie i\r
132         cpsie f\r
133         dsb\r
134         isb\r
135         svc 0\r
136 \r
137 /*-----------------------------------------------------------*/\r
138 \r
139 vPortRestoreContextOfFirstTask\r
140         /* Use the NVIC offset register to locate the stack. */\r
141         ldr r0, =0xE000ED08\r
142         ldr r0, [r0]\r
143         ldr r0, [r0]\r
144         /* Set the msp back to the start of the stack. */\r
145         msr msp, r0\r
146         /* Restore the context. */\r
147         ldr     r3, =pxCurrentTCB\r
148         ldr r1, [r3]\r
149         /* The first item in the TCB is the task top of stack. */\r
150         ldr r0, [r1]\r
151         /* Move onto the second item in the TCB... */\r
152         add r1, r1, #4\r
153         /* Region Base Address register. */\r
154         ldr r2, =0xe000ed9c\r
155         /* Read 4 sets of MPU registers. */\r
156         ldmia r1!, {r4-r11}\r
157         /* Write 4 sets of MPU registers. */\r
158         stmia r2!, {r4-r11}\r
159         /* Pop the registers that are not automatically saved on exception entry. */\r
160         ldmia r0!, {r3-r11, r14}\r
161         msr control, r3\r
162         /* Restore the task stack pointer. */\r
163         msr psp, r0\r
164         mov r0, #0\r
165         msr     basepri, r0\r
166         bx r14\r
167 \r
168 /*-----------------------------------------------------------*/\r
169 \r
170 vPortEnableVFP\r
171         /* The FPU enable bits are in the CPACR. */\r
172         ldr.w r0, =0xE000ED88\r
173         ldr     r1, [r0]\r
174 \r
175         /* Enable CP10 and CP11 coprocessors, then save back. */\r
176         orr     r1, r1, #( 0xf << 20 )\r
177         str r1, [r0]\r
178         bx      r14\r
179 \r
180 /*-----------------------------------------------------------*/\r
181 \r
182 xPortRaisePrivilege\r
183         mrs r0, control\r
184         /* Is the task running privileged? */\r
185         tst r0, #1\r
186         itte ne\r
187         /* CONTROL[0]!=0, return false. */\r
188         movne r0, #0\r
189         /* Switch to privileged. */\r
190         svcne 2 /* 2 == portSVC_RAISE_PRIVILEGE */\r
191         /* CONTROL[0]==0, return true. */\r
192         moveq r0, #1\r
193         bx lr\r
194 \r
195 \r
196         END\r
197 \r