]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/ARM_CA9/portASM.s
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS / Source / portable / IAR / ARM_CA9 / portASM.s
1 ;/*\r
2 ; * FreeRTOS Kernel V10.0.0\r
3 ; * Copyright (C) 2017 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. If you wish to use our Amazon\r
14 ; * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15 ; *\r
16 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 ; *\r
23 ; * http://www.FreeRTOS.org\r
24 ; * http://aws.amazon.com/freertos\r
25 ; *\r
26 ; * 1 tab == 4 spaces!\r
27 ; */\r
28 \r
29         INCLUDE FreeRTOSConfig.h\r
30         INCLUDE portmacro.h\r
31 \r
32         EXTERN  vApplicationIRQHandler\r
33         EXTERN  vTaskSwitchContext\r
34         EXTERN  ulPortYieldRequired\r
35         EXTERN  ulPortInterruptNesting\r
36 \r
37         PUBLIC  FreeRTOS_SWI_Handler\r
38         PUBLIC  FreeRTOS_IRQ_Handler\r
39         PUBLIC  vPortRestoreTaskContext\r
40 \r
41 SYS_MODE                        EQU             0x1f\r
42 SVC_MODE                        EQU             0x13\r
43 IRQ_MODE                        EQU             0x12\r
44 \r
45 \r
46         SECTION .text:CODE:ROOT(2)\r
47         ARM\r
48 \r
49         INCLUDE portASM.h\r
50 \r
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
52 ; SVC handler is used to yield a task.\r
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
54 FreeRTOS_SWI_Handler\r
55 \r
56         PRESERVE8\r
57 \r
58         ; Save the context of the current task and select a new task to run.\r
59         portSAVE_CONTEXT\r
60         LDR R0, =vTaskSwitchContext\r
61         BLX     R0\r
62         portRESTORE_CONTEXT\r
63 \r
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
65 ; vPortRestoreTaskContext is used to start the scheduler.\r
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
67 vPortRestoreTaskContext\r
68         ; Switch to system mode\r
69         CPS             #SYS_MODE\r
70         portRESTORE_CONTEXT\r
71 \r
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
73 ; PL390 GIC interrupt handler\r
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\r
75 FreeRTOS_IRQ_Handler\r
76 \r
77         ; Return to the interrupted instruction.\r
78         SUB             lr, lr, #4\r
79 \r
80         ; Push the return address and SPSR\r
81         PUSH    {lr}\r
82         MRS             lr, SPSR\r
83         PUSH    {lr}\r
84 \r
85         ; Change to supervisor mode to allow reentry.\r
86         CPS             #SVC_MODE\r
87 \r
88         ; Push used registers.\r
89         PUSH    {r0-r4, r12}\r
90 \r
91         ; Increment nesting count.  r3 holds the address of ulPortInterruptNesting\r
92         ; for future use.  r1 holds the original ulPortInterruptNesting value for\r
93         ; future use.\r
94         LDR             r3, =ulPortInterruptNesting\r
95         LDR             r1, [r3]\r
96         ADD             r4, r1, #1\r
97         STR             r4, [r3]\r
98 \r
99         ; Read value from the interrupt acknowledge register, which is stored in r0\r
100         ; for future parameter and interrupt clearing use.\r
101         LDR     r2, =portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS\r
102         LDR             r0, [r2]\r
103 \r
104         ; Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\r
105         ; future use.  _RB_ Is this ever necessary if start of stack is 8-byte aligned?\r
106         MOV             r2, sp\r
107         AND             r2, r2, #4\r
108         SUB             sp, sp, r2\r
109 \r
110         ; Call the interrupt handler.  r4 is pushed to maintain alignment.\r
111         PUSH    {r0-r4, lr}\r
112         LDR             r1, =vApplicationIRQHandler\r
113         BLX             r1\r
114         POP             {r0-r4, lr}\r
115         ADD             sp, sp, r2\r
116 \r
117         CPSID   i\r
118 \r
119         ; Write the value read from ICCIAR to ICCEOIR\r
120         LDR     r4, =portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS\r
121         STR             r0, [r4]\r
122 \r
123         ; Restore the old nesting count\r
124         STR             r1, [r3]\r
125 \r
126         ; A context switch is never performed if the nesting count is not 0\r
127         CMP             r1, #0\r
128         BNE             exit_without_switch\r
129 \r
130         ; Did the interrupt request a context switch?  r1 holds the address of\r
131         ; ulPortYieldRequired and r0 the value of ulPortYieldRequired for future\r
132         ; use.\r
133         LDR             r1, =ulPortYieldRequired\r
134         LDR             r0, [r1]\r
135         CMP             r0, #0\r
136         BNE             switch_before_exit\r
137 \r
138 exit_without_switch\r
139         ; No context switch.  Restore used registers, LR_irq and SPSR before\r
140         ; returning.\r
141         POP             {r0-r4, r12}\r
142         CPS             #IRQ_MODE\r
143         POP             {LR}\r
144         MSR             SPSR_cxsf, LR\r
145         POP             {LR}\r
146         MOVS    PC, LR\r
147 \r
148 switch_before_exit\r
149         ; A context switch is to be performed.  Clear the context switch pending\r
150         ; flag.\r
151         MOV             r0, #0\r
152         STR             r0, [r1]\r
153 \r
154         ; Restore used registers, LR-irq and SPSR before saving the context\r
155         ; to the task stack.\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         portSAVE_CONTEXT\r
162 \r
163         ; Call the function that selects the new task to execute.\r
164         ; vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\r
165         ; instructions, or 8 byte aligned stack allocated data.  LR does not need\r
166         ; saving as a new LR will be loaded by portRESTORE_CONTEXT anyway.\r
167         LDR             r0, =vTaskSwitchContext\r
168         BLX             r0\r
169 \r
170         ; Restore the context of, and branch to, the task selected to execute next.\r
171         portRESTORE_CONTEXT\r
172 \r
173 \r
174         END\r
175 \r
176 \r
177 \r
178 \r