]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/oWatcom/16BitDOS/common/portcomn.c
Update version number in readiness for V10.2.0 release.
[freertos] / FreeRTOS / Source / portable / oWatcom / 16BitDOS / common / portcomn.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 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, TaskFunction_t pxCode, void *pvParameters )\r
54 {\r
55 StackType_t DS_Reg = 0, *pxOriginalSP;\r
56 \r
57         /* Place a few bytes of known values on the bottom of the stack. \r
58         This is just useful for debugging. */\r
59 \r
60         *pxTopOfStack = 0x1111;\r
61         pxTopOfStack--;\r
62         *pxTopOfStack = 0x2222;\r
63         pxTopOfStack--;\r
64         *pxTopOfStack = 0x3333;\r
65         pxTopOfStack--;\r
66         *pxTopOfStack = 0x4444;\r
67         pxTopOfStack--;\r
68         *pxTopOfStack = 0x5555;\r
69         pxTopOfStack--;\r
70 \r
71 \r
72         /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */\r
73 \r
74         /* We are going to start the scheduler using a return from interrupt\r
75         instruction to load the program counter, so first there would be the\r
76         status register and interrupt return address.  We make this the start \r
77         of the task. */\r
78         *pxTopOfStack = portINITIAL_SW; \r
79         pxTopOfStack--;\r
80         *pxTopOfStack = FP_SEG( pxCode );\r
81         pxTopOfStack--;\r
82         *pxTopOfStack = FP_OFF( pxCode );\r
83         pxTopOfStack--;\r
84 \r
85         /* We are going to setup the stack for the new task to look like\r
86         the stack frame was setup by a compiler generated ISR.  We need to know\r
87         the address of the existing stack top to place in the SP register within\r
88         the stack frame.  pxOriginalSP holds SP before (simulated) pusha was \r
89         called. */\r
90         pxOriginalSP = pxTopOfStack;\r
91 \r
92         /* The remaining registers would be pushed on the stack by our context \r
93         switch function.  These are loaded with values simply to make debugging\r
94         easier. */\r
95         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
96         pxTopOfStack--;\r
97         *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */\r
98         pxTopOfStack--;\r
99         *pxTopOfStack = FP_SEG( pvParameters );         /* DX */\r
100         pxTopOfStack--;\r
101         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */\r
102         pxTopOfStack--;\r
103         *pxTopOfStack = FP_OFF( pxOriginalSP );         /* SP */\r
104         pxTopOfStack--;\r
105         *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */\r
106         pxTopOfStack--;\r
107         *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */\r
108         pxTopOfStack--;\r
109         *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */\r
110 \r
111         /* We need the true data segment. */\r
112         __asm{  MOV DS_Reg, DS };\r
113 \r
114         pxTopOfStack--;\r
115         *pxTopOfStack = DS_Reg; /* DS */\r
116 \r
117         pxTopOfStack--;\r
118         *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */\r
119 \r
120         /* The AX register is pushed again twice - don't know why. */\r
121         pxTopOfStack--;\r
122         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
123         pxTopOfStack--;\r
124         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
125 \r
126 \r
127         #ifdef DEBUG_BUILD\r
128                 /* The compiler adds space to each ISR stack if building to\r
129                 include debug information.  Presumably this is used by the\r
130                 debugger - we don't need to initialise it to anything just\r
131                 make sure it is there. */\r
132                 pxTopOfStack--;\r
133         #endif\r
134 \r
135         /*lint +e950 +e611 +e923 */\r
136 \r
137         return pxTopOfStack;\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 \r