2 * FreeRTOS Kernel V10.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
36 /* Hardware registers. */
\r
41 /* Variables and functions. */
\r
42 .extern ulMaxAPIPriorityMask
\r
43 .extern _freertos_vector_table
\r
44 .extern pxCurrentTCB
\r
45 .extern vTaskSwitchContext
\r
46 .extern vApplicationIRQHandler
\r
47 .extern ulPortInterruptNesting
\r
48 .extern ulPortTaskHasFPUContext
\r
50 .global FreeRTOS_IRQ_Handler
\r
51 .global FreeRTOS_SWI_Handler
\r
52 .global vPortRestoreTaskContext
\r
54 .macro portSAVE_CONTEXT
\r
56 /* Save the LR and SPSR onto the system mode stack before switching to
\r
57 system mode to save the remaining system mode registers. */
\r
58 SRSDB sp!, #SYS_MODE
\r
62 /* Push the critical nesting count. */
\r
63 LDR R2, ulCriticalNestingConst
\r
67 /* Does the task have a floating point context that needs saving? If
\r
68 ulPortTaskHasFPUContext is 0 then no. */
\r
69 LDR R2, ulPortTaskHasFPUContextConst
\r
73 /* Save the floating point context, if any. */
\r
76 /*VPUSHNE {D16-D31}*/
\r
79 /* Save ulPortTaskHasFPUContext itself. */
\r
82 /* Save the stack pointer in the TCB. */
\r
83 LDR R0, pxCurrentTCBConst
\r
89 ; /**********************************************************************/
\r
91 .macro portRESTORE_CONTEXT
\r
93 /* Set the SP to point to the stack of the task being restored. */
\r
94 LDR R0, pxCurrentTCBConst
\r
98 /* Is there a floating point context to restore? If the restored
\r
99 ulPortTaskHasFPUContext is zero then no. */
\r
100 LDR R0, ulPortTaskHasFPUContextConst
\r
105 /* Restore the floating point context, if any. */
\r
107 /*VPOPNE {D16-D31}*/
\r
111 /* Restore the critical section nesting depth. */
\r
112 LDR R0, ulCriticalNestingConst
\r
116 /* Ensure the priority mask is correct for the critical nesting depth. */
\r
117 LDR R2, ulICCPMRConst
\r
121 LDRNE R4, ulMaxAPIPriorityMaskConst
\r
125 /* Restore all system mode registers other than the SP (which is already
\r
129 /* Return to the task code, loading CPSR on the way. */
\r
137 /******************************************************************************
\r
138 * SVC handler is used to start the scheduler.
\r
139 *****************************************************************************/
\r
141 .type FreeRTOS_SWI_Handler, %function
\r
142 FreeRTOS_SWI_Handler:
\r
143 /* Save the context of the current task and select a new task to run. */
\r
145 LDR R0, vTaskSwitchContextConst
\r
147 portRESTORE_CONTEXT
\r
150 /******************************************************************************
\r
151 * vPortRestoreTaskContext is used to start the scheduler.
\r
152 *****************************************************************************/
\r
153 .type vPortRestoreTaskContext, %function
\r
154 vPortRestoreTaskContext:
\r
155 /* Switch to system mode. */
\r
157 portRESTORE_CONTEXT
\r
160 .type FreeRTOS_IRQ_Handler, %function
\r
161 FreeRTOS_IRQ_Handler:
\r
163 /* Return to the interrupted instruction. */
\r
166 /* Push the return address and SPSR. */
\r
171 /* Change to supervisor mode to allow reentry. */
\r
174 /* Push used registers. */
\r
177 /* Increment nesting count. r3 holds the address of ulPortInterruptNesting
\r
178 for future use. r1 holds the original ulPortInterruptNesting value for
\r
180 LDR r3, ulPortInterruptNestingConst
\r
185 /* Read value from the interrupt acknowledge register, which is stored in r0
\r
186 for future parameter and interrupt clearing use. */
\r
187 LDR r2, ulICCIARConst
\r
191 /* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
\r
192 future use. _RB_ Is this ever needed provided the start of the stack is
\r
193 alligned on an 8-byte boundary? */
\r
198 /* Call the interrupt handler. */
\r
200 LDR r1, vApplicationIRQHandlerConst
\r
209 /* Write the value read from ICCIAR to ICCEOIR. */
\r
210 LDR r4, ulICCEOIRConst
\r
214 /* Restore the old nesting count. */
\r
217 /* A context switch is never performed if the nesting count is not 0. */
\r
219 BNE exit_without_switch
\r
221 /* Did the interrupt request a context switch? r1 holds the address of
\r
222 ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
\r
224 LDR r1, =ulPortYieldRequired
\r
227 BNE switch_before_exit
\r
229 exit_without_switch:
\r
230 /* No context switch. Restore used registers, LR_irq and SPSR before
\r
239 switch_before_exit:
\r
240 /* A context swtich is to be performed. Clear the context switch pending
\r
245 /* Restore used registers, LR-irq and SPSR before saving the context
\r
246 to the task stack. */
\r
254 /* Call the function that selects the new task to execute.
\r
255 vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
\r
256 instructions, or 8 byte aligned stack allocated data. LR does not need
\r
257 saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
\r
258 LDR R0, vTaskSwitchContextConst
\r
261 /* Restore the context of, and branch to, the task selected to execute
\r
263 portRESTORE_CONTEXT
\r
265 ulICCIARConst: .word ulICCIAR
\r
266 ulICCEOIRConst: .word ulICCEOIR
\r
267 ulICCPMRConst: .word ulICCPMR
\r
268 pxCurrentTCBConst: .word pxCurrentTCB
\r
269 ulCriticalNestingConst: .word ulCriticalNesting
\r
270 ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
\r
271 ulMaxAPIPriorityMaskConst: .word ulMaxAPIPriorityMask
\r
272 vTaskSwitchContextConst: .word vTaskSwitchContext
\r
273 vApplicationIRQHandlerConst: .word vApplicationIRQHandler
\r
274 ulPortInterruptNestingConst: .word ulPortInterruptNesting
\r