]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/IA32_flat/portASM.S
2267b85854098c2922c627b3310d69761ce24472
[freertos] / FreeRTOS / Source / portable / GCC / IA32_flat / portASM.S
1 /*\r
2  * FreeRTOS Kernel V10.1.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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 .file "portASM.S"\r
29 #include "FreeRTOSConfig.h"\r
30 #include "ISR_Support.h"\r
31 \r
32         .extern pxCurrentTCB\r
33         .extern vTaskSwitchContext\r
34         .extern vPortCentralInterruptHandler\r
35         .extern xTaskIncrementTick\r
36         .extern vPortAPICErrorHandler\r
37         .extern pucPortTaskFPUContextBuffer\r
38         .extern ulPortYieldPending\r
39 \r
40         .global vPortStartFirstTask\r
41         .global vPortCentralInterruptWrapper\r
42         .global vPortAPICErrorHandlerWrapper\r
43         .global vPortTimerHandler\r
44         .global vPortYieldCall\r
45         .global vPortAPICSpuriousHandler\r
46 \r
47         .text\r
48 \r
49 /*-----------------------------------------------------------*/\r
50 \r
51 .align 4\r
52 .func vPortYieldCall\r
53 vPortYieldCall:\r
54         /* Save general purpose registers. */\r
55         pusha\r
56 \r
57         .if configSUPPORT_FPU == 1\r
58 \r
59                 /* If the task has a buffer allocated to save the FPU context then save\r
60                 the FPU context now. */\r
61                 movl    pucPortTaskFPUContextBuffer, %eax\r
62                 test    %eax, %eax\r
63                 je              1f\r
64                 fnsave  ( %eax )\r
65                 fwait\r
66 \r
67                 1:\r
68 \r
69                 /* Save the address of the FPU context, if any. */\r
70                 push    pucPortTaskFPUContextBuffer\r
71 \r
72         .endif /* configSUPPORT_FPU */\r
73 \r
74         /* Find the TCB. */\r
75         movl    pxCurrentTCB, %eax\r
76 \r
77         /* Stack location is first item in the TCB. */\r
78         movl    %esp, (%eax)\r
79 \r
80         call vTaskSwitchContext\r
81 \r
82         /* Find the location of pxCurrentTCB again - a callee saved register could\r
83         be used in place of eax to prevent this second load, but that then relies\r
84         on the compiler and other asm code. */\r
85         movl    pxCurrentTCB, %eax\r
86         movl    (%eax), %esp\r
87 \r
88         .if configSUPPORT_FPU == 1\r
89 \r
90                 /* Restore address of task's FPU context buffer. */\r
91                 pop     pucPortTaskFPUContextBuffer\r
92 \r
93                 /* If the task has a buffer allocated in which its FPU context is saved,\r
94                 then restore it now. */\r
95                 movl    pucPortTaskFPUContextBuffer, %eax\r
96                 test    %eax, %eax\r
97                 je              1f\r
98                 frstor  ( %eax )\r
99                 1:\r
100         .endif\r
101 \r
102         popa\r
103         iret\r
104 \r
105 .endfunc\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 .align 4\r
109 .func vPortStartFirstTask\r
110 vPortStartFirstTask:\r
111 \r
112         /* Find the TCB. */\r
113         movl    pxCurrentTCB, %eax\r
114 \r
115         /* Stack location is first item in the TCB. */\r
116         movl    (%eax), %esp\r
117 \r
118         /* Restore FPU context flag. */\r
119         .if configSUPPORT_FPU == 1\r
120 \r
121                 pop     pucPortTaskFPUContextBuffer\r
122 \r
123         .endif /* configSUPPORT_FPU */\r
124 \r
125         /* Restore general purpose registers. */\r
126         popa\r
127         iret\r
128 .endfunc\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 .align 4\r
132 .func vPortAPICErrorHandlerWrapper\r
133 vPortAPICErrorHandlerWrapper:\r
134         pusha\r
135         call    vPortAPICErrorHandler\r
136         popa\r
137         /* EOI. */\r
138         movl    $0x00, (0xFEE000B0)\r
139         iret\r
140 .endfunc\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 .align 4\r
144 .func vPortTimerHandler\r
145 vPortTimerHandler:\r
146 \r
147         /* Save general purpose registers. */\r
148         pusha\r
149 \r
150         /* Interrupts are not nested, so save the rest of the task context. */\r
151         .if configSUPPORT_FPU == 1\r
152 \r
153                 /* If the task has a buffer allocated to save the FPU context then save the\r
154                 FPU context now. */\r
155                 movl    pucPortTaskFPUContextBuffer, %eax\r
156                 test    %eax, %eax\r
157                 je              1f\r
158                 fnsave  ( %eax ) /* Save FLOP context into ucTempFPUBuffer array. */\r
159                 fwait\r
160 \r
161                 1:\r
162                 /* Save the address of the FPU context, if any. */\r
163                 push    pucPortTaskFPUContextBuffer\r
164 \r
165         .endif /* configSUPPORT_FPU */\r
166 \r
167         /* Find the TCB. */\r
168         movl    pxCurrentTCB, %eax\r
169 \r
170         /* Stack location is first item in the TCB. */\r
171         movl    %esp, (%eax)\r
172 \r
173         /* Switch stacks. */\r
174         movl    ulTopOfSystemStack, %esp\r
175         movl    %esp, %ebp\r
176 \r
177         /* Increment nesting count. */\r
178         add     $1, ulInterruptNesting\r
179 \r
180         call    xTaskIncrementTick\r
181 \r
182         sti\r
183 \r
184         /* Is a switch to another task required? */\r
185         test    %eax, %eax\r
186         je              _skip_context_switch\r
187         cli\r
188         call    vTaskSwitchContext\r
189 \r
190 _skip_context_switch:\r
191         cli\r
192 \r
193         /* Decrement the variable used to determine if a switch to a system\r
194         stack is necessary. */\r
195         sub             $1, ulInterruptNesting\r
196 \r
197         /* Stack location is first item in the TCB. */\r
198         movl    pxCurrentTCB, %eax\r
199         movl    (%eax), %esp\r
200 \r
201         .if configSUPPORT_FPU == 1\r
202 \r
203                 /* Restore address of task's FPU context buffer. */\r
204                 pop     pucPortTaskFPUContextBuffer\r
205 \r
206                 /* If the task has a buffer allocated in which its FPU context is saved,\r
207                 then restore it now. */\r
208                 movl    pucPortTaskFPUContextBuffer, %eax\r
209                 test    %eax, %eax\r
210                 je              1f\r
211                 frstor  ( %eax )\r
212                 1:\r
213         .endif\r
214 \r
215         popa\r
216 \r
217         /* EOI. */\r
218         movl    $0x00, (0xFEE000B0)\r
219         iret\r
220 \r
221 .endfunc\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 .if configUSE_COMMON_INTERRUPT_ENTRY_POINT == 1\r
225 \r
226         .align 4\r
227         .func vPortCentralInterruptWrapper\r
228         vPortCentralInterruptWrapper:\r
229 \r
230                 portFREERTOS_INTERRUPT_ENTRY\r
231 \r
232                 movl $0xFEE00170, %eax                  /* Highest In Service Register (ISR) long word. */\r
233                 movl $8, %ecx                                   /* Loop counter. */\r
234 \r
235         next_isr_long_word:\r
236                 test %ecx, %ecx                                 /* Loop counter reached 0? */\r
237                 je wrapper_epilogue                             /* Looked at all ISR registers without finding a bit set. */\r
238                 sub $1, %ecx                                    /* Sub 1 from loop counter. */\r
239                 movl (%eax), %ebx                               /* Load next ISR long word. */\r
240                 sub $0x10, %eax                                 /* Point to next ISR long word in case no bits are set in the current long word. */\r
241                 test %ebx, %ebx                                 /* Are there any bits set? */\r
242                 je next_isr_long_word                   /* Look at next ISR long word if no bits were set. */\r
243                 sti\r
244                 bsr %ebx, %ebx                                  /* A bit was set, which one? */\r
245                 movl $32, %eax                                  /* Destination operand for following multiplication. */\r
246                 mul %ecx                                                /* Calculate base vector for current register, 32 vectors per register. */\r
247                 add %ebx, %eax                                  /* Add bit offset into register to get final vector number. */\r
248                 push %eax                                               /* Vector number is function parameter. */\r
249                 call vPortCentralInterruptHandler\r
250                 pop %eax                                                /* Remove parameter. */\r
251 \r
252         wrapper_epilogue:\r
253                 portFREERTOS_INTERRUPT_EXIT\r
254 \r
255         .endfunc\r
256 \r
257 .endif /* configUSE_COMMON_INTERRUPT_ENTRY_POINT */\r
258 /*-----------------------------------------------------------*/\r
259 \r
260 .align 4\r
261 .func vPortAPISpuriousHandler\r
262 vPortAPICSpuriousHandler:\r
263         iret\r
264 \r
265 .endfunc\r
266 \r
267 .end\r
268 \r
269 \r
270 \r
271 \r
272 \r
273 \r
274 \r