2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
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 #include "FreeRTOSConfig.h"
32 .extern vTaskSwitchContext
33 .extern xTaskIncrementTick
34 .extern vPortISRHandler
36 .global vPortStartFirstTask
39 .global vPortISRWrapper
40 .global vPortSaveFPURegisters
41 .global vPortRestoreFPURegisters
44 .set NextLRField, BChainField + 4
45 .set MSRField, NextLRField + 4
46 .set PCField, MSRField + 4
47 .set LRField, PCField + 4
48 .set CTRField, LRField + 4
49 .set XERField, CTRField + 4
50 .set CRField, XERField + 4
51 .set USPRG0Field, CRField + 4
52 .set r0Field, USPRG0Field + 4
53 .set r2Field, r0Field + 4
54 .set r3r31Field, r2Field + 4
55 .set IFrameSize, r3r31Field + ( ( 31 - 3 ) + 1 ) * 4
58 .macro portSAVE_STACK_POINTER_AND_LR
60 /* Get the address of the TCB. */
62 addis R2, R0, pxCurrentTCB@ha
63 lwz R2, pxCurrentTCB@l( R2 )
65 /* Store the stack pointer into the TCB */
68 /* Save the link register */
77 .macro portRESTORE_STACK_POINTER_AND_LR
79 /* Restore the link register */
86 /* Get the address of the TCB. */
88 addis SP, R0, pxCurrentTCB@ha
89 lwz SP, pxCurrentTCB@l( R1 )
91 /* Get the task stack pointer from the TCB. */
99 /* Get the address of the TCB. */
101 addis SP, R0, pxCurrentTCB@ha
102 lwz SP, pxCurrentTCB@l( SP )
104 /* Get the task stack pointer from the TCB. */
107 /* Restore MSR register to SRR1. */
111 /* Restore current PC location to SRR0. */
115 /* Save USPRG0 register */
116 lwz R0, USPRG0Field(R1)
119 /* Restore Condition register */
123 /* Restore Fixed Point Exception register */
127 /* Restore Counter register */
131 /* Restore Link register */
135 /* Restore remaining GPR registers. */
136 lmw R3,r3r31Field(R1)
138 /* Restore r0 and r2. */
142 /* Remove frame from stack */
143 addi R1,R1,IFrameSize
145 /* Return into the first task */
152 portSAVE_STACK_POINTER_AND_LR
153 bl vTaskSwitchContext
154 portRESTORE_STACK_POINTER_AND_LR
159 portSAVE_STACK_POINTER_AND_LR
160 bl xTaskIncrementTick
162 #if configUSE_PREEMPTION == 1
163 bl vTaskSwitchContext
166 /* Clear the interrupt */
170 portRESTORE_STACK_POINTER_AND_LR
175 portSAVE_STACK_POINTER_AND_LR
177 portRESTORE_STACK_POINTER_AND_LR
180 #if configUSE_FPU == 1
182 vPortSaveFPURegisters:
184 /* Enable APU and mark FPU as present. */
194 /* Buffer address is in r3. Save each flop register into an offset from
195 this buffer address. */
229 /* Also save the FPSCR. */
235 /* Buffer address is in r3. Save each flop register into an offset from
236 this buffer address. */
270 /* Also save the FPSCR. */
278 #endif /* configUSE_FPU. */
281 #if configUSE_FPU == 1
283 vPortRestoreFPURegisters:
285 /* Enable APU and mark FPU as present. */
295 /* Buffer address is in r3. Restore each flop register from an offset
337 /* Buffer address is in r3. Restore each flop register from an offset
381 #endif /* configUSE_FPU. */