]> git.sur5r.net Git - freertos/blob - Source/portable/oWatcom/16BitDOS/common/portcomn.c
b78d9215950ad24f05f078818a1aa0ae441d5bf3
[freertos] / Source / portable / oWatcom / 16BitDOS / common / portcomn.c
1 /*\r
2     FreeRTOS V6.0.4 - Copyright (C) 2010 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public \r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it \r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55 Changes from V1.00:\r
56         \r
57         + pxPortInitialiseStack() now initialises the stack of new tasks to the \r
58           same format used by the compiler.  This allows the compiler generated\r
59           interrupt mechanism to be used for context switches.\r
60 \r
61 Changes from V2.4.2:\r
62 \r
63         + pvPortMalloc and vPortFree have been removed.  The projects now use\r
64           the definitions from the source/portable/MemMang directory.\r
65 \r
66 Changes from V2.6.1:\r
67 \r
68         + usPortCheckFreeStackSpace() has been moved to tasks.c.\r
69 */\r
70 \r
71         \r
72 \r
73 #include <stdlib.h>\r
74 #include "FreeRTOS.h"\r
75 \r
76 /*-----------------------------------------------------------*/\r
77 \r
78 /* See header file for description. */\r
79 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
80 {\r
81 portSTACK_TYPE DS_Reg = 0, *pxOriginalSP;\r
82 \r
83         /* Place a few bytes of known values on the bottom of the stack. \r
84         This is just useful for debugging. */\r
85 \r
86         *pxTopOfStack = 0x1111;\r
87         pxTopOfStack--;\r
88         *pxTopOfStack = 0x2222;\r
89         pxTopOfStack--;\r
90         *pxTopOfStack = 0x3333;\r
91         pxTopOfStack--;\r
92         *pxTopOfStack = 0x4444;\r
93         pxTopOfStack--;\r
94         *pxTopOfStack = 0x5555;\r
95         pxTopOfStack--;\r
96 \r
97 \r
98         /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */\r
99 \r
100         /* We are going to start the scheduler using a return from interrupt\r
101         instruction to load the program counter, so first there would be the\r
102         status register and interrupt return address.  We make this the start \r
103         of the task. */\r
104         *pxTopOfStack = portINITIAL_SW; \r
105         pxTopOfStack--;\r
106         *pxTopOfStack = FP_SEG( pxCode );\r
107         pxTopOfStack--;\r
108         *pxTopOfStack = FP_OFF( pxCode );\r
109         pxTopOfStack--;\r
110 \r
111         /* We are going to setup the stack for the new task to look like\r
112         the stack frame was setup by a compiler generated ISR.  We need to know\r
113         the address of the existing stack top to place in the SP register within\r
114         the stack frame.  pxOriginalSP holds SP before (simulated) pusha was \r
115         called. */\r
116         pxOriginalSP = pxTopOfStack;\r
117 \r
118         /* The remaining registers would be pushed on the stack by our context \r
119         switch function.  These are loaded with values simply to make debugging\r
120         easier. */\r
121         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;      /* CX */\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = FP_SEG( pvParameters );         /* DX */\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BX */\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = FP_OFF( pxOriginalSP );         /* SP */\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;      /* BP */\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( portSTACK_TYPE ) 0x0123;      /* SI */\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;      /* DI */\r
136 \r
137         /* We need the true data segment. */\r
138         __asm{  MOV DS_Reg, DS };\r
139 \r
140         pxTopOfStack--;\r
141         *pxTopOfStack = DS_Reg; /* DS */\r
142 \r
143         pxTopOfStack--;\r
144         *pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;      /* ES */\r
145 \r
146         /* The AX register is pushed again twice - don't know why. */\r
147         pxTopOfStack--;\r
148         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
149         pxTopOfStack--;\r
150         *pxTopOfStack = FP_OFF( pvParameters );         /* AX */\r
151 \r
152 \r
153         #ifdef DEBUG_BUILD\r
154                 /* The compiler adds space to each ISR stack if building to\r
155                 include debug information.  Presumably this is used by the\r
156                 debugger - we don't need to initialise it to anything just\r
157                 make sure it is there. */\r
158                 pxTopOfStack--;\r
159         #endif\r
160 \r
161         /*lint +e950 +e611 +e923 */\r
162 \r
163         return pxTopOfStack;\r
164 }\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 \r