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
30 #include <sys/asm.h>
\r
31 #include "ISR_Support.h"
\r
37 .extern pxCurrentTCB
\r
38 .extern vTaskSwitchContext
\r
39 .extern vPortIncrementTick
\r
40 .extern xISRStackTop
\r
42 .global vPortStartFirstTask
\r
43 .global vPortYieldISR
\r
44 .global vPortTickInterruptHandler
\r
47 /******************************************************************/
\r
51 .ent vPortTickInterruptHandler
\r
53 vPortTickInterruptHandler:
\r
57 jal vPortIncrementTick
\r
62 .end vPortTickInterruptHandler
\r
64 /******************************************************************/
\r
68 .ent vPortStartFirstTask
\r
70 vPortStartFirstTask:
\r
72 /* Simply restore the context of the highest priority task that has been
\r
76 .end vPortStartFirstTask
\r
80 /*******************************************************************/
\r
88 /* Make room for the context. First save the current status so it can be
\r
90 addiu sp, sp, -portCONTEXT_SIZE
\r
91 mfc0 k1, _CP0_STATUS
\r
93 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
94 maintain the values of these registers across the ISR. */
\r
97 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
99 /* Prepare to re-enabled interrupt above the kernel priority. */
\r
100 ins k1, zero, 10, 6
\r
101 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
104 /* s5 is used as the frame pointer. */
\r
107 /* Swap to the system stack. This is not conditional on the nesting
\r
108 count as this interrupt is always the lowest priority and therefore
\r
109 the nesting is always 0. */
\r
110 la sp, xISRStackTop
\r
113 /* Set the nesting count. */
\r
114 la k0, uxInterruptNesting
\r
118 /* s6 holds the EPC value, this is saved with the rest of the context
\r
119 after interrupts are enabled. */
\r
122 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
123 mtc0 k1, _CP0_STATUS
\r
125 /* Save the context into the space just created. s6 is saved again
\r
126 here as it now contains the EPC value. */
\r
146 sw s6, portEPC_STACK_LOCATION(s5)
\r
147 /* s5 and s6 has already been saved. */
\r
155 /* s7 is used as a scratch register as this should always be saved across
\r
156 nesting interrupts. */
\r
162 /* Save the stack pointer to the task. */
\r
163 la s7, pxCurrentTCB
\r
167 /* Set the interrupt mask to the max priority that can use the API. The
\r
168 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
169 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
170 raise the IPL value and never lower it. */
\r
173 mfc0 s7, _CP0_STATUS
\r
174 ins s7, zero, 10, 6
\r
175 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
177 /* This mtc0 re-enables interrupts, but only above
\r
178 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
179 mtc0 s6, _CP0_STATUS
\r
182 /* Clear the software interrupt in the core. */
\r
183 mfc0 s6, _CP0_CAUSE
\r
185 mtc0 s6, _CP0_CAUSE
\r
188 /* Clear the interrupt in the interrupt controller. */
\r
193 jal vTaskSwitchContext
\r
196 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
197 mtc0 s7, _CP0_STATUS
\r
200 /* Restore the stack pointer from the TCB. */
\r
201 la s0, pxCurrentTCB
\r
205 /* Restore the rest of the context. */
\r
216 /* s5 is loaded later. */
\r
238 /* Protect access to the k registers, and others. */
\r
242 /* Set nesting back to zero. As the lowest priority interrupt this
\r
243 interrupt cannot have nested. */
\r
244 la k0, uxInterruptNesting
\r
247 /* Switch back to use the real stack pointer. */
\r
250 /* Restore the real s5 value. */
\r
253 /* Pop the status and epc values. */
\r
254 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
255 lw k0, portEPC_STACK_LOCATION(sp)
\r
257 /* Remove stack frame. */
\r
258 addiu sp, sp, portCONTEXT_SIZE
\r
260 mtc0 k1, _CP0_STATUS
\r