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