]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/MPLAB/PIC32MEC14xx/port_asm.S
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS / Source / portable / MPLAB / PIC32MEC14xx / port_asm.S
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 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 /* FreeRTOS includes. */\r
29 #include "FreeRTOSConfig.h"\r
30 #include "ISR_Support.h"\r
31 \r
32 /* Microchip includes. */\r
33 #include <xc.h>\r
34 #include <sys/asm.h>\r
35 \r
36         .extern pxCurrentTCB\r
37         .extern vTaskSwitchContext\r
38         .extern vPortIncrementTick\r
39         .extern xISRStackTop\r
40 \r
41         PORT_CPP_JTVIC_BASE = 0xBFFFC000\r
42         PORT_CCP_JTVIC_GIRQ24_SRC = 0xBFFFC100\r
43 \r
44         .global vPortStartFirstTask .text\r
45         .global vPortYieldISR .text\r
46         .global vPortTickInterruptHandler .text\r
47 \r
48 \r
49 /******************************************************************/\r
50 \r
51 \r
52 /***************************************************************\r
53 *  The following is needed to locate the\r
54 *  vPortTickInterruptHandler function into the correct vector\r
55 *  MEC14xx - This ISR will only be used if HW timers' interrupts\r
56 *  in GIRQ23 are disaggregated.\r
57 *\r
58 ***************************************************************/\r
59 \r
60         .set  noreorder\r
61         .set  noat\r
62         .set  micromips\r
63 \r
64         .section .text, code\r
65         .ent    vPortTickInterruptHandler\r
66 \r
67 #if configTIMERS_DISAGGREGATED_ISRS == 0\r
68 \r
69         .globl girq23_isr\r
70 \r
71 girq23_isr:\r
72 vPortTickInterruptHandler:\r
73 \r
74         portSAVE_CONTEXT\r
75 \r
76         jal             girq23_handler\r
77         nop\r
78 \r
79         portRESTORE_CONTEXT\r
80 \r
81 .end vPortTickInterruptHandler\r
82 \r
83 #else\r
84 \r
85         .globl girq23_b4\r
86 \r
87 girq23_b4:\r
88 vPortTickInterruptHandler:\r
89 \r
90         portSAVE_CONTEXT\r
91 \r
92         jal             vPortIncrementTick\r
93         nop\r
94 \r
95         portRESTORE_CONTEXT\r
96 \r
97 .end vPortTickInterruptHandler\r
98 \r
99 #endif /* #if configTIMERS_DISAGGREGATED_ISRS == 0 */\r
100 \r
101 /******************************************************************/\r
102 \r
103         .set    micromips\r
104         .set    noreorder\r
105         .set    noat\r
106 \r
107         .section .text, code\r
108         .ent    vPortStartFirstTask\r
109 \r
110 vPortStartFirstTask:\r
111 \r
112         /* Simply restore the context of the highest priority task that has\r
113         been created so far. */\r
114         portRESTORE_CONTEXT\r
115 \r
116 .end vPortStartFirstTask\r
117 \r
118 \r
119 \r
120 /*******************************************************************/\r
121 \r
122 /***************************************************************\r
123 *  The following is needed to locate the vPortYieldISR function into the correct\r
124 * vector.\r
125 ***************************************************************/\r
126 \r
127         .set micromips\r
128         .set noreorder\r
129         .set noat\r
130 \r
131         .section .text, code\r
132 \r
133         .global vPortYieldISR\r
134 \r
135 \r
136 #if configCPU_DISAGGREGATED_ISRS == 0\r
137         .global girq24_isr\r
138         .ent girq24_isr\r
139 girq24_isr:\r
140         la              k0, PORT_CPP_JTVIC_BASE\r
141         lw              k0, 0x10C(k0)\r
142         andi    k1, k0, 0x2\r
143         bgtz    k1, vPortYieldISR\r
144         nop\r
145 \r
146         portSAVE_CONTEXT\r
147 \r
148         jal             girq24_b_0_2\r
149 \r
150         portRESTORE_CONTEXT\r
151 \r
152         .end girq24_isr\r
153 \r
154 #else\r
155         .global girq24_b1\r
156 girq24_b1:\r
157 #endif\r
158                 .ent  vPortYieldISR\r
159 vPortYieldISR:\r
160 \r
161         /* Make room for the context. First save the current status so it can be\r
162         manipulated, and the cause and EPC registers so thier original values\r
163         are captured. */\r
164         addiu   sp, sp, -portCONTEXT_SIZE\r
165         mfc0    k1, _CP0_STATUS\r
166 \r
167         /* Also save s6 and s5 so they can be used.  Any nesting interrupts should\r
168         maintain the values of these registers across the ISR. */\r
169         sw              s6, 44(sp)\r
170         sw              s5, 40(sp)\r
171         sw              k1, portSTATUS_STACK_LOCATION(sp)\r
172 \r
173         /* Prepare to re-enable interrupts above the kernel priority. */\r
174         ins             k1, zero, 10, 7          /* Clear IPL bits 0:6. */\r
175         ins             k1, zero, 18, 1          /* Clear IPL bit 7  */\r
176         ori             k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )\r
177         ins             k1, zero, 1, 4            /* Clear EXL, ERL and UM. */\r
178 \r
179         /* s5 is used as the frame pointer. */\r
180         add             s5, zero, sp\r
181 \r
182         /* Swap to the system stack.  This is not conditional on the nesting\r
183         count as this interrupt is always the lowest priority and therefore\r
184         the nesting is always 0. */\r
185         la              sp, xISRStackTop\r
186         lw              sp, (sp)\r
187 \r
188         /* Set the nesting count. */\r
189         la              k0, uxInterruptNesting\r
190         addiu   s6, zero, 1\r
191         sw              s6, 0(k0)\r
192 \r
193         /* s6 holds the EPC value, this is saved with the rest of the context\r
194         after interrupts are enabled. */\r
195         mfc0    s6, _CP0_EPC\r
196 \r
197         /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */\r
198         mtc0    k1, _CP0_STATUS\r
199 \r
200         /* Save the context into the space just created.  s6 is saved again\r
201         here as it now contains the EPC value. */\r
202         sw              ra, 120(s5)\r
203         sw              s8, 116(s5)\r
204         sw              t9, 112(s5)\r
205         sw              t8, 108(s5)\r
206         sw              t7, 104(s5)\r
207         sw              t6, 100(s5)\r
208         sw              t5, 96(s5)\r
209         sw              t4, 92(s5)\r
210         sw              t3, 88(s5)\r
211         sw              t2, 84(s5)\r
212         sw              t1, 80(s5)\r
213         sw              t0, 76(s5)\r
214         sw              a3, 72(s5)\r
215         sw              a2, 68(s5)\r
216         sw              a1, 64(s5)\r
217         sw              a0, 60(s5)\r
218         sw              v1, 56(s5)\r
219         sw              v0, 52(s5)\r
220         sw              s7, 48(s5)\r
221         sw              s6, portEPC_STACK_LOCATION(s5)\r
222         /* s5 and s6 has already been saved. */\r
223         sw              s4, 36(s5)\r
224         sw              s3, 32(s5)\r
225         sw              s2, 28(s5)\r
226         sw              s1, 24(s5)\r
227         sw              s0, 20(s5)\r
228         sw              $1, 16(s5)\r
229 \r
230         /* s7 is used as a scratch register as this should always be saved acro ss\r
231         nesting interrupts. */\r
232         mfhi    s7\r
233         sw              s7, 12(s5)\r
234         mflo    s7\r
235         sw              s7, 8(s5)\r
236 \r
237         /* Save the stack pointer to the task. */\r
238         la              s7, pxCurrentTCB\r
239         lw              s7, (s7)\r
240         sw              s5, (s7)\r
241 \r
242         /* Set the interrupt mask to the max priority that can use the API.\r
243         The yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY\r
244         which is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only\r
245         ever raise the IPL value and never lower it. */\r
246         di\r
247         ehb\r
248         mfc0    s7, _CP0_STATUS\r
249         ins             s7, zero, 10, 7\r
250         ins             s7, zero, 18, 1\r
251         ori             s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1\r
252 \r
253         /* This mtc0 re-enables interrupts, but only above\r
254         configMAX_SYSCALL_INTERRUPT_PRIORITY. */\r
255         mtc0    s6, _CP0_STATUS\r
256         ehb\r
257 \r
258         /* Clear the software interrupt in the core. */\r
259         mfc0    s6, _CP0_CAUSE\r
260         ins             s6, zero, 8, 1\r
261         mtc0    s6, _CP0_CAUSE\r
262         ehb\r
263 \r
264         /* Clear the interrupt in the interrupt controller.\r
265         MEC14xx GIRQ24 Source bit[1] = 1 to clear */\r
266         la              s6, PORT_CCP_JTVIC_GIRQ24_SRC\r
267         addiu   s4, zero, 2\r
268         sw              s4, (s6)\r
269         jal             vTaskSwitchContext\r
270         nop\r
271 \r
272         /* Clear the interrupt mask again. The saved status value is still in s7 */\r
273         mtc0    s7, _CP0_STATUS\r
274         ehb\r
275 \r
276         /* Restore the stack pointer from the TCB. */\r
277         la              s0, pxCurrentTCB\r
278         lw              s0, (s0)\r
279         lw              s5, (s0)\r
280 \r
281         /* Restore the rest of the context. */\r
282         lw              s0, 8(s5)\r
283         mtlo    s0\r
284         lw              s0, 12(s5)\r
285         mthi    s0\r
286 \r
287         lw              $1, 16(s5)\r
288         lw              s0, 20(s5)\r
289         lw              s1, 24(s5)\r
290         lw              s2, 28(s5)\r
291         lw              s3, 32(s5)\r
292         lw              s4, 36(s5)\r
293 \r
294         /* s5 is loaded later. */\r
295         lw              s6, 44(s5)\r
296         lw              s7, 48(s5)\r
297         lw              v0, 52(s5)\r
298         lw              v1, 56(s5)\r
299         lw              a0, 60(s5)\r
300         lw              a1, 64(s5)\r
301         lw              a2, 68(s5)\r
302         lw              a3, 72(s5)\r
303         lw              t0, 76(s5)\r
304         lw              t1, 80(s5)\r
305         lw              t2, 84(s5)\r
306         lw              t3, 88(s5)\r
307         lw              t4, 92(s5)\r
308         lw              t5, 96(s5)\r
309         lw              t6, 100(s5)\r
310         lw              t7, 104(s5)\r
311         lw              t8, 108(s5)\r
312         lw              t9, 112(s5)\r
313         lw              s8, 116(s5)\r
314         lw              ra, 120(s5)\r
315 \r
316         /* Protect access to the k registers, and others. */\r
317         di\r
318         ehb\r
319 \r
320         /* Set nesting back to zero.  As the lowest priority interrupt this\r
321         interrupt cannot have nested. */\r
322         la              k0, uxInterruptNesting\r
323         sw              zero, 0(k0)\r
324 \r
325         /* Switch back to use the real stack pointer. */\r
326         add             sp, zero, s5\r
327 \r
328         /* Restore the real s5 value. */\r
329         lw              s5, 40(sp)\r
330 \r
331         /* Pop the status and epc values. */\r
332         lw              k1, portSTATUS_STACK_LOCATION(sp)\r
333         lw              k0, portEPC_STACK_LOCATION(sp)\r
334 \r
335         /* Remove stack frame. */\r
336         addiu   sp, sp, portCONTEXT_SIZE\r
337 \r
338         mtc0    k1, _CP0_STATUS\r
339         mtc0    k0, _CP0_EPC\r
340         ehb\r
341         eret\r
342         nop\r
343 \r
344 .end    vPortYieldISR\r
345 \r
346 \r
347 \r
348 \r