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
25 * 1 tab == 4 spaces!
\r
29 * Changes from V1.00:
\r
31 + pxPortInitialiseStack() now initialises the stack of new tasks to the
\r
32 + same format used by the compiler. This allows the compiler generated
\r
33 + interrupt mechanism to be used for context switches.
\r
35 + Changes from V2.4.2:
\r
37 + pvPortMalloc and vPortFree have been removed. The projects now use
\r
38 + the definitions from the source/portable/MemMang directory.
\r
40 + Changes from V2.6.1:
\r
42 + usPortCheckFreeStackSpace() has been moved to tasks.c.
\r
48 #include "FreeRTOS.h"
\r
50 /*-----------------------------------------------------------*/
\r
52 /* See header file for description. */
\r
53 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
\r
54 TaskFunction_t pxCode,
\r
55 void * pvParameters )
\r
57 StackType_t DS_Reg = 0, * pxOriginalSP;
\r
59 /* Place a few bytes of known values on the bottom of the stack.
\r
60 * This is just useful for debugging. */
\r
62 *pxTopOfStack = 0x1111;
\r
64 *pxTopOfStack = 0x2222;
\r
66 *pxTopOfStack = 0x3333;
\r
68 *pxTopOfStack = 0x4444;
\r
70 *pxTopOfStack = 0x5555;
\r
74 /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */
\r
76 /* We are going to start the scheduler using a return from interrupt
\r
77 * instruction to load the program counter, so first there would be the
\r
78 * status register and interrupt return address. We make this the start
\r
80 *pxTopOfStack = portINITIAL_SW;
\r
82 *pxTopOfStack = FP_SEG( pxCode );
\r
84 *pxTopOfStack = FP_OFF( pxCode );
\r
87 /* We are going to setup the stack for the new task to look like
\r
88 * the stack frame was setup by a compiler generated ISR. We need to know
\r
89 * the address of the existing stack top to place in the SP register within
\r
90 * the stack frame. pxOriginalSP holds SP before (simulated) pusha was
\r
92 pxOriginalSP = pxTopOfStack;
\r
94 /* The remaining registers would be pushed on the stack by our context
\r
95 * switch function. These are loaded with values simply to make debugging
\r
97 *pxTopOfStack = FP_OFF( pvParameters ); /* AX */
\r
99 *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */
\r
101 *pxTopOfStack = FP_SEG( pvParameters ); /* DX */
\r
103 *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */
\r
105 *pxTopOfStack = FP_OFF( pxOriginalSP ); /* SP */
\r
107 *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */
\r
109 *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */
\r
111 *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */
\r
113 /* We need the true data segment. */
\r
119 *pxTopOfStack = DS_Reg; /* DS */
\r
122 *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */
\r
124 /* The AX register is pushed again twice - don't know why. */
\r
126 *pxTopOfStack = FP_OFF( pvParameters ); /* AX */
\r
128 *pxTopOfStack = FP_OFF( pvParameters ); /* AX */
\r
133 /* The compiler adds space to each ISR stack if building to
\r
134 * include debug information. Presumably this is used by the
\r
135 * debugger - we don't need to initialise it to anything just
\r
136 * make sure it is there. */
\r
140 /*lint +e950 +e611 +e923 */
\r
142 return pxTopOfStack;
\r
144 /*-----------------------------------------------------------*/
\r