2 FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 #include "FreeRTOSConfig.h"
\r
54 #define portCONTEXT_SIZE 132
\r
55 #define portEPC_STACK_LOCATION 124
\r
56 #define portSTATUS_STACK_LOCATION 128
\r
58 /******************************************************************/
\r
59 .macro portSAVE_CONTEXT
\r
61 /* Make room for the context. First save the current status so we can
\r
62 manipulate it, and the cause and EPC registers so we capture their
\r
63 original values in case of interrupt nesting. */
\r
65 addiu sp, sp, -portCONTEXT_SIZE
\r
66 mfc0 k1, _CP0_STATUS
\r
68 /* Also save s6 and s5 so we can use them during this interrupt. Any
\r
69 nesting interrupts should maintain the values of these registers
\r
73 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
75 /* Enable interrupts above the current priority. */
\r
80 /* s5 is used as the frame pointer. */
\r
83 /* Check the nesting count value. */
\r
84 la k0, uxInterruptNesting
\r
87 /* If the nesting count is 0 then swap to the the system stack, otherwise
\r
88 the system stack is already being used. */
\r
92 /* Swap to the system stack. */
\r
96 /* Increment and save the nesting count. */
\r
100 /* s6 holds the EPC value, this is saved after interrupts are re-enabled. */
\r
103 /* Re-enable interrupts. */
\r
104 mtc0 k1, _CP0_STATUS
\r
106 /* Save the context into the space just created. s6 is saved again
\r
107 here as it now contains the EPC value. No other s registers need be
\r
127 sw s6, portEPC_STACK_LOCATION(s5)
\r
130 /* s6 is used as a scratch register. */
\r
136 /* Update the task stack pointer value if nesting is zero. */
\r
137 la s6, uxInterruptNesting
\r
143 /* Save the stack pointer. */
\r
144 la s6, uxSavedTaskStackPointer
\r
149 /******************************************************************/
\r
150 .macro portRESTORE_CONTEXT
\r
152 /* Restore the stack pointer from the TCB. This is only done if the
\r
153 nesting count is 1. */
\r
154 la s6, uxInterruptNesting
\r
159 la s6, uxSavedTaskStackPointer
\r
162 /* Restore the context. */
\r
168 /* s6 is loaded as it was used as a scratch register and therefore saved
\r
169 as part of the interrupt context. */
\r
190 /* Protect access to the k registers, and others. */
\r
193 /* Decrement the nesting count. */
\r
194 la k0, uxInterruptNesting
\r
199 lw k0, portSTATUS_STACK_LOCATION(s5)
\r
200 lw k1, portEPC_STACK_LOCATION(s5)
\r
202 /* Leave the stack how we found it. First load sp from s5, then restore
\r
203 s5 from the stack. */
\r
206 addiu sp, sp, portCONTEXT_SIZE
\r
208 mtc0 k0, _CP0_STATUS
\r