source: trunk/hal/i386/hal_types.h @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 7.0 KB
Line 
1/*
2 * hal_types.h - common kernel types for I86 64 bits
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_TYPES_H_
25#define HAL_TYPES_H_
26
27#include <almos_config.h>
28#include <stdint.h>
29
30#ifndef NULL
31#define NULL (void*)        0
32#endif
33
34/**************************************************************************
35 *                      Exact-width integer types. 
36 **************************************************************************/
37
38typedef   signed           char     int8_t;
39typedef unsigned           char    uint8_t;
40
41typedef   signed           int      int16_t;
42typedef unsigned           int     uint16_t;
43
44typedef   signed long      int      int32_t;
45typedef unsigned long      int     uint32_t;
46
47typedef   signed long long int      int64_t;
48typedef unsigned long long int     uint64_t;
49
50/***************************************************************************
51 * Pthread related types
52 **************************************************************************/
53
54typedef uint32_t      pthread_t;
55typedef uint32_t      pthread_mutexattr_t;
56typedef uint32_t      pthread_barrier_t;
57typedef uint32_t      pthread_barrierattr_t;
58typedef uint32_t      sem_t;
59typedef uint32_t      pthread_cond_t;
60typedef uint32_t      pthread_condattr_t;
61typedef uint32_t      pthread_rwlock_t;
62typedef uint32_t      pthread_rwlockattr_t;
63typedef uint32_t      pthread_key_t;
64
65/***************************************************************************
66 * Boolean type and macros
67 **************************************************************************/
68
69typedef uint32_t      bool_t;
70
71#define false         0
72#define true          1
73
74/***************************************************************************
75 * Kernel error type : signed
76 **************************************************************************/
77
78typedef int32_t       error_t;
79
80/***************************************************************************
81 * Time related types
82 **************************************************************************/
83
84typedef uint64_t      clock_t;
85
86/***************************************************************************
87 * Processus identifier type / fixed format
88 * 16 MSB bits = cluster XY coordinates
89 * 16 LSB bits = local process identifier
90 **************************************************************************/
91
92typedef uint32_t      pid_t;   
93
94/***************************************************************************
95 * Local Process index 
96 **************************************************************************/
97
98typedef uint16_t      lpid_t;
99
100/***************************************************************************
101 * Thread  identifier type / fixed format
102 * 16 MSB = cluster XY identifier
103 * 16 LSB = local thread index
104 **************************************************************************/
105
106typedef uint32_t      trdid_t;
107
108/***************************************************************************
109 * Local Thread index   
110 **************************************************************************/
111
112typedef uint16_t      ltid_t;
113
114/***************************************************************************
115 * User identifier type
116 **************************************************************************/
117
118typedef uint32_t      uid_t;
119
120/***************************************************************************
121 * CPU identifier types
122 **************************************************************************/
123
124typedef uint32_t      lid_t;     // local index in cluster
125typedef uint32_t      gid_t;     // global identifier
126
127/***************************************************************************
128 * File Descriptor Index in File Descriptor Array
129 **************************************************************************/
130
131typedef uint32_t      fdid_t;
132
133/***************************************************************************
134 * This structure defines a single 32 bits integer alone in a cache line.
135 **************************************************************************/
136
137typedef struct cache_line_s
138{
139  union
140  {
141    uint32_t values[CONFIG_CACHE_LINE_LENGTH];
142    uint32_t value;
143  };
144}
145__attribute__((packed)) cacheline_t;
146
147#define CACHELINE_ALIGNED __attribute__((aligned(CONFIG_CACHE_LINE_SIZE)))
148
149/***************************************************************************
150 *  Address types and macros        !!! hardware dependant !!!
151 ***************************************************************************
152 * An extended pointer is a 64 bits integer, structured in two fields :
153 * - cxy : cluster identifier.
154 * - ptr : pointer in the virtual space of a single cluster.
155 *
156 * In Intel 64 bits, the kernel virtual space has 256 Tbytes per cluster
157 * - the cxy field occupies bits[63:48]
158 * - the ptr field occupies bits[47:0]
159 ***************************************************************************
160 * A physical address is a 64 bits integer, structured in two fields :
161 * - cxy : cluster identifier.
162 * - lpa : local physical address inside cluster.
163 *
164 * In INTEL 64 bits, the physical space has 256 Gbytes per cluster.
165 * - the cxy field occupies bits[63:48]
166 * - the lpa field occupies bits[47:0]
167 **************************************************************************/
168
169typedef uint64_t               reg_t;         // core register
170
171typedef uint64_t               xptr_t;         // extended pointer
172
173typedef uint16_t               cxy_t;          // cluster identifier
174
175typedef uint64_t               paddr_t;        // global physical address (64 bits)
176
177typedef uint64_t               lpa_t;          // local physical address
178
179typedef uint64_t               intptr_t;       // local pointer stored as integer
180
181typedef uint64_t               ppn_t;          // Physical Page Number
182
183typedef uint64_t               vpn_t;          // Virtual Page number
184
185#define XPTR_NULL              0
186
187#define PTR_MASK               ((1ULL)<<47)
188
189#define GET_CXY(xp)            ((cxy_t)((xp) >> 48))
190
191#define GET_PTR(xp)            ((void*)((xp) & PTR_MASK))
192
193#define XPTR(cxy,ptr)          (((uint64_t)(cxy) << 48) | (((uint64_t)(ptr)) & PTR_MASK))
194
195#define LPA_MASK               ((1ULL)<<47)
196
197#define CXY_FROM_PADDR(paddr)  ((cxy_t)((paddr) >> 48))
198
199#define LPA_FROM_PADDR(paddr)  (lpa_t)((paddr & LPA_MASK)
200
201#define PADDR(cxy,lad)         (((uint64_t)(cxy) << 48) | (((uint64_t)(ptr)) & LPA_MASK))
202
203
204
205#endif  /* HAL_TYPES_H_ */
Note: See TracBrowser for help on using the repository browser.