]> begriffs open source - freertos/blob - portable/oWatcom/16BitDOS/common/portcomn.c
Style: uncrustify kernel files
[freertos] / portable / oWatcom / 16BitDOS / common / portcomn.c
1 /*\r
2  * FreeRTOS Kernel V10.3.1\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Changes from V1.00:\r
30  *\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
34  +\r
35  + Changes from V2.4.2:\r
36  +\r
37  + pvPortMalloc and vPortFree have been removed.  The projects now use\r
38  +    the definitions from the source/portable/MemMang directory.\r
39  +\r
40  + Changes from V2.6.1:\r
41  +\r
42  + usPortCheckFreeStackSpace() has been moved to tasks.c.\r
43  */\r
44 \r
45 \r
46 \r
47 #include <stdlib.h>\r
48 #include "FreeRTOS.h"\r
49 \r
50 /*-----------------------------------------------------------*/\r
51 \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
56 {\r
57     StackType_t DS_Reg = 0, * pxOriginalSP;\r
58 \r
59     /* Place a few bytes of known values on the bottom of the stack.\r
60      * This is just useful for debugging. */\r
61 \r
62     *pxTopOfStack = 0x1111;\r
63     pxTopOfStack--;\r
64     *pxTopOfStack = 0x2222;\r
65     pxTopOfStack--;\r
66     *pxTopOfStack = 0x3333;\r
67     pxTopOfStack--;\r
68     *pxTopOfStack = 0x4444;\r
69     pxTopOfStack--;\r
70     *pxTopOfStack = 0x5555;\r
71     pxTopOfStack--;\r
72 \r
73 \r
74     /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */\r
75 \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
79      * of the task. */\r
80     *pxTopOfStack = portINITIAL_SW;\r
81     pxTopOfStack--;\r
82     *pxTopOfStack = FP_SEG( pxCode );\r
83     pxTopOfStack--;\r
84     *pxTopOfStack = FP_OFF( pxCode );\r
85     pxTopOfStack--;\r
86 \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
91      * called. */\r
92     pxOriginalSP = pxTopOfStack;\r
93 \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
96      * easier. */\r
97     *pxTopOfStack = FP_OFF( pvParameters ); /* AX */\r
98     pxTopOfStack--;\r
99     *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */\r
100     pxTopOfStack--;\r
101     *pxTopOfStack = FP_SEG( pvParameters ); /* DX */\r
102     pxTopOfStack--;\r
103     *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */\r
104     pxTopOfStack--;\r
105     *pxTopOfStack = FP_OFF( pxOriginalSP ); /* SP */\r
106     pxTopOfStack--;\r
107     *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */\r
108     pxTopOfStack--;\r
109     *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */\r
110     pxTopOfStack--;\r
111     *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */\r
112 \r
113     /* We need the true data segment. */\r
114     __asm {\r
115         MOV DS_Reg, DS\r
116     };\r
117 \r
118     pxTopOfStack--;\r
119     *pxTopOfStack = DS_Reg; /* DS */\r
120 \r
121     pxTopOfStack--;\r
122     *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */\r
123 \r
124     /* The AX register is pushed again twice - don't know why. */\r
125     pxTopOfStack--;\r
126     *pxTopOfStack = FP_OFF( pvParameters ); /* AX */\r
127     pxTopOfStack--;\r
128     *pxTopOfStack = FP_OFF( pvParameters ); /* AX */\r
129 \r
130 \r
131     #ifdef DEBUG_BUILD\r
132 \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
137         pxTopOfStack--;\r
138     #endif\r
139 \r
140     /*lint +e950 +e611 +e923 */\r
141 \r
142     return pxTopOfStack;\r
143 }\r
144 /*-----------------------------------------------------------*/\r