1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* -------------------------------------------
Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
------------------------------------------- */
#pragma once
#include <NeKit/Macros.h>
#define NEKIT_VERSION_STR "0.0.1"
#define NEKIT_VERSION_BCD 0x0001
#ifndef __cplusplus
#error !!! Kernel compiles only with a C++ compiler. !!!
#endif
#if __cplusplus <= 201703L
#define char8_t char
#endif
#ifdef __has_feature
#if !__has_feature(cxx_nullptr)
#if !__has_nullptr
#error !!! You must at least have nullptr featured on your C++ compiler. !!!
#endif
#endif
#endif
/// @brief The **Kernel** namespace.
namespace Kernel {
using voidPtr = void*;
using VoidPtr = void*;
using nullPtr = decltype(nullptr);
using NullPtr = decltype(nullptr);
using Int = int;
using Int32 = __INT32_TYPE__;
using UShort = __UINT16_TYPE__;
using UInt16 = __UINT16_TYPE__;
using Short = short;
using Int16 = __INT16_TYPE__;
using UInt = __UINT32_TYPE__;
using UInt32 = __UINT32_TYPE__;
using Long = __INT64_TYPE__;
using Int64 = __INT64_TYPE__;
using ULong = __UINT64_TYPE__;
using UInt64 = __UINT64_TYPE__;
using Boolean = bool;
using Bool = bool;
using Char = char;
using Int8 = __INT8_TYPE__;
using Char8 = char8_t;
using UChar = __UINT8_TYPE__;
using UInt8 = __UINT8_TYPE__;
using SSize = long;
using SSizeT = long;
using Size = __SIZE_TYPE__;
using SizeT = __SIZE_TYPE__;
using IntPtr = __INTPTR_TYPE__;
using UIntPtr = __UINTPTR_TYPE__;
using IntFast = __INT_FAST32_TYPE__;
using IntFast64 = __INT_FAST64_TYPE__;
using PtrDiff = __PTRDIFF_TYPE__;
using SInt16 = Int16;
using SInt32 = Int32;
using SInt64 = Int64;
typedef UIntPtr* Ptr64;
typedef UInt32* Ptr32;
typedef UInt8* Ptr8;
using Utf8Char = char8_t;
using Utf16Char = char16_t;
using WideChar = wchar_t;
using Utf32Char = char32_t;
using LongDouble = long double;
using Double = double;
using Float = float;
typedef UInt32 PhysicalAddressKind;
typedef UIntPtr VirtualAddressKind;
using Void = void;
using Any = void*;
using Lba = UInt64;
using Char16 = char16_t;
enum class Endian : UInt8 { kEndianInvalid, kEndianBig, kEndianLittle, kEndianMixed, kEndianCount };
/// @brief Forward object.
/// @tparam Args the object type.
/// @param arg the object.
/// @return object's rvalue
template <typename Args>
inline Args&& forward(Args& arg) {
return static_cast<Args&&>(arg);
}
/// @brief Move object.
/// @tparam Args the object type.
/// @param arg the object.
/// @return object's rvalue
template <typename Args>
inline Args&& move(Args&& arg) {
return static_cast<Args&&>(arg);
}
/// @brief Encoding interface, used as a proxy to convert T to Char*
/// Used to cast A to B or B to A.
class ICodec {
public:
explicit ICodec() = default;
virtual ~ICodec() = default;
ICodec& operator=(const ICodec&) = default;
ICodec(const ICodec&) = default;
public:
/// @brief Convert type to bytes.
/// @tparam T the type.
/// @param type (a1) the data.
/// @return a1 as Char*
template <typename T>
const Char* AsBytes(T type) noexcept {
NE_UNUSED(type);
return nullptr;
}
/// @brief Construct from type to class.
/// @tparam T the type to convert.
/// @param type (a1) the data.
/// @return a1 as Char*
template <typename OutputClass, typename FactoryClass>
OutputClass* Construct(Char* type) noexcept {
FactoryClass class_fac;
return class_fac.template From<OutputClass>(type);
}
/// @brief Convert T class to Y class.
/// @tparam T the class type of type.
/// @tparam Y the result class.
/// @param type the class to cast.
/// @return the class as Y.
template <typename T, typename Y>
Y As(T type) noexcept {
if (type.template IsSerializable()) {
return reinterpret_cast<Char*>(type);
}
return type.template As<Y>();
}
};
/// \brief Scheduler interface, represents a scheduler object.
/// @note This is used to schedule tasks, such as threads, drivers, user threads, etc.
class ISchedulable {
public:
explicit ISchedulable() = default;
virtual ~ISchedulable() = default;
ISchedulable& operator=(const ISchedulable&) = default;
ISchedulable(const ISchedulable&) = default;
/// @brief Is this object only accepting user tasks?
virtual Bool IsUser() { return NO; }
/// @brief Is this object only accepting kernel tasks?
virtual Bool IsKernel() { return NO; }
/// @brief Is this object offloading to another CPU?
virtual Bool HasMP() { return NO; }
};
} // namespace Kernel
|