]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/ARM_CAx_No_GIC/portASM.s
Add new port layer for Cortex-A devices without the means to mask interrupt priorities.
[freertos] / FreeRTOS / Source / portable / IAR / ARM_CAx_No_GIC / portASM.s
1 ;/*\r
2 ;    FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3 ;    All rights reserved\r
4 ;\r
5 ;\r
6 ;    ***************************************************************************\r
7 ;     *                                                                       *\r
8 ;     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
9 ;     *    Complete, revised, and edited pdf reference manuals are also       *\r
10 ;     *    available.                                                         *\r
11 ;     *                                                                       *\r
12 ;     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
13 ;     *    ensuring you get running as quickly as possible and with an        *\r
14 ;     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
15 ;     *    the FreeRTOS project to continue with its mission of providing     *\r
16 ;     *    professional grade, cross platform, de facto standard solutions    *\r
17 ;     *    for microcontrollers - completely free of charge!                  *\r
18 ;     *                                                                       *\r
19 ;     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
20 ;     *                                                                       *\r
21 ;     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
22 ;     *                                                                       *\r
23 ;    ***************************************************************************\r
24 ;\r
25 ;\r
26 ;    This file is part of the FreeRTOS distribution.\r
27 ;\r
28 ;    FreeRTOS is free software; you can redistribute it and/or modify it under\r
29 ;    the terms of the GNU General Public License (version 2) as published by the\r
30 ;    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
31 ;    >>>NOTE<<< The modification to the GPL is included to allow you to\r
32 ;    distribute a combined work that includes FreeRTOS without being obliged to\r
33 ;    provide the source code for proprietary components outside of the FreeRTOS\r
34 ;    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
35 ;    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
36 ;    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
37 ;    more details. You should have received a copy of the GNU General Public\r
38 ;    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
39 ;    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
40 ;    by writing to Richard Barry, contact details for whom are available on the\r
41 ;    FreeRTOS WEB site.\r
42 ;\r
43 ;    1 tab == 4 spaces!\r
44 ;\r
45 ;    http://www.FreeRTOS.org - Documentation, latest information, license and\r
46 ;    contact details.\r
47 ;\r
48 ;    http://www.SafeRTOS.com - A version that is certified for use in safety\r
49 ;    critical systems.\r
50 ;\r
51 ;    http://www.OpenRTOS.com - Commercial support, development, porting,\r
52 ;    licensing and training services.\r
53 ;*/\r
54 \r
55         INCLUDE FreeRTOSConfig.h\r
56         INCLUDE portmacro.h\r
57 \r
58         EXTERN  vTaskSwitchContext\r
59         EXTERN  ulPortYieldRequired\r
60         EXTERN  ulPortInterruptNesting\r
61 \r
62         PUBLIC  FreeRTOS_SWI_Handler\r
63         PUBLIC  FreeRTOS_IRQ_Handler\r
64         PUBLIC  vPortRestoreTaskContext\r
65 \r
66 SYS_MODE                        EQU             0x1f\r
67 SVC_MODE                        EQU             0x13\r
68 IRQ_MODE                        EQU             0x12\r
69 \r
70 ; AIC register definitions.\r
71 AIC_IVR                         EQU             0xFFFFF010UL\r
72 AIC_EOICR                       EQU             0xFFFFF038UL\r
73 \r
74         SECTION .text:CODE:ROOT(2)\r
75         ARM\r
76 \r
77         INCLUDE portASM.h\r
78 \r
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
80 ; SVC handler is used to start the scheduler and yield a task.\r
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
82 FreeRTOS_SWI_Handler\r
83 \r
84         PRESERVE8\r
85 \r
86         ; Save the context of the current task and select a new task to run.\r
87         portSAVE_CONTEXT\r
88         LDR R0, =vTaskSwitchContext\r
89         BLX     R0\r
90 \r
91 vPortRestoreTaskContext\r
92         portRESTORE_CONTEXT\r
93 \r
94 \r
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
96 ; AIC interrupt handler\r
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
98 FreeRTOS_IRQ_Handler\r
99 \r
100         ; Return to the interrupted instruction.\r
101         SUB             lr, lr, #4\r
102 \r
103         ; Push the return address and SPSR\r
104         PUSH    {lr}\r
105         MRS             lr, SPSR\r
106         PUSH    {lr}\r
107 \r
108         ; Change to supervisor mode to allow reentry.\r
109         CPS             #SVC_MODE\r
110 \r
111         ; Push used registers.\r
112         PUSH    {r0-r4, r12}\r
113 \r
114         ; Increment nesting count.  r3 holds the address of ulPortInterruptNesting\r
115         ; for future use.  r1 holds the original ulPortInterruptNesting value for\r
116         ; future use.\r
117         LDR             r3, =ulPortInterruptNesting\r
118         LDR             r1, [r3]\r
119         ADD             r4, r1, #1\r
120         STR             r4, [r3]\r
121 \r
122         ; Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\r
123         ; future use.\r
124         MOV             r2, sp\r
125         AND             r2, r2, #4\r
126         SUB             sp, sp, r2\r
127 \r
128         ; Call the interrupt handler\r
129         PUSH    {r0-r3, lr}\r
130         LDR             r1, =AIC_IVR\r
131         LDR             r0, [r1]\r
132         STR             r1, [r1] ; Write to IVR in case protect mode is being used.\r
133         BLX             r0\r
134         POP             {r0-r3, lr}\r
135         ADD             sp, sp, r2\r
136 \r
137         CPSID   i\r
138 \r
139         ; Write to the EOI register\r
140         LDR     r4, =AIC_EOICR\r
141         STR             r0, [r4]\r
142 \r
143         ; Restore the old nesting count\r
144         STR             r1, [r3]\r
145 \r
146         ; A context switch is never performed if the nesting count is not 0\r
147         CMP             r1, #0\r
148         BNE             exit_without_switch\r
149 \r
150         ; Did the interrupt request a context switch?  r1 holds the address of\r
151         ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future\r
152         ; use.\r
153         LDR             r1, =ulPortYieldRequired\r
154         LDR             r0, [r1]\r
155         CMP             r0, #0\r
156         BNE             switch_before_exit\r
157 \r
158 exit_without_switch\r
159         ; No context switch.  Restore used registers, LR_irq and SPSR before\r
160         ; returning.\r
161         POP             {r0-r4, r12}\r
162         CPS             #IRQ_MODE\r
163         POP             {LR}\r
164         MSR             SPSR_cxsf, LR\r
165         POP             {LR}\r
166         MOVS    PC, LR\r
167 \r
168 switch_before_exit\r
169         ; A context switch is to be performed.  Clear the context switch pending\r
170         ; flag.\r
171         MOV             r0, #0\r
172         STR             r0, [r1]\r
173 \r
174         ; Restore used registers, LR-irq and SPSR before saving the context\r
175         ; to the task stack.\r
176         POP             {r0-r4, r12}\r
177         CPS             #IRQ_MODE\r
178         POP             {LR}\r
179         MSR             SPSR_cxsf, LR\r
180         POP             {LR}\r
181         portSAVE_CONTEXT\r
182 \r
183         ; Call the function that selects the new task to execute.\r
184         ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\r
185         ; instructions, or 8 byte aligned stack allocated data.  LR does not need\r
186         ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.\r
187         LDR             r0, =vTaskSwitchContext\r
188         BLX             r0\r
189 \r
190         ; Restore the context of, and branch to, the task selected to execute next.\r
191         portRESTORE_CONTEXT\r
192 \r
193 \r
194         END\r
195 \r
196 \r
197 \r
198 \r