source: trunk/hal/x86_64/core/hal_types.h @ 113

Last change on this file since 113 was 73, checked in by max@…, 7 years ago

now that the fields are stable, embed the VA base in XPTR

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