2 * FreeRTOS Kernel V10.3.1
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
27 #include "FreeRTOSConfig.h"
\r
29 #define portCONTEXT_SIZE 132
\r
30 #define portEPC_STACK_LOCATION 124
\r
31 #define portSTATUS_STACK_LOCATION 128
\r
33 #ifdef __LANGUAGE_ASSEMBLY__
\r
35 /******************************************************************/
\r
36 .macro portSAVE_CONTEXT
\r
38 /* Make room for the context. First save the current status so it can be
\r
39 * manipulated, and the cause and EPC registers so their original values are
\r
42 addiu sp, sp, -portCONTEXT_SIZE
\r
43 mfc0 k1, _CP0_STATUS
\r
45 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
46 * maintain the values of these registers across the ISR. */
\r
49 sw k1, portSTATUS_STACK_LOCATION( sp )
\r
51 /* Prepare to enable interrupts above the current priority.
\r
52 * k0 = k0 >> 10. Moves RIPL[17:10] to [7:0] */
\r
55 /* Insert bit field. 7 bits k0[6:0] to k1[16:10] */
\r
58 /* Sets CP0.Status.IPL = CP0.Cause.RIPL
\r
59 * Copy the MSB of the IPL, but it would be an error if it was set anyway. */
\r
62 /* MSB of IPL is bit[18] of CP0.Status */
\r
65 /* CP0.Status[5:1] = 0 b[5]=Rsvd, b[4]=UM,
\r
66 * b[3]=Rsvd, b[2]=ERL, b[1]=EXL
\r
67 * Setting EXL=0 allows higher priority interrupts
\r
68 * to preempt this handler */
\r
72 /* s5 is used as the frame pointer. */
\r
75 /* Check the nesting count value. */
\r
76 la k0, uxInterruptNesting
\r
79 /* If the nesting count is 0 then swap to the the system stack, otherwise
\r
80 * the system stack is already being used. */
\r
84 /* Swap to the system stack. */
\r
88 /* Increment and save the nesting count. */
\r
92 /* s6 holds the EPC value, this is saved after interrupts are re-enabled. */
\r
95 /* Re-enable interrupts. */
\r
96 mtc0 k1, _CP0_STATUS
\r
98 /* Save the context into the space just created. s6 is saved again
\r
99 * here as it now contains the EPC value. No other s registers need be
\r
101 sw ra, 120 ( s5 ) /* Return address (RA=R31) */
\r
102 sw s8, 116 ( s5 ) /* Frame Pointer (FP=R30) */
\r
119 sw s6, portEPC_STACK_LOCATION( s5 )
\r
122 /* MEC14xx does not have DSP, removed 7 words */
\r
128 /* Update the task stack pointer value if nesting is zero. */
\r
129 la s6, uxInterruptNesting
\r
135 /* Save the stack pointer. */
\r
136 la s6, uxSavedTaskStackPointer
\r
141 /******************************************************************/
\r
142 .macro portRESTORE_CONTEXT
\r
144 /* Restore the stack pointer from the TCB. This is only done if the
\r
145 * nesting count is 1. */
\r
146 la s6, uxInterruptNesting
\r
151 la s6, uxSavedTaskStackPointer
\r
154 /* Restore the context.
\r
155 * MCHP MEC14xx does not include DSP */
\r
163 /* s6 is loaded as it was used as a scratch register and therefore saved
\r
164 * as part of the interrupt context. */
\r
185 /* Protect access to the k registers, and others. */
\r
189 /* Decrement the nesting count. */
\r
190 la k0, uxInterruptNesting
\r
195 lw k0, portSTATUS_STACK_LOCATION( s5 )
\r
196 lw k1, portEPC_STACK_LOCATION( s5 )
\r
198 /* Leave the stack in its original state. First load sp from s5, then
\r
199 * restore s5 from the stack. */
\r
202 addiu sp, sp, portCONTEXT_SIZE
\r
204 mtc0 k0, _CP0_STATUS
\r
212 #endif /* #ifdef __LANGUAGE_ASSEMBLY__ */
\r