]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/MicroBlaze/portasm.s
fc36ca17f46eb4fefae7dd035bf98ee3084f88ad
[freertos] / FreeRTOS / Source / portable / GCC / MicroBlaze / portasm.s
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95         .extern pxCurrentTCB\r
96         .extern vTaskISRHandler\r
97         .extern vTaskSwitchContext\r
98         .extern uxCriticalNesting\r
99         .extern pulISRStack\r
100 \r
101         .global __FreeRTOS_interrupt_handler\r
102         .global VPortYieldASM\r
103         .global vStartFirstTask\r
104 \r
105 \r
106 .macro portSAVE_CONTEXT\r
107         /* Make room for the context on the stack. */\r
108         addik r1, r1, -132\r
109         /* Save r31 so it can then be used. */\r
110         swi r31, r1, 4\r
111         /* Copy the msr into r31 - this is stacked later. */\r
112         mfs r31, rmsr\r
113         /* Stack general registers. */\r
114         swi r30, r1, 12\r
115         swi r29, r1, 16\r
116         swi r28, r1, 20\r
117         swi r27, r1, 24\r
118         swi r26, r1, 28\r
119         swi r25, r1, 32\r
120         swi r24, r1, 36\r
121         swi r23, r1, 40\r
122         swi r22, r1, 44\r
123         swi r21, r1, 48\r
124         swi r20, r1, 52\r
125         swi r19, r1, 56\r
126         swi r18, r1, 60\r
127         swi r17, r1, 64\r
128         swi r16, r1, 68\r
129         swi r15, r1, 72\r
130         swi r13, r1, 80\r
131         swi r12, r1, 84\r
132         swi r11, r1, 88\r
133         swi r10, r1, 92\r
134         swi r9, r1, 96\r
135         swi r8, r1, 100\r
136         swi r7, r1, 104\r
137         swi r6, r1, 108\r
138         swi r5, r1, 112\r
139         swi r4, r1, 116\r
140         swi r3, r1, 120\r
141         swi r2, r1, 124\r
142         /* Stack the critical section nesting value. */\r
143         lwi r3, r0, uxCriticalNesting\r
144         swi r3, r1, 128\r
145         /* Save the top of stack value to the TCB. */\r
146         lwi r3, r0, pxCurrentTCB\r
147         sw      r1, r0, r3\r
148         \r
149         .endm\r
150 \r
151 .macro portRESTORE_CONTEXT\r
152         /* Load the top of stack value from the TCB. */\r
153         lwi r3, r0, pxCurrentTCB\r
154         lw      r1, r0, r3      \r
155         /* Restore the general registers. */\r
156         lwi r31, r1, 4          \r
157         lwi r30, r1, 12         \r
158         lwi r29, r1, 16 \r
159         lwi r28, r1, 20 \r
160         lwi r27, r1, 24 \r
161         lwi r26, r1, 28 \r
162         lwi r25, r1, 32 \r
163         lwi r24, r1, 36 \r
164         lwi r23, r1, 40 \r
165         lwi r22, r1, 44 \r
166         lwi r21, r1, 48 \r
167         lwi r20, r1, 52 \r
168         lwi r19, r1, 56 \r
169         lwi r18, r1, 60 \r
170         lwi r17, r1, 64 \r
171         lwi r16, r1, 68 \r
172         lwi r15, r1, 72 \r
173         lwi r14, r1, 76 \r
174         lwi r13, r1, 80 \r
175         lwi r12, r1, 84 \r
176         lwi r11, r1, 88 \r
177         lwi r10, r1, 92 \r
178         lwi r9, r1, 96  \r
179         lwi r8, r1, 100 \r
180         lwi r7, r1, 104\r
181         lwi r6, r1, 108\r
182         lwi r5, r1, 112\r
183         lwi r4, r1, 116\r
184         lwi r2, r1, 124\r
185 \r
186         /* Load the critical nesting value. */\r
187         lwi r3, r1, 128\r
188         swi r3, r0, uxCriticalNesting\r
189 \r
190         /* Obtain the MSR value from the stack. */\r
191         lwi r3, r1, 8\r
192 \r
193         /* Are interrupts enabled in the MSR?  If so return using an return from \r
194         interrupt instruction to ensure interrupts are enabled only once the task\r
195         is running again. */\r
196         andi r3, r3, 2\r
197         beqid r3, 36\r
198         or r0, r0, r0\r
199 \r
200         /* Reload the rmsr from the stack, clear the enable interrupt bit in the\r
201         value before saving back to rmsr register, then return enabling interrupts\r
202         as we return. */\r
203         lwi r3, r1, 8\r
204         andi r3, r3, ~2\r
205         mts rmsr, r3\r
206         lwi r3, r1, 120\r
207         addik r1, r1, 132\r
208         rtid r14, 0\r
209         or r0, r0, r0\r
210 \r
211         /* Reload the rmsr from the stack, place it in the rmsr register, and\r
212         return without enabling interrupts. */\r
213         lwi r3, r1, 8\r
214         mts rmsr, r3\r
215         lwi r3, r1, 120\r
216         addik r1, r1, 132\r
217         rtsd r14, 0\r
218         or r0, r0, r0\r
219 \r
220         .endm\r
221 \r
222         .text\r
223         .align  2\r
224 \r
225 \r
226 __FreeRTOS_interrupt_handler:\r
227         portSAVE_CONTEXT\r
228         /* Entered via an interrupt so interrupts must be enabled in msr. */\r
229         ori r31, r31, 2\r
230         /* Stack msr. */\r
231         swi r31, r1, 8\r
232         /* Stack the return address.  As we entered via an interrupt we do\r
233         not need to modify the return address prior to stacking. */\r
234         swi r14, r1, 76\r
235         /* Now switch to use the ISR stack. */\r
236         lwi r3, r0, pulISRStack\r
237         add r1, r3, r0\r
238         bralid r15, vTaskISRHandler\r
239         or r0, r0, r0\r
240         portRESTORE_CONTEXT\r
241 \r
242 \r
243 VPortYieldASM:\r
244         portSAVE_CONTEXT\r
245         /* Stack msr. */\r
246         swi r31, r1, 8\r
247         /* Modify the return address so we return to the instruction after the\r
248         exception. */\r
249         addi r14, r14, 8\r
250         swi r14, r1, 76\r
251         /* Now switch to use the ISR stack. */\r
252         lwi r3, r0, pulISRStack\r
253         add r1, r3, r0\r
254         bralid r15, vTaskSwitchContext\r
255         or r0, r0, r0\r
256         portRESTORE_CONTEXT\r
257 \r
258 vStartFirstTask:\r
259         portRESTORE_CONTEXT\r
260         \r
261         \r
262 \r
263 \r
264 \r
265 \r