2 FreeRTOS.org V5.1.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\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
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
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
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
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
50 #include "FreeRTOSConfig.h"
\r
52 #define portCONTEXT_SIZE 132
\r
53 #define portEPC_STACK_LOCATION 124
\r
54 #define portSTATUS_STACK_LOCATION 128
\r
56 /******************************************************************/
\r
57 .macro portSAVE_CONTEXT
\r
59 /* Make room for the context. First save the current status so we can
\r
60 manipulate it, and the cause and EPC registers so we capture their
\r
61 original values in case of interrupt nesting. */
\r
63 addiu sp, sp, -portCONTEXT_SIZE
\r
64 mfc0 k1, _CP0_STATUS
\r
66 /* Also save s6 and s5 so we can use them during this interrupt. Any
\r
67 nesting interrupts should maintain the values of these registers
\r
71 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
73 /* Enable interrupts above the current priority. */
\r
78 /* s5 is used as the frame pointer. */
\r
81 /* Check the nesting count value. */
\r
82 la k0, uxInterruptNesting
\r
85 /* If the nesting count is 0 then swap to the the system stack, otherwise
\r
86 the system stack is already being used. */
\r
90 /* Swap to the system stack. */
\r
94 /* Increment and save the nesting count. */
\r
98 /* s6 holds the EPC value, this is saved after interrupts are re-enabled. */
\r
101 /* Re-enable interrupts. */
\r
102 mtc0 k1, _CP0_STATUS
\r
104 /* Save the context into the space just created. s6 is saved again
\r
105 here as it now contains the EPC value. No other s registers need be
\r
125 sw s6, portEPC_STACK_LOCATION(s5)
\r
128 /* s6 is used as a scratch register. */
\r
134 /* Update the task stack pointer value if nesting is zero. */
\r
135 la s6, uxInterruptNesting
\r
141 /* Save the stack pointer. */
\r
142 la s6, uxSavedTaskStackPointer
\r
147 /******************************************************************/
\r
148 .macro portRESTORE_CONTEXT
\r
150 /* Restore the stack pointer from the TCB. This is only done if the
\r
151 nesting count is 1. */
\r
152 la s6, uxInterruptNesting
\r
157 la s6, uxSavedTaskStackPointer
\r
160 /* Restore the context. */
\r
166 /* s6 is loaded as it was used as a scratch register and therefore saved
\r
167 as part of the interrupt context. */
\r
188 /* Protect access to the k registers, and others. */
\r
191 /* Decrement the nesting count. */
\r
192 la k0, uxInterruptNesting
\r
197 lw k0, portSTATUS_STACK_LOCATION(s5)
\r
198 lw k1, portEPC_STACK_LOCATION(s5)
\r
200 /* Leave the stack how we found it. First load sp from s5, then restore
\r
201 s5 from the stack. */
\r
204 addiu sp, sp, portCONTEXT_SIZE
\r
206 mtc0 k0, _CP0_STATUS
\r