2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 #include <sys/asm.h>
\r
72 #include "FreeRTOSConfig.h"
\r
73 #include "ISR_Support.h"
\r
75 .extern pxCurrentTCB
\r
76 .extern vTaskSwitchContext
\r
77 .extern vPortIncrementTick
\r
78 .extern xISRStackTop
\r
79 .extern ulTaskHasFPUContext
\r
81 .global vPortStartFirstTask
\r
82 .global vPortYieldISR
\r
83 .global vPortTickInterruptHandler
\r
84 .global vPortInitialiseFPSCR
\r
87 /******************************************************************/
\r
94 /***************************************************************
\r
95 * The following is needed to locate the
\r
96 * vPortTickInterruptHandler function into the correct vector
\r
97 ***************************************************************/
\r
98 #ifdef configTICK_INTERRUPT_VECTOR
\r
99 #if (configTICK_INTERRUPT_VECTOR == _CORE_TIMER_VECTOR)
\r
100 .equ __vector_dispatch_0, vPortTickInterruptHandler
\r
101 .global __vector_dispatch_0
\r
102 .section .vector_0, code, keep
\r
103 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_1_VECTOR)
\r
104 .equ __vector_dispatch_4, vPortTickInterruptHandler
\r
105 .global __vector_dispatch_4
\r
106 .section .vector_4, code, keep
\r
107 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_2_VECTOR)
\r
108 .equ __vector_dispatch_9, vPortTickInterruptHandler
\r
109 .global __vector_dispatch_9
\r
110 .section .vector_9, code, keep
\r
111 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_3_VECTOR)
\r
112 .equ __vector_dispatch_14, vPortTickInterruptHandler
\r
113 .global __vector_dispatch_14
\r
114 .section .vector_14, code, keep
\r
115 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_4_VECTOR)
\r
116 .equ __vector_dispatch_19, vPortTickInterruptHandler
\r
117 .global __vector_dispatch_19
\r
118 .section .vector_19, code, keep
\r
119 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_5_VECTOR)
\r
120 .equ __vector_dispatch_24, vPortTickInterruptHandler
\r
121 .global __vector_dispatch_24
\r
122 .section .vector_24, code, keep
\r
123 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_6_VECTOR)
\r
124 .equ __vector_dispatch_28, vPortTickInterruptHandler
\r
125 .global __vector_dispatch_28
\r
126 .section .vector_28, code, keep
\r
127 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_7_VECTOR)
\r
128 .equ __vector_dispatch_32, vPortTickInterruptHandler
\r
129 .global __vector_dispatch_32
\r
130 .section .vector_32, code, keep
\r
131 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_8_VECTOR)
\r
132 .equ __vector_dispatch_36, vPortTickInterruptHandler
\r
133 .global __vector_dispatch_36
\r
134 .section .vector_36, code, keep
\r
135 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_9_VECTOR)
\r
136 .equ __vector_dispatch_40, vPortTickInterruptHandler
\r
137 .global __vector_dispatch_40
\r
138 .section .vector_40, code, keep
\r
141 .equ __vector_dispatch_4, vPortTickInterruptHandler
\r
142 .global __vector_dispatch_4
\r
143 .section .vector_4, code, keep
\r
146 .ent vPortTickInterruptHandler
\r
148 vPortTickInterruptHandler:
\r
152 jal vPortIncrementTick
\r
155 portRESTORE_CONTEXT
\r
157 .end vPortTickInterruptHandler
\r
159 /******************************************************************/
\r
163 .section .text, code
\r
164 .ent vPortStartFirstTask
\r
166 vPortStartFirstTask:
\r
168 /* Simply restore the context of the highest priority task that has been
\r
170 portRESTORE_CONTEXT
\r
172 .end vPortStartFirstTask
\r
176 /*******************************************************************/
\r
182 /***************************************************************
\r
183 * The following is needed to locate the vPortYieldISR function
\r
184 * into the correct vector
\r
185 ***************************************************************/
\r
186 .equ __vector_dispatch_1, vPortYieldISR
\r
187 .global __vector_dispatch_1
\r
188 .section .vector_1, code
\r
193 #if ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 )
\r
194 /* Code sequence for FPU support, the context save requires advance
\r
195 knowledge of the stack frame size and if the current task actually uses the
\r
198 /* Make room for the context. First save the current status so it can be
\r
199 manipulated, and the cause and EPC registers so their original values are
\r
201 la k0, ulTaskHasFPUContext
\r
204 addiu sp, sp, -portCONTEXT_SIZE /* always reserve space for the context. */
\r
205 addiu sp, sp, -portFPU_CONTEXT_SIZE /* reserve additional space for the FPU context. */
\r
207 mfc0 k1, _CP0_STATUS
\r
209 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
210 maintain the values of these registers across the ISR. */
\r
213 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
214 sw k0, portTASK_HAS_FPU_STACK_LOCATION(sp)
\r
216 /* Prepare to re-enabled interrupts above the kernel priority. */
\r
217 ins k1, zero, 10, 7 /* Clear IPL bits 0:6. */
\r
218 ins k1, zero, 18, 1 /* Clear IPL bit 7. It would be an error here if this bit were set anyway. */
\r
219 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
220 ins k1, zero, 1, 4 /* Clear EXL, ERL and UM. */
\r
222 /* s5 is used as the frame pointer. */
\r
225 /* Swap to the system stack. This is not conditional on the nesting
\r
226 count as this interrupt is always the lowest priority and therefore
\r
227 the nesting is always 0. */
\r
228 la sp, xISRStackTop
\r
231 /* Set the nesting count. */
\r
232 la k0, uxInterruptNesting
\r
236 /* s6 holds the EPC value, this is saved with the rest of the context
\r
237 after interrupts are enabled. */
\r
240 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
241 mtc0 k1, _CP0_STATUS
\r
243 /* Save the context into the space just created. s6 is saved again
\r
244 here as it now contains the EPC value. */
\r
264 sw s6, portEPC_STACK_LOCATION(s5)
\r
265 /* s5 and s6 has already been saved. */
\r
273 /* s7 is used as a scratch register as this should always be saved across
\r
274 nesting interrupts. */
\r
276 /* Save the AC0, AC1, AC2 and AC3. */
\r
300 /* Test if FPU context save is required. */
\r
301 lw s7, portTASK_HAS_FPU_STACK_LOCATION(s5)
\r
305 /* Save the FPU registers above the normal context. */
\r
306 portSAVE_FPU_REGS (portCONTEXT_SIZE + 8), s5
\r
308 /* Save the FPU status register */
\r
310 sw s7, ( portCONTEXT_SIZE + portFPCSR_STACK_LOCATION )(s5)
\r
313 /* Save the stack pointer to the task. */
\r
314 la s7, pxCurrentTCB
\r
318 /* Set the interrupt mask to the max priority that can use the API. The
\r
319 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
320 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
321 raise the IPL value and never lower it. */
\r
324 mfc0 s7, _CP0_STATUS
\r
325 ins s7, zero, 10, 7
\r
326 ins s7, zero, 18, 1
\r
327 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
329 /* This mtc0 re-enables interrupts, but only above
\r
330 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
331 mtc0 s6, _CP0_STATUS
\r
334 /* Clear the software interrupt in the core. */
\r
335 mfc0 s6, _CP0_CAUSE
\r
337 mtc0 s6, _CP0_CAUSE
\r
340 /* Clear the interrupt in the interrupt controller. */
\r
345 jal vTaskSwitchContext
\r
348 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
349 mtc0 s7, _CP0_STATUS
\r
352 /* Restore the stack pointer from the TCB. */
\r
353 la s0, pxCurrentTCB
\r
357 /* Test if the FPU context needs restoring. */
\r
358 lw s0, portTASK_HAS_FPU_STACK_LOCATION(s5)
\r
362 /* Restore the FPU status register. */
\r
363 lw s0, ( portCONTEXT_SIZE + portFPCSR_STACK_LOCATION )(s5)
\r
366 /* Restore the FPU registers. */
\r
367 portLOAD_FPU_REGS ( portCONTEXT_SIZE + 8 ), s5
\r
370 /* Restore the rest of the context. */
\r
401 /* s5 is loaded later. */
\r
423 /* Protect access to the k registers, and others. */
\r
427 /* Set nesting back to zero. As the lowest priority interrupt this
\r
428 interrupt cannot have nested. */
\r
429 la k0, uxInterruptNesting
\r
432 /* Switch back to use the real stack pointer. */
\r
435 /* Restore the real s5 value. */
\r
438 /* Pop the FPU context value from the stack */
\r
439 lw k0, portTASK_HAS_FPU_STACK_LOCATION(sp)
\r
440 la k1, ulTaskHasFPUContext
\r
445 /* task has FPU context so adjust the stack frame after popping the
\r
446 status and epc values. */
\r
447 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
448 lw k0, portEPC_STACK_LOCATION(sp)
\r
449 addiu sp, sp, portFPU_CONTEXT_SIZE
\r
454 /* Pop the status and epc values. */
\r
455 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
456 lw k0, portEPC_STACK_LOCATION(sp)
\r
459 /* Remove stack frame. */
\r
460 addiu sp, sp, portCONTEXT_SIZE
\r
463 /* Code sequence for no FPU support, the context save requires advance
\r
464 knowledge of the stack frame size when no FPU is being used */
\r
466 /* Make room for the context. First save the current status so it can be
\r
467 manipulated, and the cause and EPC registers so thier original values are
\r
469 addiu sp, sp, -portCONTEXT_SIZE
\r
470 mfc0 k1, _CP0_STATUS
\r
472 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
473 maintain the values of these registers across the ISR. */
\r
476 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
478 /* Prepare to re-enabled interrupts above the kernel priority. */
\r
479 ins k1, zero, 10, 7 /* Clear IPL bits 0:6. */
\r
480 ins k1, zero, 18, 1 /* Clear IPL bit 7. It would be an error here if this bit were set anyway. */
\r
481 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
482 ins k1, zero, 1, 4 /* Clear EXL, ERL and UM. */
\r
484 /* s5 is used as the frame pointer. */
\r
487 /* Swap to the system stack. This is not conditional on the nesting
\r
488 count as this interrupt is always the lowest priority and therefore
\r
489 the nesting is always 0. */
\r
490 la sp, xISRStackTop
\r
493 /* Set the nesting count. */
\r
494 la k0, uxInterruptNesting
\r
498 /* s6 holds the EPC value, this is saved with the rest of the context
\r
499 after interrupts are enabled. */
\r
502 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
503 mtc0 k1, _CP0_STATUS
\r
505 /* Save the context into the space just created. s6 is saved again
\r
506 here as it now contains the EPC value. */
\r
526 sw s6, portEPC_STACK_LOCATION(s5)
\r
527 /* s5 and s6 has already been saved. */
\r
535 /* s7 is used as a scratch register as this should always be saved across
\r
536 nesting interrupts. */
\r
538 /* Save the AC0, AC1, AC2 and AC3. */
\r
562 /* Save the stack pointer to the task. */
\r
563 la s7, pxCurrentTCB
\r
567 /* Set the interrupt mask to the max priority that can use the API. The
\r
568 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
569 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
570 raise the IPL value and never lower it. */
\r
573 mfc0 s7, _CP0_STATUS
\r
574 ins s7, zero, 10, 7
\r
575 ins s7, zero, 18, 1
\r
576 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
578 /* This mtc0 re-enables interrupts, but only above
\r
579 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
580 mtc0 s6, _CP0_STATUS
\r
583 /* Clear the software interrupt in the core. */
\r
584 mfc0 s6, _CP0_CAUSE
\r
586 mtc0 s6, _CP0_CAUSE
\r
589 /* Clear the interrupt in the interrupt controller. */
\r
594 jal vTaskSwitchContext
\r
597 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
598 mtc0 s7, _CP0_STATUS
\r
601 /* Restore the stack pointer from the TCB. */
\r
602 la s0, pxCurrentTCB
\r
606 /* Restore the rest of the context. */
\r
637 /* s5 is loaded later. */
\r
659 /* Protect access to the k registers, and others. */
\r
663 /* Set nesting back to zero. As the lowest priority interrupt this
\r
664 interrupt cannot have nested. */
\r
665 la k0, uxInterruptNesting
\r
668 /* Switch back to use the real stack pointer. */
\r
671 /* Restore the real s5 value. */
\r
674 /* Pop the status and epc values. */
\r
675 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
676 lw k0, portEPC_STACK_LOCATION(sp)
\r
678 /* Remove stack frame. */
\r
679 addiu sp, sp, portCONTEXT_SIZE
\r
681 #endif /* ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 ) */
\r
683 /* Restore the status and EPC registers and return */
\r
684 mtc0 k1, _CP0_STATUS
\r
692 /******************************************************************/
\r
694 #if ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 )
\r
696 .macro portFPUSetAndInc reg, dest
\r
698 cvt.d.w \dest, \dest
\r
699 addiu \reg, \reg, 1
\r
704 .section .text, code
\r
705 .ent vPortInitialiseFPSCR
\r
707 vPortInitialiseFPSCR:
\r
709 /* Initialize the floating point status register in CP1. The initial
\r
710 value is passed in a0. */
\r
713 /* Clear the FPU registers */
\r
714 addiu a0, zero, 0x0000
\r
715 portFPUSetAndInc a0, $f0
\r
716 portFPUSetAndInc a0, $f1
\r
717 portFPUSetAndInc a0, $f2
\r
718 portFPUSetAndInc a0, $f3
\r
719 portFPUSetAndInc a0, $f4
\r
720 portFPUSetAndInc a0, $f5
\r
721 portFPUSetAndInc a0, $f6
\r
722 portFPUSetAndInc a0, $f7
\r
723 portFPUSetAndInc a0, $f8
\r
724 portFPUSetAndInc a0, $f9
\r
725 portFPUSetAndInc a0, $f10
\r
726 portFPUSetAndInc a0, $f11
\r
727 portFPUSetAndInc a0, $f12
\r
728 portFPUSetAndInc a0, $f13
\r
729 portFPUSetAndInc a0, $f14
\r
730 portFPUSetAndInc a0, $f15
\r
731 portFPUSetAndInc a0, $f16
\r
732 portFPUSetAndInc a0, $f17
\r
733 portFPUSetAndInc a0, $f18
\r
734 portFPUSetAndInc a0, $f19
\r
735 portFPUSetAndInc a0, $f20
\r
736 portFPUSetAndInc a0, $f21
\r
737 portFPUSetAndInc a0, $f22
\r
738 portFPUSetAndInc a0, $f23
\r
739 portFPUSetAndInc a0, $f24
\r
740 portFPUSetAndInc a0, $f25
\r
741 portFPUSetAndInc a0, $f26
\r
742 portFPUSetAndInc a0, $f27
\r
743 portFPUSetAndInc a0, $f28
\r
744 portFPUSetAndInc a0, $f29
\r
745 portFPUSetAndInc a0, $f30
\r
746 portFPUSetAndInc a0, $f31
\r
751 .end vPortInitialiseFPSCR
\r
753 #endif /* ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 ) */
\r
755 #if ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 )
\r
757 /**********************************************************************/
\r
758 /* Test read back */
\r
759 /* a0 = address to store registers */
\r
763 .section .text, code
\r
764 .ent vPortFPUReadback
\r
765 .global vPortFPUReadback
\r
804 .end vPortFPUReadback
\r
806 #endif /* ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 ) */
\r