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 vApplicationIRQHandler
33 EXTERN vTaskSwitchContext
34 EXTERN ulPortYieldRequired
35 EXTERN ulPortInterruptNesting
37 PUBLIC FreeRTOS_SWI_Handler
38 PUBLIC FreeRTOS_IRQ_Handler
39 PUBLIC vPortRestoreTaskContext
46 SECTION .text:CODE:ROOT(2)
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ; SVC handler is used to yield a task.
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 ; Save the context of the current task and select a new task to run.
60 LDR R0, =vTaskSwitchContext
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 ; vPortRestoreTaskContext is used to start the scheduler.
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 vPortRestoreTaskContext
68 ; Switch to system mode
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ; PL390 GIC interrupt handler
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ; Return to the interrupted instruction.
80 ; Push the return address and SPSR
85 ; Change to supervisor mode to allow reentry.
88 ; Push used registers.
91 ; Increment nesting count. r3 holds the address of ulPortInterruptNesting
92 ; for future use. r1 holds the original ulPortInterruptNesting value for
94 LDR r3, =ulPortInterruptNesting
99 ; Read value from the interrupt acknowledge register, which is stored in r0
100 ; for future parameter and interrupt clearing use.
101 LDR r2, =portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS
104 ; Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
105 ; future use. _RB_ Is this ever necessary if start of stack is 8-byte aligned?
110 ; Call the interrupt handler. r4 is pushed to maintain alignment.
112 LDR r1, =vApplicationIRQHandler
119 ; Write the value read from ICCIAR to ICCEOIR
120 LDR r4, =portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS
123 ; Restore the old nesting count
126 ; A context switch is never performed if the nesting count is not 0
128 BNE exit_without_switch
130 ; Did the interrupt request a context switch? r1 holds the address of
131 ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
133 LDR r1, =ulPortYieldRequired
136 BNE switch_before_exit
139 ; No context switch. Restore used registers, LR_irq and SPSR before
149 ; A context switch is to be performed. Clear the context switch pending
154 ; Restore used registers, LR-irq and SPSR before saving the context
163 ; Call the function that selects the new task to execute.
164 ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
165 ; instructions, or 8 byte aligned stack allocated data. LR does not need
166 ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.
167 LDR r0, =vTaskSwitchContext
170 ; Restore the context of, and branch to, the task selected to execute next.