]> begriffs open source - freertos/blob - Source/portable/MPLAB/PIC32MX/port_asm.S
Update to V4.7.1
[freertos] / Source / portable / MPLAB / PIC32MX / port_asm.S
1 /*\r
2         FreeRTOS.org V4.7.1 - 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         Please ensure to read the configuration and relevant port sections of the \r
29         online documentation.\r
30 \r
31         +++ http://www.FreeRTOS.org +++\r
32         Documentation, latest information, license and contact details.  \r
33 \r
34         +++ http://www.SafeRTOS.com +++\r
35         A version that is certified for use in safety critical systems.\r
36 \r
37         +++ http://www.OpenRTOS.com +++\r
38         Commercial support, development, porting, licensing and training services.\r
39 \r
40         ***************************************************************************\r
41 */\r
42  \r
43 #include <p32xxxx.h>\r
44 #include <sys/asm.h>\r
45 #include "ISR_Support.h"\r
46  \r
47 #define portEXC_CODE_MASK ( 0x1f << 2 )\r
48 \r
49         .set    nomips16\r
50         .set    noreorder\r
51         \r
52         .extern pxCurrentTCB\r
53         .extern uxCriticalNesting\r
54         .extern vTaskSwitchContext\r
55         .extern vTaskIncrementTick\r
56         .extern vApplicationGeneralExceptionHandler\r
57         .extern xISRStackTop\r
58         \r
59         .global vPortStartFirstTask\r
60         .global _general_exception_context\r
61         .global vT1InterruptHandler\r
62 \r
63 \r
64 /******************************************************************/\r
65 \r
66         .section        .FreeRTOS, "ax", @progbits\r
67         .set            noreorder\r
68         .set            noat\r
69         .ent            vT1InterruptHandler\r
70         \r
71 vT1InterruptHandler:\r
72 \r
73         portSAVE_CONTEXT\r
74 \r
75         jal             vTaskIncrementTick\r
76         nop\r
77 \r
78         /* If we are using the preemptive scheduler then we might want to select\r
79         a different task to execute. */\r
80         #if configUSE_PREEMPTION == 1\r
81                 jal             vTaskSwitchContext\r
82                 nop\r
83         #endif /* configUSE_PREEMPTION */\r
84 \r
85         /* Clear timer 0 interrupt. */\r
86         la                      s1, IFS0CLR
87         addiu       s0,zero,_IFS0_T1IF_MASK
88         sw                      s0, 0(s1)\r
89 \r
90         portRESTORE_CONTEXT\r
91 \r
92         .end vT1InterruptHandler\r
93 \r
94 /******************************************************************/\r
95 \r
96         .section        .FreeRTOS, "ax", @progbits\r
97         .set            noreorder\r
98         .set            noat\r
99         .ent            xPortStartScheduler\r
100 \r
101 vPortStartFirstTask:\r
102 \r
103         /* Simply restore the context of the highest priority task that has been\r
104         created so far. */\r
105         portRESTORE_CONTEXT\r
106 \r
107         .end xPortStartScheduler\r
108 \r
109 /*******************************************************************/\r
110 \r
111         .section        .FreeRTOS, "ax", @progbits\r
112         .set            noreorder\r
113         .set            noat\r
114         .ent            _general_exception_context\r
115 \r
116 _general_exception_context:\r
117 \r
118         /* Save the context of the current task. */\r
119         portSAVE_CONTEXT\r
120 \r
121         /* Was this handler caused by a syscall?  The original Cause\r
122         value was saved to the stack as it could change as interrupts\r
123         nest.  Use of k registers must be protected from use by nesting\r
124         interrupts. */\r
125         lw                      s7, portCAUSE_STACK_LOCATION(s5)\r
126         andi            s7, s7, portEXC_CODE_MASK\r
127         addi            s7, s7, -( _EXCCODE_SYS << 2 )\r
128 \r
129         /* Yes - call the SYSCALL handler to select a new task to execute. */\r
130         beq         s7, zero, SyscallHandler\r
131         nop\r
132 \r
133         /* No - call the application handler to handle all other types of \r
134         exception.  Pass the status and cause to the application provided \r
135         handler.  Interrupts are disabled during the execution of the user\r
136         defined handler. */\r
137         di\r
138         lw                      a1, portSTATUS_STACK_LOCATION(s5)\r
139         lw                      a0, portCAUSE_STACK_LOCATION(s5)\r
140         jal                     vApplicationGeneralExceptionHandler
141         nop\r
142         ei\r
143         beq             zero, zero, FinishExceptionHandler\r
144         nop\r
145 \r
146 SyscallHandler:\r
147 \r
148         /* Adjust the return that was placed onto the stack to be the \r
149         address of the instruction following the syscall.  s6 already\r
150         contains the EPC value. */\r
151         addi            s6, 4\r
152         sw                      s6, portEPC_STACK_LOCATION(s5)\r
153 \r
154         jal                     vTaskSwitchContext\r
155         nop\r
156 \r
157 FinishExceptionHandler:\r
158         portRESTORE_CONTEXT\r
159 \r
160         .end            _general_exception_context\r
161 \r
162 \r
163