MOS Source Code
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/mos_global.h>
6#include <stdbool.h>
7#include <stddef.h>
8
9#ifdef __cplusplus
10#include <atomic>
11#endif
12
13typedef signed char s8;
14typedef signed short s16;
15typedef signed int s32;
16typedef signed long slong;
17typedef signed long long int s64;
18
19typedef unsigned char u8;
20typedef unsigned short u16;
21typedef unsigned int u32;
22typedef unsigned long ulong;
23typedef unsigned long long u64;
24
25typedef unsigned long ptr_t;
26typedef unsigned int ptr32_t;
27typedef unsigned long long ptr64_t;
28
29typedef signed long intn;
30typedef unsigned long uintn;
31
32// native integer type
33#define PTR_FMT "0x%16.16lx"
34#define PTR_VLFMT "0x%lx"
35
36#define PTR_RANGE "[" PTR_FMT " - " PTR_FMT "]"
37#define PTR_VLRANGE "[" PTR_VLFMT " - " PTR_VLFMT "]"
38#define PTR_RANGE64 "[0x%.16llx - 0x%.16llx]"
39
40// physical frame number
41typedef unsigned long long pfn_t;
42#define PFN_FMT "%llu"
43#define PFN_RANGE "[" PFN_FMT " - " PFN_FMT "]"
44#define PFNADDR_RANGE "[" PTR_FMT " - " PTR_FMT "] (PFN " PFN_FMT " - " PFN_FMT ")"
45
46#define PFNADDR(pfn, end) (((ptr_t) (pfn)) * MOS_PAGE_SIZE), ((((ptr_t) end) * MOS_PAGE_SIZE) - 1), (pfn), (end)
47
48MOS_STATIC_ASSERT(sizeof(void *) == 8, "pointer size check failed");
49MOS_STATIC_ASSERT(sizeof(ptr_t) == sizeof(void *), "ptr_t is not the same size as void *");
50
51typedef uintn reg_t; // native register type
52typedef u16 reg16_t; // 16-bit
53typedef u32 reg32_t; // 32-bit
54typedef u64 reg64_t; // 64-bit
55
56typedef union
57{
58 struct
59 {
60 bool b0 : 1;
61 bool b1 : 1;
62 bool b2 : 1;
63 bool b3 : 1;
64 bool b4 : 1;
65 bool b5 : 1;
66 bool b6 : 1;
67 bool msb : 1;
68 } __packed bits;
70} byte_t;
71
72MOS_STATIC_ASSERT(sizeof(byte_t) == 1, "byte_t is not 1 byte");
73
74typedef u32 id_t;
75typedef u32 uid_t;
76typedef u32 gid_t;
77
78typedef s32 pid_t;
79typedef s32 tid_t;
80
81typedef s32 fd_t;
82
83typedef signed long ssize_t;
84typedef ssize_t off_t;
85
86typedef long pte_content_t;
87
88#define new_named_opaque_type(base, name, type) \
89 typedef struct \
90 { \
91 base name; \
92 } type
93
94#define new_opaque_type(type, name) new_named_opaque_type(type, name, name##_t)
95#define new_opaque_ptr_type(name) new_named_opaque_type(ptr_t, ptr, name)
96
97new_opaque_type(size_t, hash);
98
100
101#ifndef __cplusplus
102#define __atomic(type) _Atomic(type)
103typedef __atomic(size_t) atomic_t;
104#else
105// for C++, we need to use the atomic type directly
106typedef std::atomic<size_t> atomic_t;
107#endif
108
109typedef void (*thread_entry_t)(void *arg);
MOSAPI void(1, 2) fatal_abort(const char *fmt
#define __packed
Definition mos_global.h:29
#define MOS_STATIC_ASSERT
Definition mos_global.h:14
uintn reg_t
Definition types.h:51
signed int s32
Definition types.h:15
unsigned int u32
Definition types.h:21
s32 futex_word_t
Definition types.h:99
signed char s8
Definition types.h:13
unsigned long long pfn_t
Definition types.h:41
ssize_t off_t
Definition types.h:84
void(* thread_entry_t)(void *arg)
Definition types.h:109
unsigned long uintn
Definition types.h:30
signed long intn
Definition types.h:29
u32 uid_t
Definition types.h:75
s32 fd_t
Definition types.h:81
signed long long int s64
Definition types.h:17
signed short s16
Definition types.h:14
u16 reg16_t
Definition types.h:52
unsigned long ulong
Definition types.h:22
s32 tid_t
Definition types.h:79
u32 gid_t
Definition types.h:76
u32 reg32_t
Definition types.h:53
s32 pid_t
Definition types.h:78
unsigned short u16
Definition types.h:20
#define new_opaque_type(type, name)
Definition types.h:94
#define __atomic(type)
Definition types.h:102
u64 reg64_t
Definition types.h:54
unsigned int ptr32_t
Definition types.h:26
unsigned long ptr_t
Definition types.h:25
long pte_content_t
Definition types.h:86
unsigned long long u64
Definition types.h:23
signed long slong
Definition types.h:16
unsigned long long ptr64_t
Definition types.h:27
signed long ssize_t
Definition types.h:83
unsigned char u8
Definition types.h:19
u32 id_t
Definition types.h:74
Definition types.h:57
bool b1
Definition types.h:61
bool msb
Definition types.h:67
bool b5
Definition types.h:65
bool b3
Definition types.h:63
bool b2
Definition types.h:62
bool b4
Definition types.h:64
u8 byte
Definition types.h:69
bool b0
Definition types.h:60
bool b6
Definition types.h:66