2 * FreeRTOS Kernel V10.6.2
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 /* Including FreeRTOSConfig.h here will cause build errors if the header file
30 contains code not understood by the assembler - for example the 'extern' keyword.
31 To avoid errors place any such code inside a #ifdef __ICCARM__/#endif block so
32 the code is included in C files but excluded by the preprocessor in assembly
33 files (__ICCARM__ is defined by the IAR C compiler but not by the IAR assembler. */
34 #include "FreeRTOSConfig.h"
36 /* System call numbers includes. */
37 #include "mpu_syscall_numbers.h"
39 #ifndef configUSE_MPU_WRAPPERS_V1
40 #define configUSE_MPU_WRAPPERS_V1 0
45 EXTERN vTaskSwitchContext
46 EXTERN vPortSVCHandler_C
47 EXTERN SecureContext_SaveContext
48 EXTERN SecureContext_LoadContext
49 #if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
50 EXTERN vSystemCallEnter
51 EXTERN vSystemCallExit
55 PUBLIC vResetPrivilege
56 PUBLIC vPortAllocateSecureContext
57 PUBLIC vRestoreContextOfFirstTask
58 PUBLIC vRaisePrivilege
59 PUBLIC vStartFirstTask
60 PUBLIC ulSetInterruptMask
61 PUBLIC vClearInterruptMask
64 PUBLIC vPortFreeSecureContext
66 #if ( configENABLE_FPU == 1 )
67 #error Cortex-M23 does not have a Floating Point Unit (FPU) and therefore configENABLE_FPU must be set to 0.
69 /*-----------------------------------------------------------*/
71 /*---------------- Unprivileged Functions -------------------*/
73 /*-----------------------------------------------------------*/
75 SECTION .text:CODE:NOROOT(2)
77 /*-----------------------------------------------------------*/
80 mrs r0, control /* r0 = CONTROL. */
81 movs r1, #1 /* r1 = 1. */
82 tst r0, r1 /* Perform r0 & r1 (bitwise AND) and update the conditions flag. */
83 beq running_privileged /* If the result of previous AND operation was 0, branch. */
84 movs r0, #0 /* CONTROL[0]!=0. Return false to indicate that the processor is not privileged. */
87 movs r0, #1 /* CONTROL[0]==0. Return true to indicate that the processor is privileged. */
89 /*-----------------------------------------------------------*/
92 mrs r0, control /* r0 = CONTROL. */
93 movs r1, #1 /* r1 = 1. */
94 orrs r0, r1 /* r0 = r0 | r1. */
95 msr control, r0 /* CONTROL = r0. */
96 bx lr /* Return to the caller. */
97 /*-----------------------------------------------------------*/
99 vPortAllocateSecureContext:
100 svc 100 /* Secure context is allocated in the supervisor call. portSVC_ALLOCATE_SECURE_CONTEXT = 100. */
102 /*-----------------------------------------------------------*/
104 /*----------------- Privileged Functions --------------------*/
106 /*-----------------------------------------------------------*/
108 SECTION privileged_functions:CODE:NOROOT(2)
110 /*-----------------------------------------------------------*/
112 #if ( configENABLE_MPU == 1 )
114 vRestoreContextOfFirstTask:
115 program_mpu_first_task:
116 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
117 ldr r0, [r3] /* r0 = pxCurrentTCB.*/
119 dmb /* Complete outstanding transfers before disabling MPU. */
120 ldr r1, =0xe000ed94 /* r1 = 0xe000ed94 [Location of MPU_CTRL]. */
121 ldr r2, [r1] /* Read the value of MPU_CTRL. */
122 movs r3, #1 /* r3 = 1. */
123 bics r2, r3 /* r2 = r2 & ~r3 i.e. Clear the bit 0 in r2. */
124 str r2, [r1] /* Disable MPU. */
126 adds r0, #4 /* r0 = r0 + 4. r0 now points to MAIR0 in TCB. */
127 ldr r1, [r0] /* r1 = *r0 i.e. r1 = MAIR0. */
128 ldr r2, =0xe000edc0 /* r2 = 0xe000edc0 [Location of MAIR0]. */
129 str r1, [r2] /* Program MAIR0. */
131 adds r0, #4 /* r0 = r0 + 4. r0 now points to first RBAR in TCB. */
132 ldr r1, =0xe000ed98 /* r1 = 0xe000ed98 [Location of RNR]. */
134 movs r3, #4 /* r3 = 4. */
135 str r3, [r1] /* Program RNR = 4. */
136 ldmia r0!, {r4-r5} /* Read first set of RBAR/RLAR registers from TCB. */
137 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
138 stmia r2!, {r4-r5} /* Write first set of RBAR/RLAR registers. */
139 movs r3, #5 /* r3 = 5. */
140 str r3, [r1] /* Program RNR = 5. */
141 ldmia r0!, {r4-r5} /* Read second set of RBAR/RLAR registers from TCB. */
142 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
143 stmia r2!, {r4-r5} /* Write second set of RBAR/RLAR registers. */
144 movs r3, #6 /* r3 = 6. */
145 str r3, [r1] /* Program RNR = 6. */
146 ldmia r0!, {r4-r5} /* Read third set of RBAR/RLAR registers from TCB. */
147 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
148 stmia r2!, {r4-r5} /* Write third set of RBAR/RLAR registers. */
149 movs r3, #7 /* r3 = 6. */
150 str r3, [r1] /* Program RNR = 7. */
151 ldmia r0!, {r4-r5} /* Read fourth set of RBAR/RLAR registers from TCB. */
152 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
153 stmia r2!, {r4-r5} /* Write fourth set of RBAR/RLAR registers. */
155 ldr r1, =0xe000ed94 /* r1 = 0xe000ed94 [Location of MPU_CTRL]. */
156 ldr r2, [r1] /* Read the value of MPU_CTRL. */
157 movs r3, #1 /* r3 = 1. */
158 orrs r2, r3 /* r2 = r2 | r3 i.e. Set the bit 0 in r2. */
159 str r2, [r1] /* Enable MPU. */
160 dsb /* Force memory writes before continuing. */
162 restore_context_first_task:
163 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
164 ldr r1, [r3] /* r1 = pxCurrentTCB.*/
165 ldr r2, [r1] /* r2 = Location of saved context in TCB. */
167 restore_special_regs_first_task:
169 ldmia r2!, {r0, r3-r6} /* r0 = xSecureContext, r3 = original PSP, r4 = PSPLIM, r5 = CONTROL, r6 = LR. */
175 ldr r4, =xSecureContext /* Read the location of xSecureContext i.e. &( xSecureContext ). */
176 str r0, [r4] /* Restore xSecureContext. */
178 restore_general_regs_first_task:
180 ldmia r2!, {r4-r7} /* r4-r7 contain half of the hardware saved context. */
181 stmia r3!, {r4-r7} /* Copy half of the the hardware saved context on the task stack. */
182 ldmia r2!, {r4-r7} /* r4-r7 contain rest half of the hardware saved context. */
183 stmia r3!, {r4-r7} /* Copy rest half of the the hardware saved context on the task stack. */
185 ldmia r2!, {r4-r7} /* Restore r8-r11. */
186 mov r8, r4 /* r8 = r4. */
187 mov r9, r5 /* r9 = r5. */
188 mov r10, r6 /* r10 = r6. */
189 mov r11, r7 /* r11 = r7. */
191 ldmia r2!, {r4-r7} /* Restore r4-r7. */
194 restore_context_done_first_task:
195 str r2, [r1] /* Save the location where the context should be saved next as the first member of TCB. */
198 #else /* configENABLE_MPU */
200 vRestoreContextOfFirstTask:
201 ldr r2, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
202 ldr r3, [r2] /* Read pxCurrentTCB. */
203 ldr r0, [r3] /* Read top of stack from TCB - The first item in pxCurrentTCB is the task top of stack. */
205 ldm r0!, {r1-r3} /* Read from stack - r1 = xSecureContext, r2 = PSPLIM and r3 = EXC_RETURN. */
206 ldr r4, =xSecureContext
207 str r1, [r4] /* Set xSecureContext to this task's value for the same. */
208 msr psplim, r2 /* Set this task's PSPLIM value. */
209 movs r1, #2 /* r1 = 2. */
210 msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
211 adds r0, #32 /* Discard everything up to r0. */
212 msr psp, r0 /* This is now the new top of stack to use in the task. */
214 bx r3 /* Finally, branch to EXC_RETURN. */
216 #endif /* configENABLE_MPU */
217 /*-----------------------------------------------------------*/
220 mrs r0, control /* Read the CONTROL register. */
221 movs r1, #1 /* r1 = 1. */
222 bics r0, r1 /* Clear the bit 0. */
223 msr control, r0 /* Write back the new CONTROL value. */
224 bx lr /* Return to the caller. */
225 /*-----------------------------------------------------------*/
228 ldr r0, =0xe000ed08 /* Use the NVIC offset register to locate the stack. */
229 ldr r0, [r0] /* Read the VTOR register which gives the address of vector table. */
230 ldr r0, [r0] /* The first entry in vector table is stack pointer. */
231 msr msp, r0 /* Set the MSP back to the start of the stack. */
232 cpsie i /* Globally enable interrupts. */
235 svc 102 /* System call to start the first task. portSVC_START_SCHEDULER = 102. */
236 /*-----------------------------------------------------------*/
242 /*-----------------------------------------------------------*/
247 /*-----------------------------------------------------------*/
248 #if ( configENABLE_MPU == 1 )
251 ldr r3, =xSecureContext /* Read the location of xSecureContext i.e. &( xSecureContext ). */
252 ldr r0, [r3] /* Read xSecureContext - Value of xSecureContext must be in r0 as it is used as a parameter later. */
253 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
254 ldr r1, [r3] /* Read pxCurrentTCB - Value of pxCurrentTCB must be in r1 as it is used as a parameter later.*/
255 ldr r2, [r1] /* r2 = Location in TCB where the context should be saved. */
257 cbz r0, save_ns_context /* No secure context to save. */
260 bl SecureContext_SaveContext /* Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. */
261 pop {r0-r3} /* LR is now in r3. */
262 mov lr, r3 /* Restore LR. */
265 mov r3, lr /* r3 = LR (EXC_RETURN). */
266 lsls r3, r3, #25 /* r3 = r3 << 25. Bit[6] of EXC_RETURN is 1 if secure stack was used, 0 if non-secure stack was used to store stack frame. */
267 bmi save_special_regs /* r3 < 0 ==> Bit[6] in EXC_RETURN is 1 ==> secure stack was used to store the stack frame. */
271 stmia r2!, {r4-r7} /* Store r4-r7. */
272 mov r4, r8 /* r4 = r8. */
273 mov r5, r9 /* r5 = r9. */
274 mov r6, r10 /* r6 = r10. */
275 mov r7, r11 /* r7 = r11. */
276 stmia r2!, {r4-r7} /* Store r8-r11. */
277 ldmia r3!, {r4-r7} /* Copy half of the hardware saved context into r4-r7. */
278 stmia r2!, {r4-r7} /* Store the hardware saved context. */
279 ldmia r3!, {r4-r7} /* Copy rest half of the hardware saved context into r4-r7. */
280 stmia r2!, {r4-r7} /* Store the hardware saved context. */
283 mrs r3, psp /* r3 = PSP. */
284 mrs r4, psplim /* r4 = PSPLIM. */
285 mrs r5, control /* r5 = CONTROL. */
286 mov r6, lr /* r6 = LR. */
287 stmia r2!, {r0, r3-r6} /* Store xSecureContext, original PSP (after hardware has saved context), PSPLIM, CONTROL and LR. */
288 str r2, [r1] /* Save the location from where the context should be restored as the first member of TCB. */
292 bl vTaskSwitchContext
296 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
297 ldr r0, [r3] /* r0 = pxCurrentTCB.*/
299 dmb /* Complete outstanding transfers before disabling MPU. */
300 ldr r1, =0xe000ed94 /* r1 = 0xe000ed94 [Location of MPU_CTRL]. */
301 ldr r2, [r1] /* Read the value of MPU_CTRL. */
302 movs r3, #1 /* r3 = 1. */
303 bics r2, r3 /* r2 = r2 & ~r3 i.e. Clear the bit 0 in r2. */
304 str r2, [r1] /* Disable MPU. */
306 adds r0, #4 /* r0 = r0 + 4. r0 now points to MAIR0 in TCB. */
307 ldr r1, [r0] /* r1 = *r0 i.e. r1 = MAIR0. */
308 ldr r2, =0xe000edc0 /* r2 = 0xe000edc0 [Location of MAIR0]. */
309 str r1, [r2] /* Program MAIR0. */
311 adds r0, #4 /* r0 = r0 + 4. r0 now points to first RBAR in TCB. */
312 ldr r1, =0xe000ed98 /* r1 = 0xe000ed98 [Location of RNR]. */
314 movs r3, #4 /* r3 = 4. */
315 str r3, [r1] /* Program RNR = 4. */
316 ldmia r0!, {r4-r5} /* Read first set of RBAR/RLAR registers from TCB. */
317 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
318 stmia r2!, {r4-r5} /* Write first set of RBAR/RLAR registers. */
319 movs r3, #5 /* r3 = 5. */
320 str r3, [r1] /* Program RNR = 5. */
321 ldmia r0!, {r4-r5} /* Read second set of RBAR/RLAR registers from TCB. */
322 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
323 stmia r2!, {r4-r5} /* Write second set of RBAR/RLAR registers. */
324 movs r3, #6 /* r3 = 6. */
325 str r3, [r1] /* Program RNR = 6. */
326 ldmia r0!, {r4-r5} /* Read third set of RBAR/RLAR registers from TCB. */
327 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
328 stmia r2!, {r4-r5} /* Write third set of RBAR/RLAR registers. */
329 movs r3, #7 /* r3 = 6. */
330 str r3, [r1] /* Program RNR = 7. */
331 ldmia r0!, {r4-r5} /* Read fourth set of RBAR/RLAR registers from TCB. */
332 ldr r2, =0xe000ed9c /* r2 = 0xe000ed9c [Location of RBAR]. */
333 stmia r2!, {r4-r5} /* Write fourth set of RBAR/RLAR registers. */
335 ldr r1, =0xe000ed94 /* r1 = 0xe000ed94 [Location of MPU_CTRL]. */
336 ldr r2, [r1] /* Read the value of MPU_CTRL. */
337 movs r3, #1 /* r3 = 1. */
338 orrs r2, r3 /* r2 = r2 | r3 i.e. Set the bit 0 in r2. */
339 str r2, [r1] /* Enable MPU. */
340 dsb /* Force memory writes before continuing. */
343 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
344 ldr r1, [r3] /* r1 = pxCurrentTCB.*/
345 ldr r2, [r1] /* r2 = Location of saved context in TCB. */
347 restore_special_regs:
349 ldmia r2!, {r0, r3-r6} /* r0 = xSecureContext, r3 = original PSP, r4 = PSPLIM, r5 = CONTROL, r6 = LR. */
355 ldr r4, =xSecureContext /* Read the location of xSecureContext i.e. &( xSecureContext ). */
356 str r0, [r4] /* Restore xSecureContext. */
357 cbz r0, restore_ns_context /* No secure context to restore. */
361 bl SecureContext_LoadContext /* Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. */
362 pop {r1-r4} /* LR is now in r4. */
366 mov r0, lr /* r0 = LR (EXC_RETURN). */
367 lsls r0, r0, #25 /* r0 = r0 << 25. Bit[6] of EXC_RETURN is 1 if secure stack was used, 0 if non-secure stack was used to store stack frame. */
368 bmi restore_context_done /* r0 < 0 ==> Bit[6] in EXC_RETURN is 1 ==> secure stack was used to store the stack frame. */
370 restore_general_regs:
372 ldmia r2!, {r4-r7} /* r4-r7 contain half of the hardware saved context. */
373 stmia r3!, {r4-r7} /* Copy half of the the hardware saved context on the task stack. */
374 ldmia r2!, {r4-r7} /* r4-r7 contain rest half of the hardware saved context. */
375 stmia r3!, {r4-r7} /* Copy rest half of the the hardware saved context on the task stack. */
377 ldmia r2!, {r4-r7} /* Restore r8-r11. */
378 mov r8, r4 /* r8 = r4. */
379 mov r9, r5 /* r9 = r5. */
380 mov r10, r6 /* r10 = r6. */
381 mov r11, r7 /* r11 = r7. */
383 ldmia r2!, {r4-r7} /* Restore r4-r7. */
386 restore_context_done:
387 str r2, [r1] /* Save the location where the context should be saved next as the first member of TCB. */
390 #else /* configENABLE_MPU */
393 ldr r3, =xSecureContext /* Read the location of xSecureContext i.e. &( xSecureContext ). */
394 ldr r0, [r3] /* Read xSecureContext - Value of xSecureContext must be in r0 as it is used as a parameter later. */
395 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
396 ldr r1, [r3] /* Read pxCurrentTCB - Value of pxCurrentTCB must be in r1 as it is used as a parameter later. */
397 mrs r2, psp /* Read PSP in r2. */
399 cbz r0, save_ns_context /* No secure context to save. */
401 bl SecureContext_SaveContext /* Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. */
402 pop {r0-r3} /* LR is now in r3. */
403 mov lr, r3 /* LR = r3. */
404 lsls r1, r3, #25 /* r1 = r3 << 25. Bit[6] of EXC_RETURN is 1 if secure stack was used, 0 if non-secure stack was used to store stack frame. */
405 bpl save_ns_context /* bpl - branch if positive or zero. If r1 >= 0 ==> Bit[6] in EXC_RETURN is 0 i.e. non-secure stack was used. */
406 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
407 ldr r1, [r3] /* Read pxCurrentTCB. */
409 subs r2, r2, #12 /* Make space for xSecureContext, PSPLIM and LR on the stack. */
410 str r2, [r1] /* Save the new top of stack in TCB. */
411 mrs r1, psplim /* r1 = PSPLIM. */
412 mov r3, lr /* r3 = LR/EXC_RETURN. */
413 stmia r2!, {r0, r1, r3} /* Store xSecureContext, PSPLIM and LR on the stack. */
418 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
419 ldr r1, [r3] /* Read pxCurrentTCB. */
420 subs r2, r2, #44 /* Make space for xSecureContext, PSPLIM, LR and the remaining registers on the stack. */
421 str r2, [r1] /* Save the new top of stack in TCB. */
422 mrs r1, psplim /* r1 = PSPLIM. */
423 mov r3, lr /* r3 = LR/EXC_RETURN. */
424 stmia r2!, {r0, r1, r3-r7} /* Store xSecureContext, PSPLIM, LR and the low registers that are not saved automatically. */
425 mov r4, r8 /* r4 = r8. */
426 mov r5, r9 /* r5 = r9. */
427 mov r6, r10 /* r6 = r10. */
428 mov r7, r11 /* r7 = r11. */
429 stmia r2!, {r4-r7} /* Store the high registers that are not saved automatically. */
433 bl vTaskSwitchContext
436 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
437 ldr r1, [r3] /* Read pxCurrentTCB. */
438 ldr r2, [r1] /* The first item in pxCurrentTCB is the task top of stack. r2 now points to the top of stack. */
440 ldmia r2!, {r0, r1, r4} /* Read from stack - r0 = xSecureContext, r1 = PSPLIM and r4 = LR. */
441 msr psplim, r1 /* Restore the PSPLIM register value for the task. */
442 mov lr, r4 /* LR = r4. */
443 ldr r3, =xSecureContext /* Read the location of xSecureContext i.e. &( xSecureContext ). */
444 str r0, [r3] /* Restore the task's xSecureContext. */
445 cbz r0, restore_ns_context /* If there is no secure context for the task, restore the non-secure context. */
446 ldr r3, =pxCurrentTCB /* Read the location of pxCurrentTCB i.e. &( pxCurrentTCB ). */
447 ldr r1, [r3] /* Read pxCurrentTCB. */
449 bl SecureContext_LoadContext /* Restore the secure context. Params are in r0 and r1. r0 = xSecureContext and r1 = pxCurrentTCB. */
451 mov lr, r4 /* LR = r4. */
452 lsls r1, r4, #25 /* r1 = r4 << 25. Bit[6] of EXC_RETURN is 1 if secure stack was used, 0 if non-secure stack was used to store stack frame. */
453 bpl restore_ns_context /* bpl - branch if positive or zero. If r1 >= 0 ==> Bit[6] in EXC_RETURN is 0 i.e. non-secure stack was used. */
454 msr psp, r2 /* Remember the new top of stack for the task. */
458 adds r2, r2, #16 /* Move to the high registers. */
459 ldmia r2!, {r4-r7} /* Restore the high registers that are not automatically restored. */
460 mov r8, r4 /* r8 = r4. */
461 mov r9, r5 /* r9 = r5. */
462 mov r10, r6 /* r10 = r6. */
463 mov r11, r7 /* r11 = r7. */
464 msr psp, r2 /* Remember the new top of stack for the task. */
465 subs r2, r2, #32 /* Go back to the low registers. */
466 ldmia r2!, {r4-r7} /* Restore the low registers that are not automatically restored. */
469 #endif /* configENABLE_MPU */
470 /*-----------------------------------------------------------*/
472 #if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) )
490 cmp r2, #NUM_SYSTEM_CALLS
491 blt system_call_enter
492 cmp r2, #104 /* portSVC_SYSTEM_CALL_EXIT. */
501 #else /* ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
507 beq stacking_used_msp
514 #endif /* ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) */
515 /*-----------------------------------------------------------*/
517 vPortFreeSecureContext:
518 ldr r2, [r0] /* The first item in the TCB is the top of the stack. */
519 ldr r1, [r2] /* The first item on the stack is the task's xSecureContext. */
520 cmp r1, #0 /* Raise svc if task's xSecureContext is not NULL. */
521 bne free_secure_context /* Branch if r1 != 0. */
522 bx lr /* There is no secure context (xSecureContext is NULL). */
524 svc 101 /* Secure context is freed in the supervisor call. portSVC_FREE_SECURE_CONTEXT = 101. */
526 /*-----------------------------------------------------------*/