2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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
28 .extern vTaskSwitchContext
\r
32 # Exported to start the first task.
\r
33 .globl restore_sp_from_pxCurrentTCB
\r
35 # Entry point for exceptions.
\r
36 .section .exceptions.entry, "xa"
\r
38 # Save the entire context of a task.
\r
40 addi ea, ea, -4 # Point to the next instruction.
\r
41 addi sp, sp, -116 # Create space on the stack.
\r
43 # Leave a gap for muldiv 0
\r
59 rdctl r5, estatus # Save the eStatus
\r
61 stw ea, 72(sp) # Save the PC
\r
62 stw r16, 76(sp) # Save the remaining registers
\r
73 save_sp_to_pxCurrentTCB:
\r
74 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
\r
75 ldw et, (et) # Load the value of the pxCurrentTCB pointer
\r
76 stw sp, (et) # Store the stack pointer into the top of the TCB
\r
78 .section .exceptions.irqtest, "xa"
\r
81 * Test to see if the exception was a software exception or caused
\r
82 * by an external interrupt, and vector accordingly.
\r
84 rdctl r4, ipending # Load the Pending Interrupts indication
\r
85 rdctl r5, estatus # Load the eStatus (enabled interrupts).
\r
86 andi r2, r5, 1 # Are interrupts enabled globally.
\r
87 beq r2, zero, soft_exceptions # Interrupts are not enabled.
\r
88 beq r4, zero, soft_exceptions # There are no interrupts triggered.
\r
90 .section .exceptions.irqhandler, "xa"
\r
92 call alt_irq_handler # Call the alt_irq_handler to deliver to the registered interrupt handler.
\r
94 .section .exceptions.irqreturn, "xa"
\r
95 restore_sp_from_pxCurrentTCB:
\r
96 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
\r
97 ldw et, (et) # Load the value of the pxCurrentTCB pointer
\r
98 ldw sp, (et) # Load the stack pointer with the top value of the TCB
\r
101 ldw ra, 0(sp) # Restore the registers.
\r
102 # Leave a gap for muldiv 0.
\r
118 ldw et, 68(sp) # Load the eStatus
\r
119 wrctl estatus, et # Write the eStatus
\r
120 ldw ea, 72(sp) # Load the Program Counter
\r
131 addi sp, sp, 116 # Release stack space
\r
133 eret # Return to address ea, loading eStatus into Status.
\r
135 .section .exceptions.soft, "xa"
\r
137 ldw et, 0(ea) # Load the instruction where the interrupt occured.
\r
138 movhi at, %hi(0x003B683A) # Load the registers with the trap instruction code
\r
139 ori at, at, %lo(0x003B683A)
\r
140 cmpne et, et, at # Compare the trap instruction code to the last excuted instruction
\r
141 beq et, r0, call_scheduler # its a trap so switchcontext
\r
142 break # This is an un-implemented instruction or muldiv problem.
\r
143 br restore_context # its something else
\r
146 addi ea, ea, 4 # A trap was called, increment the program counter so it is not called again.
\r
147 stw ea, 72(sp) # Save the new program counter to the context.
\r
148 call vTaskSwitchContext # Pick the next context.
\r
149 br restore_sp_from_pxCurrentTCB # Switch in the task context and restore.
\r