NeKernel dev
Loading...
Searching...
No Matches
Macros.h
Go to the documentation of this file.
1/* -------------------------------------------
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
4
5------------------------------------------- */
6
7#pragma once
8
9/***********************************************************************************/
12/***********************************************************************************/
13
14#ifndef KIB
15#define KIB(X) (Kernel::UInt64)((X) / 1024)
16#endif
17
18#ifndef kib_cast
19#define kib_cast(X) (Kernel::UInt64)((X) *1024)
20#endif
21
22#ifndef MIB
23#define MIB(X) (Kernel::UInt64)((Kernel::UInt64) KIB(X) / 1024)
24#endif
25
26#ifndef mib_cast
27#define mib_cast(X) (Kernel::UInt64)((Kernel::UInt64) kib_cast(X) * 1024)
28#endif
29
30#ifndef GIB
31#define GIB(X) (Kernel::UInt64)((Kernel::UInt64) MIB(X) / 1024)
32#endif
33
34#ifndef gib_cast
35#define gib_cast(X) (Kernel::UInt64)((Kernel::UInt64) mib_cast(X) * 1024)
36#endif
37
38#ifndef TIB
39#define TIB(X) (Kernel::UInt64)((Kernel::UInt64) GIB(X) / 1024)
40#endif
41
42#ifndef tib_cast
43#define tib_cast(X) ((Kernel::UInt64) gib_cast(X) * 1024)
44#endif
45
46#ifndef ARRAY_SIZE
47#define ARRAY_SIZE(a) \
48 (((sizeof(a) / sizeof(*(a))) / (static_cast<Kernel::Size>(!(sizeof(a) % sizeof(*(a)))))))
49#endif
50
51#define DEPRECATED ATTRIBUTE(deprecated)
52
53#ifndef ALIGN
54#define ALIGN(X) __attribute__((aligned(X)))
55#endif // #ifndef ALIGN
56
57#ifndef ATTRIBUTE
58#define ATTRIBUTE(...) __attribute__((__VA_ARGS__))
59#endif // #ifndef ATTRIBUTE
60
61#ifndef __NE_VER__
62#define __NE_VER__ (2024)
63#endif // !__NE_VER__
64
65#ifndef EXTERN
66#define EXTERN extern
67#endif
68
69#ifndef EXTERN_C
70#define EXTERN_C extern "C"
71#endif
72
73#ifndef MAKE_ENUM
74#define MAKE_ENUM(NAME) enum NAME {
75#endif
76
77#ifndef END_ENUM
78#define END_ENUM() \
79 } \
80 ;
81#endif
82
83#ifndef MAKE_STRING_ENUM
84#define MAKE_STRING_ENUM(NAME) namespace NAME {
85#endif
86
87#ifndef ENUM_STRING
88#define ENUM_STRING(NAME, VAL) inline constexpr const char* e##NAME = VAL
89#endif
90
91#ifndef END_STRING_ENUM
92#define END_STRING_ENUM() }
93#endif
94
95#ifndef RTL_ALLOCA
96#define RTL_ALLOCA(sz) __builtin_alloca(sz)
97#endif // #ifndef RTL_ALLOCA
98
99#ifndef CANT_REACH
100#define CANT_REACH() __builtin_unreachable()
101#endif
102
103#define kInvalidAddress 0xFBFBFBFBFBFBFBFB
104#define kBadAddress 0x0000000000000000
105#define kMaxAddr 0xFFFFFFFFFFFFFFFF
106#define kPathLen 0x100
107
108#define PACKED ATTRIBUTE(packed)
109#define NO_EXEC ATTRIBUTE(noexec)
110
111#define EXTERN extern
112#define STATIC static
113
114#define CONST const
115
116#define STRINGIFY(X) #X
117#define NE_UNUSED(X) ((Kernel::Void) X)
118
119#ifndef RGB
120#define RGB(R, G, B) ((Kernel::UInt32)((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B)))
121#endif // !RGB
122
123#ifdef __NE_AMD64__
124#define DBG_TRAP() asm volatile("int $3")
125#else
126#define DBG_TRAP() ((Kernel::Void) 0)
127#endif
128
129#define LIKELY(ARG) ((ARG) ? MUST_PASS(NO) : ((Kernel::Void) 0))
130#define UNLIKELY(ARG) LIKELY(!(ARG))
131
132#define RTL_ENDIAN(address, value) \
133 (((reinterpret_cast<Kernel::Char*>(address)[0]) == (value)) ? (Kernel::Endian::kEndianBig) \
134 : (Kernel::Endian::kEndianLittle))
135
136#define Yes true
137#define No false
138
139#define YES true
140#define NO false
141
142#define TRUE true
143#define FALSE false
144
145#define BOOL Kernel::Boolean
146
147#ifdef RTL_INIT_OBJECT
148#undef RTL_INIT_OBJECT
149#endif // ifdef RTL_INIT_OBJECT
150
151#define RTL_INIT_OBJECT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__)