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