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
29 .extern vTaskSwitchContext
\r
33 # Exported to start the first task.
\r
34 .globl restore_sp_from_pxCurrentTCB
\r
36 # Entry point for exceptions.
\r
37 .section .exceptions.entry, "xa"
\r
39 # Save the entire context of a task.
\r
41 addi ea, ea, -4 # Point to the next instruction.
\r
42 addi sp, sp, -116 # Create space on the stack.
\r
44 # Leave a gap for muldiv 0
\r
60 rdctl r5, estatus # Save the eStatus
\r
62 stw ea, 72(sp) # Save the PC
\r
63 stw r16, 76(sp) # Save the remaining registers
\r
74 save_sp_to_pxCurrentTCB:
\r
75 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
\r
76 ldw et, (et) # Load the value of the pxCurrentTCB pointer
\r
77 stw sp, (et) # Store the stack pointer into the top of the TCB
\r
79 .section .exceptions.irqtest, "xa"
\r
82 * Test to see if the exception was a software exception or caused
\r
83 * by an external interrupt, and vector accordingly.
\r
85 rdctl r4, ipending # Load the Pending Interrupts indication
\r
86 rdctl r5, estatus # Load the eStatus (enabled interrupts).
\r
87 andi r2, r5, 1 # Are interrupts enabled globally.
\r
88 beq r2, zero, soft_exceptions # Interrupts are not enabled.
\r
89 beq r4, zero, soft_exceptions # There are no interrupts triggered.
\r
91 .section .exceptions.irqhandler, "xa"
\r
93 call alt_irq_handler # Call the alt_irq_handler to deliver to the registered interrupt handler.
\r
95 .section .exceptions.irqreturn, "xa"
\r
96 restore_sp_from_pxCurrentTCB:
\r
97 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
\r
98 ldw et, (et) # Load the value of the pxCurrentTCB pointer
\r
99 ldw sp, (et) # Load the stack pointer with the top value of the TCB
\r
102 ldw ra, 0(sp) # Restore the registers.
\r
103 # Leave a gap for muldiv 0.
\r
119 ldw et, 68(sp) # Load the eStatus
\r
120 wrctl estatus, et # Write the eStatus
\r
121 ldw ea, 72(sp) # Load the Program Counter
\r
132 addi sp, sp, 116 # Release stack space
\r
134 eret # Return to address ea, loading eStatus into Status.
\r
136 .section .exceptions.soft, "xa"
\r
138 ldw et, 0(ea) # Load the instruction where the interrupt occured.
\r
139 movhi at, %hi(0x003B683A) # Load the registers with the trap instruction code
\r
140 ori at, at, %lo(0x003B683A)
\r
141 cmpne et, et, at # Compare the trap instruction code to the last excuted instruction
\r
142 beq et, r0, call_scheduler # its a trap so switchcontext
\r
143 break # This is an un-implemented instruction or muldiv problem.
\r
144 br restore_context # its something else
\r
147 addi ea, ea, 4 # A trap was called, increment the program counter so it is not called again.
\r
148 stw ea, 72(sp) # Save the new program counter to the context.
\r
149 call vTaskSwitchContext # Pick the next context.
\r
150 br restore_sp_from_pxCurrentTCB # Switch in the task context and restore.
\r