]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/ARM_CA9/portASM.S
Beginnings of GCC Cortex-A port - not yet completely converted from IAR version.
[freertos] / FreeRTOS / Source / portable / GCC / ARM_CA9 / portASM.S
1 /*\r
2     FreeRTOS V8.0.0:rc1 - 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 \r
56         .org 0\r
57         .text\r
58 \r
59         .set SYS_MODE,  0x1f\r
60         .set SVC_MODE,  0x13\r
61         .set IRQ_MODE,  0x12\r
62 \r
63         .extern _boot\r
64         .extern vTaskSwitchContext\r
65         .extern ulICCIAR\r
66         .extern ulICCEOIR\r
67 \r
68         .global _vector_table\r
69         .global FIQInterrupt\r
70         .global Undefined\r
71         .global PrefetchAbortHandler\r
72         .global DataAbortInterrupt\r
73         .global FreeRTOS_IRQ_Handler\r
74         .global FreeRTOS_SWI_Handler\r
75 \r
76         .section .vectors\r
77 \r
78 _vector_table:\r
79         B         _boot\r
80         B         Undefined\r
81         ldr   pc, _swi\r
82         B         PrefetchAbortHandler\r
83         B         DataAbortHandler\r
84         NOP       /* Placeholder for address exception vector*/\r
85         LDR   PC, _irq\r
86         B         FIQHandler\r
87 \r
88 _irq:   .word FreeRTOS_IRQ_Handler\r
89 _swi:   .word FreeRTOS_SWI_Handler\r
90 \r
91 /******************************************************************************\r
92  * SVC handler is used to start the scheduler and yield a task.\r
93  *****************************************************************************/\r
94 FreeRTOS_SWI_Handler:\r
95 \r
96         /* Save the context of the current task and select a new task to run. */\r
97 //      portSAVE_CONTEXT\r
98         LDR R0, =vTaskSwitchContext\r
99         BLX     R0\r
100 \r
101 vPortRestoreTaskContext:\r
102 //      portRESTORE_CONTEXT\r
103 \r
104 FreeRTOS_IRQ_Handler:\r
105         /* Return to the interrupted instruction. */\r
106         SUB             lr, lr, #4\r
107 \r
108         /* Push the return address and SPSR. */\r
109         PUSH    {lr}\r
110         MRS             lr, SPSR\r
111         PUSH    {lr}\r
112 \r
113         /* Change to supervisor mode to allow reentry. */\r
114         CPS             #SVC_MODE\r
115 \r
116         /* Push used registers. */\r
117         PUSH    {r0-r4, r12}\r
118 \r
119         /* Increment nesting count.  r3 holds the address of ulPortInterruptNesting\r
120         for future use.  r1 holds the original ulPortInterruptNesting value for\r
121         future use. */\r
122         LDR             r3, =ulPortInterruptNesting\r
123         LDR             r1, [r3]\r
124         ADD             r4, r1, #1\r
125         STR             r4, [r3]\r
126 \r
127         /* Read value from the interrupt acknowledge register, which is stored in r0\r
128         for future parameter and interrupt clearing use. */\r
129         LDR     r2, ulICCIARConst\r
130         LDR             r0, [r2]\r
131 \r
132         /* Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\r
133         future use. */\r
134         MOV             r2, sp\r
135         AND             r2, r2, #4\r
136         SUB             sp, sp, r2\r
137 \r
138         /* Call the interrupt handler. */\r
139         PUSH    {r0-r3, lr}\r
140         BL              vApplicationIRQHandler\r
141         POP             {r0-r3, lr}\r
142         ADD             sp, sp, r2\r
143 \r
144         CPSID   i\r
145 \r
146         /* Write the value read from ICCIAR to ICCEOIR. */\r
147         LDR     r4, ulICCEOIRConst\r
148         STR             r0, [r4]\r
149 \r
150         /* Restore the old nesting count. */\r
151         STR             r1, [r3]\r
152 \r
153         /* A context switch is never performed if the nesting count is not 0. */\r
154         CMP             r1, #0\r
155         BNE             exit_without_switch\r
156 \r
157         /* Did the interrupt request a context switch?  r1 holds the address of\r
158         ulPortYieldRequired and r0 the value of ulPortYieldRequired for future\r
159         use. */\r
160         LDR             r1, =ulPortYieldRequired\r
161         LDR             r0, [r1]\r
162         CMP             r0, #0\r
163         BNE             switch_before_exit\r
164 \r
165 exit_without_switch:\r
166         /* No context switch.  Restore used registers, LR_irq and SPSR before\r
167         returning. */\r
168         POP             {r0-r4, r12}\r
169         CPS             #IRQ_MODE\r
170         POP             {LR}\r
171         MSR             SPSR_cxsf, LR\r
172         POP             {LR}\r
173         MOVS    PC, LR\r
174 \r
175 switch_before_exit:\r
176         /* A context swtich is to be performed.  Clear the context switch pending\r
177         flag. */\r
178         MOV             r0, #0\r
179         STR             r0, [r1]\r
180 \r
181         /* Restore used registers, LR-irq and SPSR before saving the context\r
182         to the task stack. */\r
183         POP             {r0-r4, r12}\r
184         CPS             #IRQ_MODE\r
185         POP             {LR}\r
186         MSR             SPSR_cxsf, LR\r
187         POP             {LR}\r
188 //      portSAVE_CONTEXT\r
189 \r
190         /* Call the function that selects the new task to execute.\r
191         vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\r
192         instructions, or 8 byte aligned stack allocated data.  LR does not need\r
193         saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */\r
194         BL              vTaskSwitchContext\r
195 \r
196         /* Restore the context of, and branch to, the task selected to execute\r
197         next. */\r
198 //      portRESTORE_CONTEXT\r
199 \r
200 ulICCIARConst:  .word ulICCIAR\r
201 ulICCEOIRConst: .word ulICCEOIR\r
202 \r
203 \r
204 Undefined:\r
205         B               .\r
206 \r
207 PrefetchAbortHandler:\r
208         B               .\r
209 \r
210 FIQHandler:\r
211         B               .\r
212 \r
213 DataAbortHandler:\r
214         B               .\r
215 \r
216 .end\r
217 \r
218 \r
219 \r
220 \r
221 \r