]> begriffs open source - freertos/blob - portable/BCC/16BitDOS/common/portcomn.c
CI-CD Updates (#768)
[freertos] / portable / BCC / 16BitDOS / common / portcomn.c
1 /*
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * https://www.FreeRTOS.org
25  * https://github.com/FreeRTOS
26  *
27  */
28
29 /*
30  * Changes from V1.00:
31  *
32  + pxPortInitialiseStack() now initialises the stack of new tasks to the
33  +    same format used by the compiler.  This allows the compiler generated
34  +    interrupt mechanism to be used for context switches.
35  +
36  + Changes from V2.6.1
37  +
38  + Move usPortCheckFreeStackSpace() to tasks.c.
39  */
40
41
42 #include <dos.h>
43 #include <stdlib.h>
44 #include "FreeRTOS.h"
45
46 /*-----------------------------------------------------------*/
47
48 /* See header file for description. */
49 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
50                                      TaskFunction_t pxCode,
51                                      void * pvParameters )
52 {
53     StackType_t DS_Reg = 0;
54
55     /* Place a few bytes of known values on the bottom of the stack.
56      * This is just useful for debugging. */
57
58     *pxTopOfStack = 0x1111;
59     pxTopOfStack--;
60     *pxTopOfStack = 0x2222;
61     pxTopOfStack--;
62     *pxTopOfStack = 0x3333;
63     pxTopOfStack--;
64     *pxTopOfStack = 0x4444;
65     pxTopOfStack--;
66     *pxTopOfStack = 0x5555;
67     pxTopOfStack--;
68
69
70     /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */
71
72     /* We are going to start the scheduler using a return from interrupt
73      * instruction to load the program counter, so first there would be the
74      * function call with parameters preamble. */
75
76     *pxTopOfStack = FP_SEG( pvParameters );
77     pxTopOfStack--;
78     *pxTopOfStack = FP_OFF( pvParameters );
79     pxTopOfStack--;
80     *pxTopOfStack = FP_SEG( pxCode );
81     pxTopOfStack--;
82     *pxTopOfStack = FP_OFF( pxCode );
83     pxTopOfStack--;
84
85     /* Next the status register and interrupt return address. */
86     *pxTopOfStack = portINITIAL_SW;
87     pxTopOfStack--;
88     *pxTopOfStack = FP_SEG( pxCode );
89     pxTopOfStack--;
90     *pxTopOfStack = FP_OFF( pxCode );
91     pxTopOfStack--;
92
93     /* The remaining registers would be pushed on the stack by our context
94      * switch function.  These are loaded with values simply to make debugging
95      * easier. */
96     *pxTopOfStack = ( StackType_t ) 0xAAAA; /* AX */
97     pxTopOfStack--;
98     *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BX */
99     pxTopOfStack--;
100     *pxTopOfStack = ( StackType_t ) 0xCCCC; /* CX */
101     pxTopOfStack--;
102     *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DX */
103     pxTopOfStack--;
104     *pxTopOfStack = ( StackType_t ) 0xEEEE; /* ES */
105     pxTopOfStack--;
106
107     /* We need the true data segment. */
108     __asm {
109         MOV DS_Reg, DS
110     };
111
112     *pxTopOfStack = DS_Reg;                 /* DS */
113     pxTopOfStack--;
114     *pxTopOfStack = ( StackType_t ) 0x0123; /* SI */
115     pxTopOfStack--;
116     *pxTopOfStack = ( StackType_t ) 0xDDDD; /* DI */
117     pxTopOfStack--;
118     *pxTopOfStack = ( StackType_t ) 0xBBBB; /* BP */
119
120     /*lint +e950 +e611 +e923 */
121
122     return pxTopOfStack;
123 }
124 /*-----------------------------------------------------------*/