]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/ARM_CA9/portASM.s
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Source / portable / IAR / ARM_CA9 / portASM.s
1 ;/*\r
2 ;    FreeRTOS V8.1.2 - 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  vApplicationIRQHandler\r
59         EXTERN  vTaskSwitchContext\r
60         EXTERN  ulPortYieldRequired\r
61         EXTERN  ulPortInterruptNesting\r
62 \r
63         PUBLIC  FreeRTOS_SWI_Handler\r
64         PUBLIC  FreeRTOS_IRQ_Handler\r
65         PUBLIC  vPortRestoreTaskContext\r
66 \r
67 SYS_MODE                        EQU             0x1f\r
68 SVC_MODE                        EQU             0x13\r
69 IRQ_MODE                        EQU             0x12\r
70 \r
71 \r
72         SECTION .text:CODE:ROOT(2)\r
73         ARM\r
74 \r
75         INCLUDE portASM.h\r
76 \r
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
78 ; SVC handler is used to yield a task.\r
79 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
80 FreeRTOS_SWI_Handler\r
81 \r
82         PRESERVE8\r
83 \r
84         ; Save the context of the current task and select a new task to run.\r
85         portSAVE_CONTEXT\r
86         LDR R0, =vTaskSwitchContext\r
87         BLX     R0\r
88         portRESTORE_CONTEXT\r
89 \r
90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
91 ; vPortRestoreTaskContext is used to start the scheduler.\r
92 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
93 vPortRestoreTaskContext\r
94         ; Switch to system mode\r
95         CPS             #SYS_MODE\r
96         portRESTORE_CONTEXT\r
97 \r
98 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
99 ; PL390 GIC interrupt handler\r
100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
101 FreeRTOS_IRQ_Handler\r
102 \r
103         ; Return to the interrupted instruction.\r
104         SUB             lr, lr, #4\r
105 \r
106         ; Push the return address and SPSR\r
107         PUSH    {lr}\r
108         MRS             lr, SPSR\r
109         PUSH    {lr}\r
110 \r
111         ; Change to supervisor mode to allow reentry.\r
112         CPS             #SVC_MODE\r
113 \r
114         ; Push used registers.\r
115         PUSH    {r0-r4, r12}\r
116 \r
117         ; Increment nesting count.  r3 holds the address of ulPortInterruptNesting\r
118         ; for future use.  r1 holds the original ulPortInterruptNesting value for\r
119         ; future use.\r
120         LDR             r3, =ulPortInterruptNesting\r
121         LDR             r1, [r3]\r
122         ADD             r4, r1, #1\r
123         STR             r4, [r3]\r
124 \r
125         ; Read value from the interrupt acknowledge register, which is stored in r0\r
126         ; for future parameter and interrupt clearing use.\r
127         LDR     r2, =portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS\r
128         LDR             r0, [r2]\r
129 \r
130         ; Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\r
131         ; future use.\r
132         MOV             r2, sp\r
133         AND             r2, r2, #4\r
134         SUB             sp, sp, r2\r
135 \r
136         ; Call the interrupt handler\r
137         PUSH    {r0-r3, lr}\r
138         LDR             r1, =vApplicationIRQHandler\r
139         BLX             r1\r
140         POP             {r0-r3, lr}\r
141         ADD             sp, sp, r2\r
142 \r
143         CPSID   i\r
144 \r
145         ; Write the value read from ICCIAR to ICCEOIR\r
146         LDR     r4, =portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS\r
147         STR             r0, [r4]\r
148 \r
149         ; Restore the old nesting count\r
150         STR             r1, [r3]\r
151 \r
152         ; A context switch is never performed if the nesting count is not 0\r
153         CMP             r1, #0\r
154         BNE             exit_without_switch\r
155 \r
156         ; Did the interrupt request a context switch?  r1 holds the address of\r
157         ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future\r
158         ; use.\r
159         LDR             r1, =ulPortYieldRequired\r
160         LDR             r0, [r1]\r
161         CMP             r0, #0\r
162         BNE             switch_before_exit\r
163 \r
164 exit_without_switch\r
165         ; No context switch.  Restore used registers, LR_irq and SPSR before\r
166         ; returning.\r
167         POP             {r0-r4, r12}\r
168         CPS             #IRQ_MODE\r
169         POP             {LR}\r
170         MSR             SPSR_cxsf, LR\r
171         POP             {LR}\r
172         MOVS    PC, LR\r
173 \r
174 switch_before_exit\r
175         ; A context switch is to be performed.  Clear the context switch pending\r
176         ; flag.\r
177         MOV             r0, #0\r
178         STR             r0, [r1]\r
179 \r
180         ; Restore used registers, LR-irq and SPSR before saving the context\r
181         ; to the task stack.\r
182         POP             {r0-r4, r12}\r
183         CPS             #IRQ_MODE\r
184         POP             {LR}\r
185         MSR             SPSR_cxsf, LR\r
186         POP             {LR}\r
187         portSAVE_CONTEXT\r
188 \r
189         ; Call the function that selects the new task to execute.\r
190         ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\r
191         ; instructions, or 8 byte aligned stack allocated data.  LR does not need\r
192         ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.\r
193         LDR             r0, =vTaskSwitchContext\r
194         BLX             r0\r
195 \r
196         ; Restore the context of, and branch to, the task selected to execute next.\r
197         portRESTORE_CONTEXT\r
198 \r
199 \r
200         END\r
201 \r
202 \r
203 \r
204 \r