1/* 2 * FreeRTOS Kernel V10.6.2 3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * SPDX-License-Identifier: MIT 6 * 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: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 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. 23 * 24 * https://www.FreeRTOS.org 25 * https://github.com/FreeRTOS 26 * 27 */ 28 29#include "PriorityDefinitions.h" 30 31 PUBLIC _prvStartFirstTask 32 PUBLIC ___interrupt_27 33 34 EXTERN _pxCurrentTCB 35 EXTERN _vTaskSwitchContext 36 37 RSEG CODE:CODE(4) 38 39_prvStartFirstTask: 40 41 /* When starting the scheduler there is nothing that needs moving to the 42 interrupt stack because the function is not called from an interrupt. 43 Just ensure the current stack is the user stack. */ 44 SETPSW U 45 46 /* Obtain the location of the stack associated with which ever task 47 pxCurrentTCB is currently pointing to. */ 48 MOV.L #_pxCurrentTCB, R15 49 MOV.L [R15], R15 50 MOV.L [R15], R0 51 52 /* Restore the registers from the stack of the task pointed to by 53 pxCurrentTCB. */ 54 POP R15 55 56 /* Accumulator low 32 bits. */ 57 MVTACLO R15 58 POP R15 59 60 /* Accumulator high 32 bits. */ 61 MVTACHI R15 62 63 /* R1 to R15 - R0 is not included as it is the SP. */ 64 POPM R1-R15 65 66 /* This pops the remaining registers. */ 67 RTE 68 NOP 69 NOP 70 71/*-----------------------------------------------------------*/ 72 73/* The software interrupt - overwrite the default 'weak' definition. */ 74___interrupt_27: 75 76 /* Re-enable interrupts. */ 77 SETPSW I 78 79 /* Move the data that was automatically pushed onto the interrupt stack when 80 the interrupt occurred from the interrupt stack to the user stack. 81 82 R15 is saved before it is clobbered. */ 83 PUSH.L R15 84 85 /* Read the user stack pointer. */ 86 MVFC USP, R15 87 88 /* Move the address down to the data being moved. */ 89 SUB #12, R15 90 MVTC R15, USP 91 92 /* Copy the data across, R15, then PC, then PSW. */ 93 MOV.L [ R0 ], [ R15 ] 94 MOV.L 4[ R0 ], 4[ R15 ] 95 MOV.L 8[ R0 ], 8[ R15 ] 96 97 /* Move the interrupt stack pointer to its new correct position. */ 98 ADD #12, R0 99 100 /* All the rest of the registers are saved directly to the user stack. */ 101 SETPSW U 102 103 /* Save the rest of the general registers (R15 has been saved already). */ 104 PUSHM R1-R14 105 106 /* Save the accumulator. */ 107 MVFACHI R15 108 PUSH.L R15 109 110 /* Middle word. */ 111 MVFACMI R15 112 113 /* Shifted left as it is restored to the low order word. */ 114 SHLL #16, R15 115 PUSH.L R15 116 117 /* Save the stack pointer to the TCB. */ 118 MOV.L #_pxCurrentTCB, R15 119 MOV.L [ R15 ], R15 120 MOV.L R0, [ R15 ] 121 122 /* Ensure the interrupt mask is set to the syscall priority while the kernel 123 structures are being accessed. */ 124 MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY 125 126 /* Select the next task to run. */ 127 BSR.A _vTaskSwitchContext 128 129 /* Reset the interrupt mask as no more data structure access is required. */ 130 MVTIPL #configKERNEL_INTERRUPT_PRIORITY 131 132 /* Load the stack pointer of the task that is now selected as the Running 133 state task from its TCB. */ 134 MOV.L #_pxCurrentTCB,R15 135 MOV.L [ R15 ], R15 136 MOV.L [ R15 ], R0 137 138 /* Restore the context of the new task. The PSW (Program Status Word) and 139 PC will be popped by the RTE instruction. */ 140 POP R15 141 MVTACLO R15 142 POP R15 143 MVTACHI R15 144 POPM R1-R15 145 RTE 146 NOP 147 NOP 148 149/*-----------------------------------------------------------*/ 150 151 END 152