2 * FreeRTOS Kernel V11.2.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 .extern vTaskSwitchContext
33 # Exported to start the first task.
34 .globl restore_sp_from_pxCurrentTCB
36 # Entry point for exceptions.
37 .section .exceptions.entry.user, "xa"
39 # Save the entire context of a task.
41 addi sp, sp, -116 # Create space on the stack.
43 # Leave a gap for muldiv 0
59 rdctl r5, estatus # Save the eStatus
61 addi r15, ea, -4 # Instruction that caused exception
62 stw r15, 72(sp) # Save as EA
63 stw r16, 76(sp) # Save the remaining registers
74 save_sp_to_pxCurrentTCB:
75 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
76 ldw et, (et) # Load the value of the pxCurrentTCB pointer
77 stw sp, (et) # Store the stack pointer into the top of the TCB
79 br irq_test_user # skip the section .exceptions.entry
81 .section .exceptions.irqtest, "xa"
84 .section .exceptions.exit.user, "xa"
85 restore_sp_from_pxCurrentTCB:
86 movia et, pxCurrentTCB # Load the address of the pxCurrentTCB pointer
87 ldw et, (et) # Load the value of the pxCurrentTCB pointer
88 ldw sp, (et) # Load the stack pointer with the top value of the TCB
91 ldw ra, 0(sp) # Restore the registers.
92 # Leave a gap for muldiv 0.
108 ldw et, 68(sp) # Load the eStatus
109 wrctl estatus, et # Write the eStatus
110 ldw ea, 72(sp) # Load the Program Counter
121 addi sp, sp, 116 # Release stack space
123 eret # Return to address ea, loading eStatus into Status.
125 .section .exceptions.soft, "xa"
127 movhi r3, 0x003b /* upper half of trap opcode */
128 ori r3, r3, 0x683a /* lower half of trap opcode */
129 beq r2, r3, call_scheduler
130 br exceptions_unknown_user # its something else
133 stw ea, 72(sp) # EA is PC+4 so will skip over instruction causing exception
134 movia r15, vTaskSwitchContext # Pick the next context - use long call version in place of "call"
136 br restore_sp_from_pxCurrentTCB # Switch in the task context and restore.
138 .section .exceptions.unknown.user
139 exceptions_unknown_user: