]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/FreeRTOS_Source/portable/GCC/MicroBlaze/portasm.s
Tidy up the MicoBlaze port layer - still a work in progress.
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / FreeRTOS_Source / portable / GCC / MicroBlaze / portasm.s
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4 \r
5         FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
6         Atollic AB - Atollic provides professional embedded systems development\r
7         tools for C/C++ development, code analysis and test automation.\r
8         See http://www.atollic.com\r
9 \r
10 \r
11     ***************************************************************************\r
12      *                                                                       *\r
13      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
14      *    Complete, revised, and edited pdf reference manuals are also       *\r
15      *    available.                                                         *\r
16      *                                                                       *\r
17      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
18      *    ensuring you get running as quickly as possible and with an        *\r
19      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
20      *    the FreeRTOS project to continue with its mission of providing     *\r
21      *    professional grade, cross platform, de facto standard solutions    *\r
22      *    for microcontrollers - completely free of charge!                  *\r
23      *                                                                       *\r
24      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
25      *                                                                       *\r
26      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
27      *                                                                       *\r
28     ***************************************************************************\r
29 \r
30 \r
31     This file is part of the FreeRTOS distribution.\r
32 \r
33     FreeRTOS is free software; you can redistribute it and/or modify it under\r
34     the terms of the GNU General Public License (version 2) as published by the\r
35     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
36     >>>NOTE<<< The modification to the GPL is included to allow you to\r
37     distribute a combined work that includes FreeRTOS without being obliged to\r
38     provide the source code for proprietary components outside of the FreeRTOS\r
39     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
40     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
41     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
42     more details. You should have received a copy of the GNU General Public\r
43     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
44     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
45     by writing to Richard Barry, contact details for whom are available on the\r
46     FreeRTOS WEB site.\r
47 \r
48     1 tab == 4 spaces!\r
49 \r
50     http://www.FreeRTOS.org - Documentation, latest information, license and\r
51     contact details.\r
52 \r
53     http://www.SafeRTOS.com - A version that is certified for use in safety\r
54     critical systems.\r
55 \r
56     http://www.OpenRTOS.com - Commercial support, development, porting,\r
57     licensing and training services.\r
58 */\r
59 \r
60         .extern pxCurrentTCB\r
61         .extern XIntc_DeviceInterruptHandler\r
62         .extern vTaskSwitchContext\r
63         .extern uxCriticalNesting\r
64         .extern pulISRStack\r
65 \r
66         .global _interrupt_handler\r
67         .global VPortYieldASM\r
68         .global vPortStartFirstTask\r
69 \r
70 \r
71 .macro portSAVE_CONTEXT\r
72 \r
73         /* Make room for the context on the stack. */\r
74         addik r1, r1, -132\r
75 \r
76         /* Save r31 so it can then be used as a temporary. */\r
77         swi r31, r1, 4\r
78 \r
79         /* Copy the msr into r31 - this is stacked later. */\r
80         mfs r31, rmsr\r
81 \r
82         /* Stack general registers. */\r
83         swi r30, r1, 12\r
84         swi r29, r1, 16\r
85         swi r28, r1, 20\r
86         swi r27, r1, 24\r
87         swi r26, r1, 28\r
88         swi r25, r1, 32\r
89         swi r24, r1, 36\r
90         swi r23, r1, 40\r
91         swi r22, r1, 44\r
92         swi r21, r1, 48\r
93         swi r20, r1, 52\r
94         swi r19, r1, 56\r
95         swi r18, r1, 60\r
96         swi r17, r1, 64\r
97         swi r16, r1, 68\r
98         swi r15, r1, 72\r
99         swi r13, r1, 80\r
100         swi r12, r1, 84\r
101         swi r11, r1, 88\r
102         swi r10, r1, 92\r
103         swi r9, r1, 96\r
104         swi r8, r1, 100\r
105         swi r7, r1, 104\r
106         swi r6, r1, 108\r
107         swi r5, r1, 112\r
108         swi r4, r1, 116\r
109         swi r3, r1, 120\r
110         swi r2, r1, 124\r
111 \r
112         /* Stack the critical section nesting value. */\r
113         lwi r3, r0, uxCriticalNesting\r
114         swi r3, r1, 128\r
115 \r
116         /* Save the top of stack value to the TCB. */\r
117         lwi r3, r0, pxCurrentTCB\r
118         sw      r1, r0, r3\r
119         \r
120         .endm\r
121 \r
122 .macro portRESTORE_CONTEXT\r
123 \r
124         /* Load the top of stack value from the TCB. */\r
125         lwi r3, r0, pxCurrentTCB\r
126         lw      r1, r0, r3      \r
127 \r
128         /* Restore the general registers. */\r
129         lwi r31, r1, 4          \r
130         lwi r30, r1, 12         \r
131         lwi r29, r1, 16 \r
132         lwi r28, r1, 20 \r
133         lwi r27, r1, 24 \r
134         lwi r26, r1, 28 \r
135         lwi r25, r1, 32 \r
136         lwi r24, r1, 36 \r
137         lwi r23, r1, 40 \r
138         lwi r22, r1, 44 \r
139         lwi r21, r1, 48 \r
140         lwi r20, r1, 52 \r
141         lwi r19, r1, 56 \r
142         lwi r18, r1, 60 \r
143         lwi r17, r1, 64 \r
144         lwi r16, r1, 68 \r
145         lwi r15, r1, 72 \r
146         lwi r14, r1, 76 \r
147         lwi r13, r1, 80 \r
148         lwi r12, r1, 84 \r
149         lwi r11, r1, 88 \r
150         lwi r10, r1, 92 \r
151         lwi r9, r1, 96  \r
152         lwi r8, r1, 100 \r
153         lwi r7, r1, 104\r
154         lwi r6, r1, 108\r
155         lwi r5, r1, 112\r
156         lwi r4, r1, 116\r
157         lwi r2, r1, 124\r
158 \r
159         /* Reload the rmsr from the stack. */\r
160         lwi r3, r1, 8\r
161         mts rmsr, r3\r
162 \r
163         /* Load the critical nesting value. */\r
164         lwi r3, r1, 128\r
165         swi r3, r0, uxCriticalNesting\r
166 \r
167         /* Test the critical nesting value.  If it is non zero then the task last\r
168         exited the running state using a yield.  If it is zero, then the task\r
169         last exited the running state through an interrupt. */\r
170         xori r3, r3, 0\r
171         bnei r3, exit_from_yield\r
172 \r
173         /* r3 was being used as a temporary.  Now restore its true value from the\r
174         stack. */\r
175         lwi r3, r1, 120\r
176 \r
177         /* Remove the stack frame. */\r
178         addik r1, r1, 132\r
179 \r
180         /* Return using rtid so interrupts are re-enabled as this function is\r
181         exited. */\r
182         rtid r14, 0\r
183         or r0, r0, r0\r
184 \r
185         .endm\r
186 \r
187         .text\r
188         .align  2\r
189 \r
190 /* This function is used to exit portRESTORE_CONTEXT() if the task being\r
191 returned to last left the Running state by calling taskYIELD() (rather than\r
192 being preempted by an interrupt. */\r
193 exit_from_yield:\r
194 \r
195         /* r3 was being used as a temporary.  Now restore its true value from the\r
196         stack. */\r
197         lwi r3, r1, 120\r
198 \r
199         /* Remove the stack frame. */\r
200         addik r1, r1, 132\r
201 \r
202         /* Return to the task. */\r
203         rtsd r14, 0\r
204         or r0, r0, r0\r
205 \r
206 \r
207 _interrupt_handler:\r
208 \r
209         portSAVE_CONTEXT\r
210 \r
211         /* Stack msr. */\r
212         swi r31, r1, 8\r
213 \r
214         /* Stack the return address. */\r
215         swi r14, r1, 76\r
216 \r
217         /* Switch to the ISR stack. */\r
218         lwi r1, r0, pulISRStack\r
219 \r
220         /* Execute any pending interrupts. */\r
221         bralid r15, XIntc_DeviceInterruptHandler\r
222         or r0, r0, r0\r
223 \r
224         /* Restore the context of the next task scheduled to execute. */\r
225         portRESTORE_CONTEXT\r
226 \r
227 \r
228 VPortYieldASM:\r
229 \r
230         portSAVE_CONTEXT\r
231 \r
232         /* Stack msr. */\r
233         swi r31, r1, 8\r
234 \r
235         /* Modify the return address so a return is done to the instruction after\r
236         the call to VPortYieldASM. */\r
237         addi r14, r14, 8\r
238         swi r14, r1, 76\r
239 \r
240         /* Switch to use the ISR stack. */\r
241         lwi r1, r0, pulISRStack\r
242 \r
243         /* Select the next task to execute. */\r
244         bralid r15, vTaskSwitchContext\r
245         or r0, r0, r0\r
246 \r
247         /* Restore the context of the next task scheduled to execute. */\r
248         portRESTORE_CONTEXT\r
249 \r
250 vPortStartFirstTask:\r
251 \r
252         portRESTORE_CONTEXT\r
253         \r
254         \r
255 \r
256 \r
257 \r
258 \r