]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MicroBlazeV8/portasm.S
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / GCC / MicroBlazeV8 / portasm.S
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* FreeRTOS includes. */\r
71 #include "FreeRTOSConfig.h"\r
72 \r
73 /* Xilinx library includes. */\r
74 #include "microblaze_exceptions_g.h"\r
75 #include "xparameters.h"\r
76 \r
77 /* The context is oversized to allow functions called from the ISR to write\r
78 back into the caller stack. */\r
79 #if( XPAR_MICROBLAZE_USE_FPU != 0 )\r
80         #define portCONTEXT_SIZE 136\r
81         #define portMINUS_CONTEXT_SIZE -136\r
82 #else\r
83         #define portCONTEXT_SIZE 132\r
84         #define portMINUS_CONTEXT_SIZE -132\r
85 #endif\r
86 \r
87 /* Offsets from the stack pointer at which saved registers are placed. */\r
88 #define portR31_OFFSET  4\r
89 #define portR30_OFFSET  8\r
90 #define portR29_OFFSET  12\r
91 #define portR28_OFFSET  16\r
92 #define portR27_OFFSET  20\r
93 #define portR26_OFFSET  24\r
94 #define portR25_OFFSET  28\r
95 #define portR24_OFFSET  32\r
96 #define portR23_OFFSET  36\r
97 #define portR22_OFFSET  40\r
98 #define portR21_OFFSET  44\r
99 #define portR20_OFFSET  48\r
100 #define portR19_OFFSET  52\r
101 #define portR18_OFFSET  56\r
102 #define portR17_OFFSET  60\r
103 #define portR16_OFFSET  64\r
104 #define portR15_OFFSET  68\r
105 #define portR14_OFFSET  72\r
106 #define portR13_OFFSET  76\r
107 #define portR12_OFFSET  80\r
108 #define portR11_OFFSET  84\r
109 #define portR10_OFFSET  88\r
110 #define portR9_OFFSET   92\r
111 #define portR8_OFFSET   96\r
112 #define portR7_OFFSET   100\r
113 #define portR6_OFFSET   104\r
114 #define portR5_OFFSET   108\r
115 #define portR4_OFFSET   112\r
116 #define portR3_OFFSET   116\r
117 #define portR2_OFFSET   120\r
118 #define portCRITICAL_NESTING_OFFSET 124\r
119 #define portMSR_OFFSET 128\r
120 #define portFSR_OFFSET 132\r
121 \r
122         .extern pxCurrentTCB\r
123         .extern XIntc_DeviceInterruptHandler\r
124         .extern vTaskSwitchContext\r
125         .extern uxCriticalNesting\r
126         .extern pulISRStack\r
127         .extern ulTaskSwitchRequested\r
128         .extern vPortExceptionHandler\r
129         .extern pulStackPointerOnFunctionEntry\r
130 \r
131         .global _interrupt_handler\r
132         .global VPortYieldASM\r
133         .global vPortStartFirstTask\r
134         .global vPortExceptionHandlerEntry\r
135 \r
136 \r
137 .macro portSAVE_CONTEXT\r
138 \r
139         /* Make room for the context on the stack. */\r
140         addik r1, r1, portMINUS_CONTEXT_SIZE\r
141 \r
142         /* Stack general registers. */\r
143         swi r31, r1, portR31_OFFSET\r
144         swi r30, r1, portR30_OFFSET\r
145         swi r29, r1, portR29_OFFSET\r
146         swi r28, r1, portR28_OFFSET\r
147         swi r27, r1, portR27_OFFSET\r
148         swi r26, r1, portR26_OFFSET\r
149         swi r25, r1, portR25_OFFSET\r
150         swi r24, r1, portR24_OFFSET\r
151         swi r23, r1, portR23_OFFSET\r
152         swi r22, r1, portR22_OFFSET\r
153         swi r21, r1, portR21_OFFSET\r
154         swi r20, r1, portR20_OFFSET\r
155         swi r19, r1, portR19_OFFSET\r
156         swi r18, r1, portR18_OFFSET\r
157         swi r17, r1, portR17_OFFSET\r
158         swi r16, r1, portR16_OFFSET\r
159         swi r15, r1, portR15_OFFSET\r
160         /* R14 is saved later as it needs adjustment if a yield is performed. */\r
161         swi r13, r1, portR13_OFFSET\r
162         swi r12, r1, portR12_OFFSET\r
163         swi r11, r1, portR11_OFFSET\r
164         swi r10, r1, portR10_OFFSET\r
165         swi r9, r1, portR9_OFFSET\r
166         swi r8, r1, portR8_OFFSET\r
167         swi r7, r1, portR7_OFFSET\r
168         swi r6, r1, portR6_OFFSET\r
169         swi r5, r1, portR5_OFFSET\r
170         swi r4, r1, portR4_OFFSET\r
171         swi r3, r1, portR3_OFFSET\r
172         swi r2, r1, portR2_OFFSET\r
173 \r
174         /* Stack the critical section nesting value. */\r
175         lwi r18, r0, uxCriticalNesting\r
176         swi r18, r1, portCRITICAL_NESTING_OFFSET\r
177 \r
178         /* Stack MSR. */\r
179         mfs r18, rmsr\r
180         swi r18, r1, portMSR_OFFSET\r
181 \r
182         #if( XPAR_MICROBLAZE_USE_FPU != 0 )\r
183                 /* Stack FSR. */\r
184                 mfs r18, rfsr\r
185                 swi r18, r1, portFSR_OFFSET\r
186         #endif\r
187 \r
188         /* Save the top of stack value to the TCB. */\r
189         lwi r3, r0, pxCurrentTCB\r
190         sw      r1, r0, r3\r
191 \r
192         .endm\r
193 \r
194 .macro portRESTORE_CONTEXT\r
195 \r
196         /* Load the top of stack value from the TCB. */\r
197         lwi r18, r0, pxCurrentTCB\r
198         lw      r1, r0, r18\r
199 \r
200         /* Restore the general registers. */\r
201         lwi r31, r1, portR31_OFFSET\r
202         lwi r30, r1, portR30_OFFSET\r
203         lwi r29, r1, portR29_OFFSET\r
204         lwi r28, r1, portR28_OFFSET\r
205         lwi r27, r1, portR27_OFFSET\r
206         lwi r26, r1, portR26_OFFSET\r
207         lwi r25, r1, portR25_OFFSET\r
208         lwi r24, r1, portR24_OFFSET\r
209         lwi r23, r1, portR23_OFFSET\r
210         lwi r22, r1, portR22_OFFSET\r
211         lwi r21, r1, portR21_OFFSET\r
212         lwi r20, r1, portR20_OFFSET\r
213         lwi r19, r1, portR19_OFFSET\r
214         lwi r17, r1, portR17_OFFSET\r
215         lwi r16, r1, portR16_OFFSET\r
216         lwi r15, r1, portR15_OFFSET\r
217         lwi r14, r1, portR14_OFFSET\r
218         lwi r13, r1, portR13_OFFSET\r
219         lwi r12, r1, portR12_OFFSET\r
220         lwi r11, r1, portR11_OFFSET\r
221         lwi r10, r1, portR10_OFFSET\r
222         lwi r9, r1, portR9_OFFSET\r
223         lwi r8, r1, portR8_OFFSET\r
224         lwi r7, r1, portR7_OFFSET\r
225         lwi r6, r1, portR6_OFFSET\r
226         lwi r5, r1, portR5_OFFSET\r
227         lwi r4, r1, portR4_OFFSET\r
228         lwi r3, r1, portR3_OFFSET\r
229         lwi r2, r1, portR2_OFFSET\r
230 \r
231         /* Reload the rmsr from the stack. */\r
232         lwi r18, r1, portMSR_OFFSET\r
233         mts rmsr, r18\r
234 \r
235         #if( XPAR_MICROBLAZE_USE_FPU != 0 )\r
236                 /* Reload the FSR from the stack. */\r
237                 lwi r18, r1, portFSR_OFFSET\r
238                 mts rfsr, r18\r
239         #endif\r
240 \r
241         /* Load the critical nesting value. */\r
242         lwi r18, r1, portCRITICAL_NESTING_OFFSET\r
243         swi r18, r0, uxCriticalNesting\r
244 \r
245         /* Test the critical nesting value.  If it is non zero then the task last\r
246         exited the running state using a yield.  If it is zero, then the task\r
247         last exited the running state through an interrupt. */\r
248         xori r18, r18, 0\r
249         bnei r18, exit_from_yield\r
250 \r
251         /* r18 was being used as a temporary.  Now restore its true value from the\r
252         stack. */\r
253         lwi r18, r1, portR18_OFFSET\r
254 \r
255         /* Remove the stack frame. */\r
256         addik r1, r1, portCONTEXT_SIZE\r
257 \r
258         /* Return using rtid so interrupts are re-enabled as this function is\r
259         exited. */\r
260         rtid r14, 0\r
261         or r0, r0, r0\r
262 \r
263         .endm\r
264 \r
265 /* This function is used to exit portRESTORE_CONTEXT() if the task being\r
266 returned to last left the Running state by calling taskYIELD() (rather than\r
267 being preempted by an interrupt). */\r
268         .text\r
269         .align  4\r
270 exit_from_yield:\r
271 \r
272         /* r18 was being used as a temporary.  Now restore its true value from the\r
273         stack. */\r
274         lwi r18, r1, portR18_OFFSET\r
275 \r
276         /* Remove the stack frame. */\r
277         addik r1, r1, portCONTEXT_SIZE\r
278 \r
279         /* Return to the task. */\r
280         rtsd r14, 0\r
281         or r0, r0, r0\r
282 \r
283 \r
284         .text\r
285         .align  4\r
286 _interrupt_handler:\r
287 \r
288         portSAVE_CONTEXT\r
289 \r
290         /* Stack the return address. */\r
291         swi r14, r1, portR14_OFFSET\r
292 \r
293         /* Switch to the ISR stack. */\r
294         lwi r1, r0, pulISRStack\r
295 \r
296         /* The parameter to the interrupt handler. */\r
297         ori r5, r0, configINTERRUPT_CONTROLLER_TO_USE\r
298 \r
299         /* Execute any pending interrupts. */\r
300         bralid r15, XIntc_DeviceInterruptHandler\r
301         or r0, r0, r0\r
302 \r
303         /* See if a new task should be selected to execute. */\r
304         lwi r18, r0, ulTaskSwitchRequested\r
305         or r18, r18, r0\r
306 \r
307         /* If ulTaskSwitchRequested is already zero, then jump straight to\r
308         restoring the task that is already in the Running state. */\r
309         beqi r18, task_switch_not_requested\r
310 \r
311         /* Set ulTaskSwitchRequested back to zero as a task switch is about to be\r
312         performed. */\r
313         swi r0, r0, ulTaskSwitchRequested\r
314 \r
315         /* ulTaskSwitchRequested was not 0 when tested.  Select the next task to\r
316         execute. */\r
317         bralid r15, vTaskSwitchContext\r
318         or r0, r0, r0\r
319 \r
320 task_switch_not_requested:\r
321 \r
322         /* Restore the context of the next task scheduled to execute. */\r
323         portRESTORE_CONTEXT\r
324 \r
325 \r
326         .text\r
327         .align  4\r
328 VPortYieldASM:\r
329 \r
330         portSAVE_CONTEXT\r
331 \r
332         /* Modify the return address so a return is done to the instruction after\r
333         the call to VPortYieldASM. */\r
334         addi r14, r14, 8\r
335         swi r14, r1, portR14_OFFSET\r
336 \r
337         /* Switch to use the ISR stack. */\r
338         lwi r1, r0, pulISRStack\r
339 \r
340         /* Select the next task to execute. */\r
341         bralid r15, vTaskSwitchContext\r
342         or r0, r0, r0\r
343 \r
344         /* Restore the context of the next task scheduled to execute. */\r
345         portRESTORE_CONTEXT\r
346 \r
347         .text\r
348         .align  4\r
349 vPortStartFirstTask:\r
350 \r
351         portRESTORE_CONTEXT\r
352 \r
353 \r
354 \r
355 #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 )\r
356 \r
357         .text\r
358         .align 4\r
359 vPortExceptionHandlerEntry:\r
360 \r
361         /* Take a copy of the stack pointer before vPortExecptionHandler is called,\r
362         storing its value prior to the function stack frame being created. */\r
363         swi r1, r0, pulStackPointerOnFunctionEntry\r
364         bralid r15, vPortExceptionHandler\r
365         or r0, r0, r0\r
366 \r
367 #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */\r
368 \r
369 \r
370 \r