1 /* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved.
3 * Description : Task Low Level Impelmentations Headfile
4 * Author: Huawei LiteOS Team
5 * Create : 2022-12-20
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without specific prior written
15 * permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ---------------------------------------------------------------------------- */
28
29 #ifndef _ARCH_TASK_H
30 #define _ARCH_TASK_H
31
32 #include "los_typedef.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37
38 extern VOID *g_newTask;
39 #define LOSCFG_STACK_POINT_ALIGN_SIZE 16 /* must be 16 bytes aligned when compile -mpush-pop is on */
40 #define TP_INIT_VALUE 0x02020202L
41 #define SP_INIT_VALUE 0x03030303L
42 #define S11_INIT_VALUE 0x04040404L
43 #define S10_INIT_VALUE 0x05050505L
44 #define S9_INIT_VALUE 0x06060606L
45 #define S8_INIT_VALUE 0x07070707L
46 #define S7_INIT_VALUE 0x08080808L
47 #define S6_INIT_VALUE 0x09090909L
48 #define S5_INIT_VALUE 0x0a0a0a0aL
49 #define S4_INIT_VALUE 0x0b0b0b0bL
50 #define S3_INIT_VALUE 0x0c0c0c0cL
51 #define S2_INIT_VALUE 0x0d0d0d0dL
52 #define S1_INIT_VALUE 0x0e0e0e0eL
53 #define FP_INIT_VALUE 0x0f0f0f0fL
54 #define T6_INIT_VALUE 0x10101010L
55 #define T5_INIT_VALUE 0x11111111L
56 #define T4_INIT_VALUE 0x12121212L
57 #define T3_INIT_VALUE 0x13131313L
58 #define A7_INIT_VALUE 0x14141414L
59 #define A6_INIT_VALUE 0x15151515L
60 #define A5_INIT_VALUE 0x16161616L
61 #define A4_INIT_VALUE 0x17171717L
62 #define A3_INIT_VALUE 0x18181818L
63 #define A2_INIT_VALUE 0x19191919L
64 #define A1_INIT_VALUE 0x1a1a1a1aL
65 #define T2_INIT_VALUE 0x1c1c1c1cL
66 #define T1_INIT_VALUE 0x1d1d1d1dL
67 #define T0_INIT_VALUE 0x1e1e1e1eL
68
69 #ifdef LOSCFG_ARCH_FPU_DOUBLE
70 typedef UINT64 FLOATREG_TYPE;
71 #else
72 typedef UINT32 FLOATREG_TYPE;
73 #endif
74
75 /* Define the type of a task context control block. */
76 typedef struct {
77 UINT32 mstatus;
78 UINT32 mepc;
79 UINT32 tp; /* X4 */
80 UINT32 sp; /* X2 */
81
82 UINT32 s11; /* X27 */
83 UINT32 s10; /* X26 */
84 UINT32 s9; /* X25 */
85 UINT32 s8; /* X24 */
86 UINT32 s7; /* X23 */
87 UINT32 s6; /* X22 */
88 UINT32 s5; /* X21 */
89 UINT32 s4; /* X20 */
90 UINT32 s3; /* X19 */
91 UINT32 s2; /* X18 */
92
93 UINT32 s1; /* X9 */
94 UINT32 s0; /* X8 */
95
96 UINT32 t6; /* X31 */
97 UINT32 t5; /* X30 */
98 UINT32 t4; /* X29 */
99 UINT32 t3; /* X28 */
100
101 UINT32 a7; /* X17 */
102 UINT32 a6; /* X16 */
103 UINT32 a5; /* X15 */
104 UINT32 a4; /* X14 */
105 UINT32 a3; /* X13 */
106 UINT32 a2; /* X12 */
107 UINT32 a1; /* X11 */
108 UINT32 a0; /* X10 */
109
110 UINT32 t2; /* X7 */
111 UINT32 t1; /* X6 */
112 UINT32 t0; /* X5 */
113
114 UINT32 ra; /* X1 */
115
116 #ifdef LOSCFG_ARCH_FPU_ENABLE
117 FLOATREG_TYPE fs11; /* F27 */
118 FLOATREG_TYPE fs10; /* F26 */
119 FLOATREG_TYPE fs9; /* F25 */
120 FLOATREG_TYPE fs8; /* F24 */
121 FLOATREG_TYPE fs7; /* F23 */
122 FLOATREG_TYPE fs6; /* F22 */
123 FLOATREG_TYPE fs5; /* F21 */
124 FLOATREG_TYPE fs4; /* F20 */
125 FLOATREG_TYPE fs3; /* F19 */
126 FLOATREG_TYPE fs2; /* F18 */
127 FLOATREG_TYPE fs1; /* F9 */
128 FLOATREG_TYPE fs0; /* F8 */
129
130 FLOATREG_TYPE ft11; /* F31 */
131 FLOATREG_TYPE ft10; /* F30 */
132 FLOATREG_TYPE ft9; /* F29 */
133 FLOATREG_TYPE ft8; /* F28 */
134 FLOATREG_TYPE fa7; /* F17 */
135 FLOATREG_TYPE fa6; /* F16 */
136 FLOATREG_TYPE fa5; /* F15 */
137 FLOATREG_TYPE fa4; /* F14 */
138 FLOATREG_TYPE fa3; /* F13 */
139 FLOATREG_TYPE fa2; /* F12 */
140 FLOATREG_TYPE fa1; /* F11 */
141 FLOATREG_TYPE fa0; /* F10 */
142 FLOATREG_TYPE ft7; /* F7 */
143 FLOATREG_TYPE ft6; /* F6 */
144 FLOATREG_TYPE ft5; /* F5 */
145 FLOATREG_TYPE ft4; /* F4 */
146 FLOATREG_TYPE ft3; /* F3 */
147 FLOATREG_TYPE ft2; /* F2 */
148 FLOATREG_TYPE ft1; /* F1 */
149 FLOATREG_TYPE ft0; /* F0 */
150
151 UINT32 fcsr; /* FCSR */
152 UINT32 reserved[3]; /* 3: aligned 16 bytes */
153 #endif
154 } TaskContext;
155
ArchCurrTaskGet(VOID)156 STATIC INLINE VOID *ArchCurrTaskGet(VOID)
157 {
158 return g_newTask;
159 }
160
ArchCurrTaskSet(VOID * val)161 STATIC INLINE VOID ArchCurrTaskSet(VOID *val)
162 {
163 g_newTask = val;
164 }
165
ArchGetTaskFp(const VOID * stackPointer)166 STATIC INLINE UINTPTR ArchGetTaskFp(const VOID *stackPointer)
167 {
168 return ((TaskContext *)(stackPointer))->s0; /* s0: FP */
169 }
170
ArchGetTaskRa(const VOID * stackPointer)171 STATIC INLINE UINTPTR ArchGetTaskRa(const VOID *stackPointer)
172 {
173 return ((TaskContext *)(stackPointer))->ra; /* s0: FP */
174 }
175
176 extern VOID *ArchTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack);
177
178 #ifdef __cplusplus
179 }
180 #endif /* __cplusplus */
181
182 #endif
183