]> begriffs open source - freertos/blob - portable/RVDS/ARM_CA9/portASM.s
RP2040: Fix compiler warning and comment (#509)
[freertos] / portable / RVDS / ARM_CA9 / portASM.s
1 ;/*
2 ; * FreeRTOS SMP Kernel V202110.00
3 ; * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4 ; *
5 ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 ; * this software and associated documentation files (the "Software"), to deal in
7 ; * the Software without restriction, including without limitation the rights to
8 ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 ; * the Software, and to permit persons to whom the Software is furnished to do so,
10 ; * subject to the following conditions:
11 ; *
12 ; * The above copyright notice and this permission notice shall be included in all
13 ; * copies or substantial portions of the Software.
14 ; *
15 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ; *
22 ; * https://www.FreeRTOS.org
23 ; * https://github.com/FreeRTOS
24 ; *
25 ; * 1 tab == 4 spaces!
26 ; */
27
28         INCLUDE portmacro.inc
29
30         IMPORT  vApplicationIRQHandler
31         IMPORT  vTaskSwitchContext
32         IMPORT  ulPortYieldRequired
33         IMPORT  ulPortInterruptNesting
34         IMPORT  vTaskSwitchContext
35         IMPORT  ulICCIAR
36         IMPORT  ulICCEOIR
37
38         EXPORT  FreeRTOS_SWI_Handler
39         EXPORT  FreeRTOS_IRQ_Handler
40         EXPORT  vPortRestoreTaskContext
41
42         ARM
43         AREA    PORT_ASM, CODE, READONLY
44
45
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ; SVC handler is used to yield a task.
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 FreeRTOS_SWI_Handler
50
51         PRESERVE8
52
53         ; Save the context of the current task and select a new task to run.
54         portSAVE_CONTEXT
55         LDR R0, =vTaskSwitchContext
56         BLX     R0
57         portRESTORE_CONTEXT
58
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 ; vPortRestoreTaskContext is used to start the scheduler.
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 vPortRestoreTaskContext
63         ; Switch to system mode
64         CPS             #SYS_MODE
65         portRESTORE_CONTEXT
66
67 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68 ; PL390 GIC interrupt handler
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 FreeRTOS_IRQ_Handler
71
72         ; Return to the interrupted instruction.
73         SUB             lr, lr, #4
74
75         ; Push the return address and SPSR
76         PUSH    {lr}
77         MRS             lr, SPSR
78         PUSH    {lr}
79
80         ; Change to supervisor mode to allow reentry.
81         CPS             #SVC_MODE
82
83         ; Push used registers.
84         PUSH    {r0-r4, r12}
85
86         ; Increment nesting count.  r3 holds the address of ulPortInterruptNesting
87         ; for future use.  r1 holds the original ulPortInterruptNesting value for
88         ; future use.
89         LDR             r3, =ulPortInterruptNesting
90         LDR             r1, [r3]
91         ADD             r4, r1, #1
92         STR             r4, [r3]
93
94         ; Read value from the interrupt acknowledge register, which is stored in r0
95         ; for future parameter and interrupt clearing use.
96         LDR     r2, =ulICCIAR
97         LDR             r0, [r2]
98
99         ; Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for
100         ; future use.  _RB_ Does this ever actually need to be done provided the
101         ; start of the stack is 8-byte aligned?
102         MOV             r2, sp
103         AND             r2, r2, #4
104         SUB             sp, sp, r2
105
106         ; Call the interrupt handler.  r4 is pushed to maintain alignment.
107         PUSH    {r0-r4, lr}
108         LDR             r1, =vApplicationIRQHandler
109         BLX             r1
110         POP             {r0-r4, lr}
111         ADD             sp, sp, r2
112
113         CPSID   i
114
115         ; Write the value read from ICCIAR to ICCEOIR
116         LDR     r4, =ulICCEOIR
117         STR             r0, [r4]
118
119         ; Restore the old nesting count
120         STR             r1, [r3]
121
122         ; A context switch is never performed if the nesting count is not 0
123         CMP             r1, #0
124         BNE             exit_without_switch
125
126         ; Did the interrupt request a context switch?  r1 holds the address of
127         ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
128         ; use.
129         LDR             r1, =ulPortYieldRequired
130         LDR             r0, [r1]
131         CMP             r0, #0
132         BNE             switch_before_exit
133
134 exit_without_switch
135         ; No context switch.  Restore used registers, LR_irq and SPSR before
136         ; returning.
137         POP             {r0-r4, r12}
138         CPS             #IRQ_MODE
139         POP             {LR}
140         MSR             SPSR_cxsf, LR
141         POP             {LR}
142         MOVS    PC, LR
143
144 switch_before_exit
145         ; A context swtich is to be performed.  Clear the context switch pending
146         ; flag.
147         MOV             r0, #0
148         STR             r0, [r1]
149
150         ; Restore used registers, LR-irq and SPSR before saving the context
151         ; to the task stack.
152         POP             {r0-r4, r12}
153         CPS             #IRQ_MODE
154         POP             {LR}
155         MSR             SPSR_cxsf, LR
156         POP             {LR}
157         portSAVE_CONTEXT
158
159         ; Call the function that selects the new task to execute.
160         ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
161         ; instructions, or 8 byte aligned stack allocated data.  LR does not need
162         ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.
163         LDR             r0, =vTaskSwitchContext
164         BLX             r0
165
166         ; Restore the context of, and branch to, the task selected to execute next.
167         portRESTORE_CONTEXT
168
169
170         END
171
172
173
174