1 | /* |
---|
2 | * hal_kernel_types.h - kernel types for TSAR-MIPS32 architecture. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef HAL_KERNEL_TYPES_H_ |
---|
25 | #define HAL_KERNEL_TYPES_H_ |
---|
26 | |
---|
27 | #include <kernel_config.h> |
---|
28 | |
---|
29 | #ifndef NULL |
---|
30 | #define NULL (void*)0 |
---|
31 | #endif |
---|
32 | |
---|
33 | /************************************************************************** |
---|
34 | * This file defines both the hardware dependant and hardware independant |
---|
35 | * data types used by the kernel for the TSAR-MIPS32 architecture. |
---|
36 | **************************************************************************/ |
---|
37 | |
---|
38 | /************************************************************************** |
---|
39 | * This defines the .elf files format (used in kernel/libk/elf.h file). |
---|
40 | **************************************************************************/ |
---|
41 | |
---|
42 | #define HAL_ELF_32_BITS |
---|
43 | |
---|
44 | /************************************************************************** |
---|
45 | * Exact-width integer types. |
---|
46 | **************************************************************************/ |
---|
47 | |
---|
48 | typedef signed char int8_t; |
---|
49 | typedef unsigned char uint8_t; |
---|
50 | |
---|
51 | typedef signed short int16_t; |
---|
52 | typedef unsigned short uint16_t; |
---|
53 | |
---|
54 | typedef signed long int int32_t; |
---|
55 | typedef unsigned long int uint32_t; |
---|
56 | |
---|
57 | typedef signed long long int int64_t; |
---|
58 | typedef unsigned long long int uint64_t; |
---|
59 | |
---|
60 | /*************************************************************************** |
---|
61 | * Boolean type and macros |
---|
62 | **************************************************************************/ |
---|
63 | |
---|
64 | typedef uint32_t bool_t; |
---|
65 | |
---|
66 | #define false 0 |
---|
67 | #define true 1 |
---|
68 | |
---|
69 | /*************************************************************************** |
---|
70 | * Kernel error type : signed |
---|
71 | **************************************************************************/ |
---|
72 | |
---|
73 | typedef int32_t error_t; |
---|
74 | |
---|
75 | /*************************************************************************** |
---|
76 | * Time related type |
---|
77 | **************************************************************************/ |
---|
78 | |
---|
79 | typedef uint64_t cycle_t; // for software cycle counters |
---|
80 | |
---|
81 | /*************************************************************************** |
---|
82 | * Global Process identifier type / fixed format |
---|
83 | * 16 MSB = cluster XY identifier |
---|
84 | * 16 LSB = local process index |
---|
85 | **************************************************************************/ |
---|
86 | |
---|
87 | typedef uint32_t pid_t; |
---|
88 | |
---|
89 | /*************************************************************************** |
---|
90 | * Local Process index |
---|
91 | **************************************************************************/ |
---|
92 | |
---|
93 | typedef uint16_t lpid_t; |
---|
94 | |
---|
95 | /*************************************************************************** |
---|
96 | * Thread identifier type / fixed format |
---|
97 | * 16 MSB = cluster XY identifier |
---|
98 | * 16 LSB = local thread index |
---|
99 | **************************************************************************/ |
---|
100 | |
---|
101 | typedef uint32_t trdid_t; |
---|
102 | |
---|
103 | /*************************************************************************** |
---|
104 | * Local Thread index |
---|
105 | **************************************************************************/ |
---|
106 | |
---|
107 | typedef uint16_t ltid_t; |
---|
108 | |
---|
109 | /*************************************************************************** |
---|
110 | * User identifier type |
---|
111 | **************************************************************************/ |
---|
112 | |
---|
113 | typedef uint32_t uid_t; |
---|
114 | |
---|
115 | /*************************************************************************** |
---|
116 | * CPU identifier types |
---|
117 | **************************************************************************/ |
---|
118 | |
---|
119 | typedef uint16_t lid_t; // local index in cluster |
---|
120 | typedef uint32_t gid_t; // global (hardware) identifier |
---|
121 | |
---|
122 | /*************************************************************************** |
---|
123 | * File Descriptor Index in File Descriptor Array |
---|
124 | **************************************************************************/ |
---|
125 | |
---|
126 | typedef uint32_t fdid_t; |
---|
127 | |
---|
128 | /*************************************************************************** |
---|
129 | * This structure defines a single 32 bits integer alone in a cache line. |
---|
130 | **************************************************************************/ |
---|
131 | |
---|
132 | typedef struct cache_line_s |
---|
133 | { |
---|
134 | union |
---|
135 | { |
---|
136 | uint32_t values[CONFIG_CACHE_LINE_SIZE>>2]; |
---|
137 | uint32_t value; |
---|
138 | }; |
---|
139 | } |
---|
140 | __attribute__((packed)) cacheline_t; |
---|
141 | |
---|
142 | /*************************************************************************** |
---|
143 | * Address types and macros !!! hardware dependant !!! |
---|
144 | *************************************************************************** |
---|
145 | * An extended pointer is a 64 bits integer, structured in two fields : |
---|
146 | * - cxy : cluster identifier. |
---|
147 | * - ptr : pointer in the virtual space of a single cluster. |
---|
148 | * |
---|
149 | * In TSAR (MIPS32), the kernel virtual space has 4 Gbytes per cluster |
---|
150 | * - the cxy field occupies bits[47:32] |
---|
151 | * - the ptr field occupies bits[31:0] |
---|
152 | *************************************************************************** |
---|
153 | * A physical address is a 64 bits integer, structured in two fields : |
---|
154 | * - cxy : cluster identifier. |
---|
155 | * - lpa : local physical address inside cluster. |
---|
156 | * |
---|
157 | * In TSAR (MIPS32), the physical space has 4Gbytes per cluster. |
---|
158 | * - the cxy field occupies bits[39:32] |
---|
159 | * - the lpa field occupies bits[31:0] |
---|
160 | **************************************************************************/ |
---|
161 | |
---|
162 | typedef uint64_t xptr_t; // extended pointer |
---|
163 | |
---|
164 | typedef uint16_t cxy_t; // cluster identifier |
---|
165 | |
---|
166 | typedef uint64_t paddr_t; // global physical address |
---|
167 | |
---|
168 | typedef uint32_t lpa_t; // local physical address |
---|
169 | |
---|
170 | typedef uint32_t intptr_t; // local pointer stored as integer |
---|
171 | |
---|
172 | typedef uint32_t ppn_t; // Physical Page Number |
---|
173 | |
---|
174 | typedef uint32_t vpn_t; // Virtual Page number |
---|
175 | |
---|
176 | |
---|
177 | #define XPTR_NULL 0 |
---|
178 | |
---|
179 | #define PTR_MASK 0x00000000FFFFFFFFULL |
---|
180 | |
---|
181 | #define PTR_SHIFT 32 |
---|
182 | |
---|
183 | #define GET_CXY(xp) ((cxy_t)((xp) >> PTR_SHIFT)) |
---|
184 | |
---|
185 | #define GET_PTR(xp) ((void*)(uint32_t)((xp) & PTR_MASK)) |
---|
186 | |
---|
187 | #define XPTR(cxy,ptr) (((uint64_t)(cxy) << PTR_SHIFT) | (((uint32_t)(ptr)) & PTR_MASK)) |
---|
188 | |
---|
189 | |
---|
190 | #define LPA_MASK 0x00000000FFFFFFFFULL |
---|
191 | |
---|
192 | #define LPA_SHIFT 32 |
---|
193 | |
---|
194 | #define CXY_FROM_PADDR(paddr) ((cxy_t)((paddr) >> LPA_SHIFT)) |
---|
195 | |
---|
196 | #define LPA_FROM_PADDR(paddr) (lpa_t)(paddr & LPA_MASK) |
---|
197 | |
---|
198 | #define PADDR(cxy,lpa) (((uint64_t)(cxy) << LPA_SHIFT) | (((uint64_t)(lpa)) & LPA_MASK)) |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | #endif /* HAL_KERNEL_TYPES_H_ */ |
---|