]> git.sur5r.net Git - freertos/blob - Source/portable/MPLAB/PIC32MX/port_asm.S
Update version numbers to V4.8.0
[freertos] / Source / portable / MPLAB / PIC32MX / port_asm.S
1 /*\r
2         FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section \r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         ***************************************************************************\r
28         *                                                                                                                                                 *\r
29         * SAVE TIME AND MONEY!  Why not get us to quote to get FreeRTOS.org               *\r
30         * running on your hardware - or even write all or part of your application*\r
31         * for you?  See http://www.OpenRTOS.com for details.                                      *\r
32         *                                                                                                                                                 *\r
33         ***************************************************************************\r
34         ***************************************************************************\r
35 \r
36         Please ensure to read the configuration and relevant port sections of the\r
37         online documentation.\r
38 \r
39         http://www.FreeRTOS.org - Documentation, latest information, license and \r
40         contact details.\r
41 \r
42         http://www.SafeRTOS.com - A version that is certified for use in safety \r
43         critical systems.\r
44 \r
45         http://www.OpenRTOS.com - Commercial support, development, porting, \r
46         licensing and training services.\r
47 */\r
48  \r
49 #include <p32xxxx.h>\r
50 #include <sys/asm.h>\r
51 #include "ISR_Support.h"\r
52  \r
53 #define portEXC_CODE_MASK ( 0x1f << 2 )\r
54 \r
55         .set    nomips16\r
56         .set    noreorder\r
57         \r
58         .extern pxCurrentTCB\r
59         .extern uxCriticalNesting\r
60         .extern vTaskSwitchContext\r
61         .extern vTaskIncrementTick\r
62         .extern vApplicationGeneralExceptionHandler\r
63         .extern xISRStackTop\r
64         \r
65         .global vPortStartFirstTask\r
66         .global _general_exception_context\r
67         .global vT1InterruptHandler\r
68 \r
69 \r
70 /******************************************************************/\r
71 \r
72         .section        .FreeRTOS, "ax", @progbits\r
73         .set            noreorder\r
74         .set            noat\r
75         .ent            vT1InterruptHandler\r
76         \r
77 vT1InterruptHandler:\r
78 \r
79         portSAVE_CONTEXT\r
80 \r
81         jal             vTaskIncrementTick\r
82         nop\r
83 \r
84         /* If we are using the preemptive scheduler then we might want to select\r
85         a different task to execute. */\r
86         #if configUSE_PREEMPTION == 1\r
87                 jal             vTaskSwitchContext\r
88                 nop\r
89         #endif /* configUSE_PREEMPTION */\r
90 \r
91         /* Clear timer 0 interrupt. */\r
92         la                      s1, IFS0CLR\r
93         addiu       s0,zero,_IFS0_T1IF_MASK\r
94         sw                      s0, 0(s1)\r
95 \r
96         portRESTORE_CONTEXT\r
97 \r
98         .end vT1InterruptHandler\r
99 \r
100 /******************************************************************/\r
101 \r
102         .section        .FreeRTOS, "ax", @progbits\r
103         .set            noreorder\r
104         .set            noat\r
105         .ent            xPortStartScheduler\r
106 \r
107 vPortStartFirstTask:\r
108 \r
109         /* Simply restore the context of the highest priority task that has been\r
110         created so far. */\r
111         portRESTORE_CONTEXT\r
112 \r
113         .end xPortStartScheduler\r
114 \r
115 /*******************************************************************/\r
116 \r
117         .section        .FreeRTOS, "ax", @progbits\r
118         .set            noreorder\r
119         .set            noat\r
120         .ent            _general_exception_context\r
121 \r
122 _general_exception_context:\r
123 \r
124         /* Save the context of the current task. */\r
125         portSAVE_CONTEXT\r
126 \r
127         /* Was this handler caused by a syscall?  The original Cause\r
128         value was saved to the stack as it could change as interrupts\r
129         nest.  Use of k registers must be protected from use by nesting\r
130         interrupts. */\r
131         lw                      s7, portCAUSE_STACK_LOCATION(s5)\r
132         andi            s7, s7, portEXC_CODE_MASK\r
133         addi            s7, s7, -( _EXCCODE_SYS << 2 )\r
134 \r
135         /* Yes - call the SYSCALL handler to select a new task to execute. */\r
136         beq         s7, zero, SyscallHandler\r
137         nop\r
138 \r
139         /* No - call the application handler to handle all other types of \r
140         exception.  Pass the status and cause to the application provided \r
141         handler.  Interrupts are disabled during the execution of the user\r
142         defined handler. */\r
143         di\r
144         lw                      a1, portSTATUS_STACK_LOCATION(s5)\r
145         lw                      a0, portCAUSE_STACK_LOCATION(s5)\r
146         jal                     vApplicationGeneralExceptionHandler\r
147         nop\r
148         ei\r
149         beq             zero, zero, FinishExceptionHandler\r
150         nop\r
151 \r
152 SyscallHandler:\r
153 \r
154         /* Adjust the return that was placed onto the stack to be the \r
155         address of the instruction following the syscall.  s6 already\r
156         contains the EPC value. */\r
157         addi            s6, 4\r
158         sw                      s6, portEPC_STACK_LOCATION(s5)\r
159 \r
160         jal                     vTaskSwitchContext\r
161         nop\r
162 \r
163 FinishExceptionHandler:\r
164         portRESTORE_CONTEXT\r
165 \r
166         .end            _general_exception_context\r
167 \r
168 \r
169 \r