2 * FreeRTOS Kernel V10.2.0
\r
3 * Copyright (C) 2019 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
35 /* Variables and functions. */
\r
36 .extern ulMaxAPIPriorityMask
\r
37 .extern _freertos_vector_table
\r
38 .extern pxCurrentTCB
\r
39 .extern vTaskSwitchContext
\r
40 .extern vApplicationIRQHandler
\r
41 .extern ulPortInterruptNesting
\r
42 .extern ulPortTaskHasFPUContext
\r
44 .extern ulPortYieldRequired
\r
46 .global FreeRTOS_IRQ_Handler
\r
47 .global FreeRTOS_SVC_Handler
\r
48 .global vPortRestoreTaskContext
\r
51 .macro portSAVE_CONTEXT
\r
53 /* Save the LR and SPSR onto the system mode stack before switching to
\r
54 system mode to save the remaining system mode registers. */
\r
55 SRSDB sp!, #SYS_MODE
\r
59 /* Push the critical nesting count. */
\r
60 LDR R2, ulCriticalNestingConst
\r
64 /* Does the task have a floating point context that needs saving? If
\r
65 ulPortTaskHasFPUContext is 0 then no. */
\r
66 LDR R2, ulPortTaskHasFPUContextConst
\r
70 /* Save the floating point context, if any. */
\r
73 #if configFPU_D32 == 1
\r
75 #endif /* configFPU_D32 */
\r
78 /* Save ulPortTaskHasFPUContext itself. */
\r
81 /* Save the stack pointer in the TCB. */
\r
82 LDR R0, pxCurrentTCBConst
\r
88 ; /**********************************************************************/
\r
90 .macro portRESTORE_CONTEXT
\r
92 /* Set the SP to point to the stack of the task being restored. */
\r
93 LDR R0, pxCurrentTCBConst
\r
97 /* Is there a floating point context to restore? If the restored
\r
98 ulPortTaskHasFPUContext is zero then no. */
\r
99 LDR R0, ulPortTaskHasFPUContextConst
\r
104 /* Restore the floating point context, if any. */
\r
106 #if configFPU_D32 == 1
\r
108 #endif /* configFPU_D32 */
\r
112 /* Restore the critical section nesting depth. */
\r
113 LDR R0, ulCriticalNestingConst
\r
117 /* Restore all system mode registers other than the SP (which is already
\r
121 /* Return to the task code, loading CPSR on the way. */
\r
129 /******************************************************************************
\r
130 * SVC handler is used to yield.
\r
131 *****************************************************************************/
\r
133 .type FreeRTOS_SVC_Handler, %function
\r
134 FreeRTOS_SVC_Handler:
\r
135 /* Save the context of the current task and select a new task to run. */
\r
137 LDR R0, vTaskSwitchContextConst
\r
139 portRESTORE_CONTEXT
\r
142 /******************************************************************************
\r
143 * vPortRestoreTaskContext is used to start the scheduler.
\r
144 *****************************************************************************/
\r
146 .type vPortRestoreTaskContext, %function
\r
147 vPortRestoreTaskContext:
\r
148 /* Switch to system mode. */
\r
150 portRESTORE_CONTEXT
\r
153 .type FreeRTOS_IRQ_Handler, %function
\r
154 FreeRTOS_IRQ_Handler:
\r
155 /* Return to the interrupted instruction. */
\r
158 /* Push the return address and SPSR. */
\r
163 /* Change to supervisor mode to allow reentry. */
\r
166 /* Push used registers. */
\r
169 /* Increment nesting count. r3 holds the address of ulPortInterruptNesting
\r
170 for future use. r1 holds the original ulPortInterruptNesting value for
\r
172 LDR r3, ulPortInterruptNestingConst
\r
177 /* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
\r
183 /* Call the interrupt handler. */
\r
185 LDR r1, vApplicationIRQHandlerConst
\r
194 /* Write to the EOI register. */
\r
195 LDR r0, ulICCEOIRConst
\r
199 /* Restore the old nesting count. */
\r
202 /* A context switch is never performed if the nesting count is not 0. */
\r
204 BNE exit_without_switch
\r
206 /* Did the interrupt request a context switch? r1 holds the address of
\r
207 ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
\r
209 LDR r1, ulPortYieldRequiredConst
\r
212 BNE switch_before_exit
\r
214 exit_without_switch:
\r
215 /* No context switch. Restore used registers, LR_irq and SPSR before
\r
224 switch_before_exit:
\r
225 /* A context swtich is to be performed. Clear the context switch pending
\r
230 /* Restore used registers, LR-irq and SPSR before saving the context
\r
231 to the task stack. */
\r
239 /* Call the function that selects the new task to execute.
\r
240 vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
\r
241 instructions, or 8 byte aligned stack allocated data. LR does not need
\r
242 saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
\r
243 LDR R0, vTaskSwitchContextConst
\r
246 /* Restore the context of, and branch to, the task selected to execute
\r
248 portRESTORE_CONTEXT
\r
250 ulICCEOIRConst: .word ulICCEOIR
\r
251 pxCurrentTCBConst: .word pxCurrentTCB
\r
252 ulCriticalNestingConst: .word ulCriticalNesting
\r
253 ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
\r
254 vTaskSwitchContextConst: .word vTaskSwitchContext
\r
255 vApplicationIRQHandlerConst: .word vApplicationIRQHandler
\r
256 ulPortInterruptNestingConst: .word ulPortInterruptNesting
\r
257 ulPortYieldRequiredConst: .word ulPortYieldRequired
\r