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 <sys/asm.h>
\r
30 #include "ISR_Support.h"
\r
36 .extern pxCurrentTCB
\r
37 .extern vTaskSwitchContext
\r
38 .extern vPortIncrementTick
\r
39 .extern xISRStackTop
\r
41 .global vPortStartFirstTask
\r
42 .global vPortYieldISR
\r
43 .global vPortTickInterruptHandler
\r
46 /******************************************************************/
\r
50 .ent vPortTickInterruptHandler
\r
52 vPortTickInterruptHandler:
\r
56 jal vPortIncrementTick
\r
61 .end vPortTickInterruptHandler
\r
63 /******************************************************************/
\r
67 .ent vPortStartFirstTask
\r
69 vPortStartFirstTask:
\r
71 /* Simply restore the context of the highest priority task that has been
\r
75 .end vPortStartFirstTask
\r
79 /*******************************************************************/
\r
87 /* Make room for the context. First save the current status so it can be
\r
89 addiu sp, sp, -portCONTEXT_SIZE
\r
90 mfc0 k1, _CP0_STATUS
\r
92 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
93 maintain the values of these registers across the ISR. */
\r
96 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
98 /* Prepare to re-enabled interrupt above the kernel priority. */
\r
100 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
103 /* s5 is used as the frame pointer. */
\r
106 /* Swap to the system stack. This is not conditional on the nesting
\r
107 count as this interrupt is always the lowest priority and therefore
\r
108 the nesting is always 0. */
\r
109 la sp, xISRStackTop
\r
112 /* Set the nesting count. */
\r
113 la k0, uxInterruptNesting
\r
117 /* s6 holds the EPC value, this is saved with the rest of the context
\r
118 after interrupts are enabled. */
\r
121 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
122 mtc0 k1, _CP0_STATUS
\r
124 /* Save the context into the space just created. s6 is saved again
\r
125 here as it now contains the EPC value. */
\r
145 sw s6, portEPC_STACK_LOCATION(s5)
\r
146 /* s5 and s6 has already been saved. */
\r
154 /* s7 is used as a scratch register as this should always be saved across
\r
155 nesting interrupts. */
\r
161 /* Save the stack pointer to the task. */
\r
162 la s7, pxCurrentTCB
\r
166 /* Set the interrupt mask to the max priority that can use the API. The
\r
167 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
168 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
169 raise the IPL value and never lower it. */
\r
172 mfc0 s7, _CP0_STATUS
\r
173 ins s7, zero, 10, 6
\r
174 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
176 /* This mtc0 re-enables interrupts, but only above
\r
177 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
178 mtc0 s6, _CP0_STATUS
\r
181 /* Clear the software interrupt in the core. */
\r
182 mfc0 s6, _CP0_CAUSE
\r
184 mtc0 s6, _CP0_CAUSE
\r
187 /* Clear the interrupt in the interrupt controller. */
\r
192 jal vTaskSwitchContext
\r
195 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
196 mtc0 s7, _CP0_STATUS
\r
199 /* Restore the stack pointer from the TCB. */
\r
200 la s0, pxCurrentTCB
\r
204 /* Restore the rest of the context. */
\r
215 /* s5 is loaded later. */
\r
237 /* Protect access to the k registers, and others. */
\r
241 /* Set nesting back to zero. As the lowest priority interrupt this
\r
242 interrupt cannot have nested. */
\r
243 la k0, uxInterruptNesting
\r
246 /* Switch back to use the real stack pointer. */
\r
249 /* Restore the real s5 value. */
\r
252 /* Pop the status and epc values. */
\r
253 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
254 lw k0, portEPC_STACK_LOCATION(sp)
\r
256 /* Remove stack frame. */
\r
257 addiu sp, sp, portCONTEXT_SIZE
\r
259 mtc0 k1, _CP0_STATUS
\r