2 * FreeRTOS Kernel V11.1.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 #include "PriorityDefinitions.h"
31 PUBLIC _prvStartFirstTask
32 PUBLIC ___interrupt_27
35 EXTERN _vTaskSwitchContext
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. */
46 /* Obtain the location of the stack associated with which ever task
47 pxCurrentTCB is currently pointing to. */
48 MOV.L #_pxCurrentTCB, R15
52 /* Restore the registers from the stack of the task pointed to by
56 /* Accumulator low 32 bits. */
60 /* Accumulator high 32 bits. */
64 /* Accumulator guard. */
68 /* Accumulator low 32 bits. */
72 /* Accumulator high 32 bits. */
76 /* Accumulator guard. */
80 /* Floating point status word. */
83 /* R1 to R15 - R0 is not included as it is the SP. */
86 /* This pops the remaining registers. */
91 /*-----------------------------------------------------------*/
93 /* The software interrupt - overwrite the default 'weak' definition. */
96 /* Re-enable interrupts. */
99 /* Move the data that was automatically pushed onto the interrupt stack when
100 the interrupt occurred from the interrupt stack to the user stack.
102 R15 is saved before it is clobbered. */
105 /* Read the user stack pointer. */
108 /* Move the address down to the data being moved. */
112 /* Copy the data across, R15, then PC, then PSW. */
113 MOV.L [ R0 ], [ R15 ]
114 MOV.L 4[ R0 ], 4[ R15 ]
115 MOV.L 8[ R0 ], 8[ R15 ]
117 /* Move the interrupt stack pointer to its new correct position. */
120 /* All the rest of the registers are saved directly to the user stack. */
123 /* Save the rest of the general registers (R15 has been saved already). */
126 /* Save the FPSW and accumulator. */
133 /* Low order word. */
140 /* Low order word. */
144 /* Save the stack pointer to the TCB. */
145 MOV.L #_pxCurrentTCB, R15
149 /* Ensure the interrupt mask is set to the syscall priority while the kernel
150 structures are being accessed. */
151 MVTIPL #configMAX_SYSCALL_INTERRUPT_PRIORITY
153 /* Select the next task to run. */
154 BSR.A _vTaskSwitchContext
156 /* Reset the interrupt mask as no more data structure access is required. */
157 MVTIPL #configKERNEL_INTERRUPT_PRIORITY
159 /* Load the stack pointer of the task that is now selected as the Running
160 state task from its TCB. */
161 MOV.L #_pxCurrentTCB,R15
165 /* Restore the context of the new task. The PSW (Program Status Word) and
166 PC will be popped by the RTE instruction. */
169 /* Accumulator low 32 bits. */
173 /* Accumulator high 32 bits. */
177 /* Accumulator guard. */
181 /* Accumulator low 32 bits. */
185 /* Accumulator high 32 bits. */
189 /* Accumulator guard. */
198 /*-----------------------------------------------------------*/