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

Last change on this file was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

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