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;
69 u8 byte;
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
99typedef s32 futex_word_t;
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);
110