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 | |
13 | typedef signed char s8; |
14 | typedef signed short s16; |
15 | typedef signed int s32; |
16 | typedef signed long slong; |
17 | typedef signed long long int s64; |
18 | |
19 | typedef unsigned char u8; |
20 | typedef unsigned short u16; |
21 | typedef unsigned int u32; |
22 | typedef unsigned long ulong; |
23 | typedef unsigned long long u64; |
24 | |
25 | typedef unsigned long ptr_t; |
26 | typedef unsigned int ptr32_t; |
27 | typedef unsigned long long ptr64_t; |
28 | |
29 | typedef signed long intn; |
30 | typedef 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 |
41 | typedef 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 | |
48 | MOS_STATIC_ASSERT(sizeof(void *) == 8, "pointer size check failed" ); |
49 | MOS_STATIC_ASSERT(sizeof(ptr_t) == sizeof(void *), "ptr_t is not the same size as void *" ); |
50 | |
51 | typedef uintn reg_t; // native register type |
52 | typedef u16 reg16_t; // 16-bit |
53 | typedef u32 reg32_t; // 32-bit |
54 | typedef u64 reg64_t; // 64-bit |
55 | |
56 | typedef 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; |
69 | u8 byte; |
70 | } byte_t; |
71 | |
72 | MOS_STATIC_ASSERT(sizeof(byte_t) == 1, "byte_t is not 1 byte" ); |
73 | |
74 | typedef u32 id_t; |
75 | typedef u32 uid_t; |
76 | typedef u32 gid_t; |
77 | |
78 | typedef s32 pid_t; |
79 | typedef s32 tid_t; |
80 | |
81 | typedef s32 fd_t; |
82 | |
83 | typedef signed long ssize_t; |
84 | typedef ssize_t off_t; |
85 | |
86 | typedef 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 | |
97 | new_opaque_type(size_t, hash); |
98 | |
99 | typedef s32 futex_word_t; |
100 | |
101 | #ifndef __cplusplus |
102 | #define __atomic(type) _Atomic(type) |
103 | typedef __atomic(size_t) atomic_t; |
104 | #else |
105 | // for C++, we need to use the atomic type directly |
106 | typedef std::atomic<size_t> atomic_t; |
107 | #endif |
108 | |
109 | typedef void (*thread_entry_t)(void *arg); |
110 | |