2 * FreeRTOS Kernel V10.1.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.
\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
29 #include "FreeRTOSConfig.h"
\r
30 #include "ISR_Support.h"
\r
32 .extern pxCurrentTCB
\r
33 .extern vTaskSwitchContext
\r
34 .extern vPortCentralInterruptHandler
\r
35 .extern xTaskIncrementTick
\r
36 .extern vPortAPICErrorHandler
\r
37 .extern pucPortTaskFPUContextBuffer
\r
38 .extern ulPortYieldPending
\r
40 .global vPortStartFirstTask
\r
41 .global vPortCentralInterruptWrapper
\r
42 .global vPortAPICErrorHandlerWrapper
\r
43 .global vPortTimerHandler
\r
44 .global vPortYieldCall
\r
45 .global vPortAPICSpuriousHandler
\r
49 /*-----------------------------------------------------------*/
\r
52 .func vPortYieldCall
\r
54 /* Save general purpose registers. */
\r
57 .if configSUPPORT_FPU == 1
\r
59 /* If the task has a buffer allocated to save the FPU context then save
\r
60 the FPU context now. */
\r
61 movl pucPortTaskFPUContextBuffer, %eax
\r
69 /* Save the address of the FPU context, if any. */
\r
70 push pucPortTaskFPUContextBuffer
\r
72 .endif /* configSUPPORT_FPU */
\r
75 movl pxCurrentTCB, %eax
\r
77 /* Stack location is first item in the TCB. */
\r
80 call vTaskSwitchContext
\r
82 /* Find the location of pxCurrentTCB again - a callee saved register could
\r
83 be used in place of eax to prevent this second load, but that then relies
\r
84 on the compiler and other asm code. */
\r
85 movl pxCurrentTCB, %eax
\r
88 .if configSUPPORT_FPU == 1
\r
90 /* Restore address of task's FPU context buffer. */
\r
91 pop pucPortTaskFPUContextBuffer
\r
93 /* If the task has a buffer allocated in which its FPU context is saved,
\r
94 then restore it now. */
\r
95 movl pucPortTaskFPUContextBuffer, %eax
\r
106 /*-----------------------------------------------------------*/
\r
109 .func vPortStartFirstTask
\r
110 vPortStartFirstTask:
\r
112 /* Find the TCB. */
\r
113 movl pxCurrentTCB, %eax
\r
115 /* Stack location is first item in the TCB. */
\r
118 /* Restore FPU context flag. */
\r
119 .if configSUPPORT_FPU == 1
\r
121 pop pucPortTaskFPUContextBuffer
\r
123 .endif /* configSUPPORT_FPU */
\r
125 /* Restore general purpose registers. */
\r
129 /*-----------------------------------------------------------*/
\r
132 .func vPortAPICErrorHandlerWrapper
\r
133 vPortAPICErrorHandlerWrapper:
\r
135 call vPortAPICErrorHandler
\r
138 movl $0x00, (0xFEE000B0)
\r
141 /*-----------------------------------------------------------*/
\r
144 .func vPortTimerHandler
\r
147 /* Save general purpose registers. */
\r
150 /* Interrupts are not nested, so save the rest of the task context. */
\r
151 .if configSUPPORT_FPU == 1
\r
153 /* If the task has a buffer allocated to save the FPU context then save the
\r
154 FPU context now. */
\r
155 movl pucPortTaskFPUContextBuffer, %eax
\r
158 fnsave ( %eax ) /* Save FLOP context into ucTempFPUBuffer array. */
\r
162 /* Save the address of the FPU context, if any. */
\r
163 push pucPortTaskFPUContextBuffer
\r
165 .endif /* configSUPPORT_FPU */
\r
167 /* Find the TCB. */
\r
168 movl pxCurrentTCB, %eax
\r
170 /* Stack location is first item in the TCB. */
\r
173 /* Switch stacks. */
\r
174 movl ulTopOfSystemStack, %esp
\r
177 /* Increment nesting count. */
\r
178 add $1, ulInterruptNesting
\r
180 call xTaskIncrementTick
\r
184 /* Is a switch to another task required? */
\r
186 je _skip_context_switch
\r
188 call vTaskSwitchContext
\r
190 _skip_context_switch:
\r
193 /* Decrement the variable used to determine if a switch to a system
\r
194 stack is necessary. */
\r
195 sub $1, ulInterruptNesting
\r
197 /* Stack location is first item in the TCB. */
\r
198 movl pxCurrentTCB, %eax
\r
201 .if configSUPPORT_FPU == 1
\r
203 /* Restore address of task's FPU context buffer. */
\r
204 pop pucPortTaskFPUContextBuffer
\r
206 /* If the task has a buffer allocated in which its FPU context is saved,
\r
207 then restore it now. */
\r
208 movl pucPortTaskFPUContextBuffer, %eax
\r
218 movl $0x00, (0xFEE000B0)
\r
222 /*-----------------------------------------------------------*/
\r
224 .if configUSE_COMMON_INTERRUPT_ENTRY_POINT == 1
\r
227 .func vPortCentralInterruptWrapper
\r
228 vPortCentralInterruptWrapper:
\r
230 portFREERTOS_INTERRUPT_ENTRY
\r
232 movl $0xFEE00170, %eax /* Highest In Service Register (ISR) long word. */
\r
233 movl $8, %ecx /* Loop counter. */
\r
235 next_isr_long_word:
\r
236 test %ecx, %ecx /* Loop counter reached 0? */
\r
237 je wrapper_epilogue /* Looked at all ISR registers without finding a bit set. */
\r
238 sub $1, %ecx /* Sub 1 from loop counter. */
\r
239 movl (%eax), %ebx /* Load next ISR long word. */
\r
240 sub $0x10, %eax /* Point to next ISR long word in case no bits are set in the current long word. */
\r
241 test %ebx, %ebx /* Are there any bits set? */
\r
242 je next_isr_long_word /* Look at next ISR long word if no bits were set. */
\r
244 bsr %ebx, %ebx /* A bit was set, which one? */
\r
245 movl $32, %eax /* Destination operand for following multiplication. */
\r
246 mul %ecx /* Calculate base vector for current register, 32 vectors per register. */
\r
247 add %ebx, %eax /* Add bit offset into register to get final vector number. */
\r
248 push %eax /* Vector number is function parameter. */
\r
249 call vPortCentralInterruptHandler
\r
250 pop %eax /* Remove parameter. */
\r
253 portFREERTOS_INTERRUPT_EXIT
\r
257 .endif /* configUSE_COMMON_INTERRUPT_ENTRY_POINT */
\r
258 /*-----------------------------------------------------------*/
\r
261 .func vPortAPISpuriousHandler
\r
262 vPortAPICSpuriousHandler:
\r