2 * FreeRTOS Kernel V10.0.1
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 #include <FreeRTOSConfig.h>
\r
34 EXTERN vTaskSwitchContext
\r
35 EXTERN vPortSVCHandler_C
\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
44 /*-----------------------------------------------------------*/
\r
49 /* Get the location of the current TCB. */
\r
50 ldr r3, =pxCurrentTCB
\r
53 /* Is the task using the FPU context? If so, push high vfp registers. */
\r
56 vstmdbeq r0!, {s16-s31}
\r
58 /* Save the core registers. */
\r
60 stmdb r0!, {r1, r4-r11, r14}
\r
62 /* Save the new top of stack into the first member of the TCB. */
\r
66 mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
\r
70 bl vTaskSwitchContext
\r
75 /* The first item in pxCurrentTCB is the task top of stack. */
\r
78 /* Move onto the second item in the TCB... */
\r
80 /* Region Base Address register. */
\r
82 /* Read 4 sets of MPU registers. */
\r
84 /* Write 4 sets of MPU registers. */
\r
86 /* Pop the registers that are not automatically saved on exception entry. */
\r
87 ldmia r0!, {r3-r11, r14}
\r
90 /* Is the task using the FPU context? If so, pop the high vfp registers
\r
94 vldmiaeq r0!, {s16-s31}
\r
102 /*-----------------------------------------------------------*/
\r
105 #ifndef USE_PROCESS_STACK /* Code should not be required if a main() is using the process stack. */
\r
113 b vPortSVCHandler_C
\r
115 /*-----------------------------------------------------------*/
\r
117 vPortStartFirstTask
\r
118 /* Use the NVIC offset register to locate the stack. */
\r
119 ldr r0, =0xE000ED08
\r
122 /* Set the msp back to the start of the stack. */
\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
130 /* Call SVC to start the first task. */
\r
137 /*-----------------------------------------------------------*/
\r
139 vPortRestoreContextOfFirstTask
\r
140 /* Use the NVIC offset register to locate the stack. */
\r
141 ldr r0, =0xE000ED08
\r
144 /* Set the msp back to the start of the stack. */
\r
146 /* Restore the context. */
\r
147 ldr r3, =pxCurrentTCB
\r
149 /* The first item in the TCB is the task top of stack. */
\r
151 /* Move onto the second item in the TCB... */
\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
162 /* Restore the task stack pointer. */
\r
168 /*-----------------------------------------------------------*/
\r
171 /* The FPU enable bits are in the CPACR. */
\r
172 ldr.w r0, =0xE000ED88
\r
175 /* Enable CP10 and CP11 coprocessors, then save back. */
\r
176 orr r1, r1, #( 0xf << 20 )
\r
180 /*-----------------------------------------------------------*/
\r
182 xPortRaisePrivilege
\r
184 /* Is the task running privileged? */
\r
187 /* CONTROL[0]!=0, return false. */
\r
189 /* Switch to privileged. */
\r
190 svcne 2 /* 2 == portSVC_RAISE_PRIVILEGE */
\r
191 /* CONTROL[0]==0, return true. */
\r