summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-24 19:57:10 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-24 19:57:10 +0200
commit8153dc983802115951836f2b164af371ee6e3d73 (patch)
treeb06f35ba0d21f6d336b5be7af2a36672ea19fc43
parentf7a7080d18ac2be758b242c22f020c018b1c4824 (diff)
MHR-16: Add QR-code when bootloader crashes alongside other welcomed changes.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/Builtins/Toolbox/Toolbox.hxx12
-rw-r--r--Private/FirmwareKit/EFI/API.hxx40
-rw-r--r--Private/FirmwareKit/Handover.hxx9
-rw-r--r--Private/KernelKit/SMPManager.hpp3
-rw-r--r--Private/NewBoot/BootKit/BitManip.hxx20
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx13
-rw-r--r--Private/NewBoot/BootKit/Vendor/Qr.hxx837
-rw-r--r--Private/NewBoot/BootKit/Vendor/QrPrelude.hxx1
-rw-r--r--Private/NewBoot/BootKit/Vendor/Support.hxx90
-rw-r--r--Private/NewBoot/Source/CDROM/SplashScreen.fmt2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx3
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx3
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx6
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootString.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Support.cxx32
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/Source/ProcessScheduler.cxx11
21 files changed, 1054 insertions, 40 deletions
diff --git a/Private/Builtins/Toolbox/Toolbox.hxx b/Private/Builtins/Toolbox/Toolbox.hxx
index b3dad30b..0c5b31c5 100644
--- a/Private/Builtins/Toolbox/Toolbox.hxx
+++ b/Private/Builtins/Toolbox/Toolbox.hxx
@@ -25,8 +25,8 @@ EXTERN_C NewOS::Boolean _hal_right_button_pressed();
#define ToolboxDrawOrRsrc(ImgPtr, _Height, _Width, BaseX, BaseY) \
__ToolboxCursor = 0; \
\
- for (NewOS::SizeT i = BaseX; i < _Height + BaseX; ++i) { \
- for (NewOS::SizeT u = BaseY; u < _Width + BaseY; ++u) { \
+ for (NewOS::SizeT i = BaseX; i < (_Height + BaseX); ++i) { \
+ for (NewOS::SizeT u = BaseY; u < (_Width + BaseY); ++u) { \
*(((volatile NewOS::UInt32*)(kHandoverHeader->f_GOP.f_The + \
4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
i + \
@@ -40,8 +40,8 @@ EXTERN_C NewOS::Boolean _hal_right_button_pressed();
#define ToolboxDrawRsrc(ImgPtr, _Height, _Width, BaseX, BaseY) \
__ToolboxCursor = 0; \
\
- for (NewOS::SizeT i = BaseX; i < _Height + BaseX; ++i) { \
- for (NewOS::SizeT u = BaseY; u < _Width + BaseY; ++u) { \
+ for (NewOS::SizeT i = BaseX; i < (_Height + BaseX); ++i) { \
+ for (NewOS::SizeT u = BaseY; u < (_Width + BaseY); ++u) { \
*(((volatile NewOS::UInt32*)(kHandoverHeader->f_GOP.f_The + \
4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
i + \
@@ -66,8 +66,8 @@ EXTERN_C NewOS::Boolean _hal_right_button_pressed();
/// @brief Draws inside a zone.
#define ToolboxDrawZone(_Clr, _Height, _Width, BaseX, BaseY) \
\
- for (NewOS::SizeT i = BaseX; i < _Width + BaseX; ++i) { \
- for (NewOS::SizeT u = BaseY; u < _Height + BaseY; ++u) { \
+ for (NewOS::SizeT i = BaseX; i < (_Width + BaseX); ++i) { \
+ for (NewOS::SizeT u = BaseY; u < (_Height + BaseY); ++u) { \
*(((volatile NewOS::UInt32*)(kHandoverHeader->f_GOP.f_The + \
4 * kHandoverHeader->f_GOP.f_PixelPerLine * \
i + \
diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx
index 536d12c8..212f3686 100644
--- a/Private/FirmwareKit/EFI/API.hxx
+++ b/Private/FirmwareKit/EFI/API.hxx
@@ -7,16 +7,23 @@
#ifndef __EFI_API__
#define __EFI_API__
-#ifdef __NEWBOOT__
-#include <BootKit/Rsrc/NewBootFatal.rsrc>
-#include <Builtins/Toolbox/Toolbox.hxx>
-#endif // ifdef __NEWBOOT__
-
#include <FirmwareKit/EFI/EFI.hxx>
#include <FirmwareKit/Handover.hxx>
#include <KernelKit/MSDOS.hpp>
#include <KernelKit/PE.hxx>
+#ifdef __NEWBOOT__
+// forward decl.
+class BTextWriter;
+
+#define __BOOTKIT_NO_INCLUDE__ 1
+
+#include <BootKit/BootKit.hxx>
+#include <BootKit/Rsrc/NewBootFatal.rsrc>
+#include <BootKit/Vendor/Qr.hxx>
+#include <Builtins/Toolbox/Toolbox.hxx>
+#endif // ifdef __NEWBOOT__
+
inline EfiSystemTable *ST = nullptr;
inline EfiBootServices *BS = nullptr;
@@ -58,17 +65,17 @@ inline UInt32 Platform() noexcept { return kPEMachineAMD64; }
*/
inline void RaiseHardError(const EfiCharType *ErrorCode,
const EfiCharType *Reason) noexcept {
+#ifdef __DEBUG__
ST->ConOut->OutputString(ST->ConOut, L"\r\n*** STOP ***\r\n");
ST->ConOut->OutputString(ST->ConOut, L"*** Error: ");
ST->ConOut->OutputString(ST->ConOut, ErrorCode);
-#ifdef __DEBUG__
ST->ConOut->OutputString(ST->ConOut, L", Reason: ");
ST->ConOut->OutputString(ST->ConOut, Reason);
-#endif // ifdef __DEBUG__
ST->ConOut->OutputString(ST->ConOut, L" ***\r\n");
+#endif // ifdef __DEBUG__
#ifdef __NEWBOOT__
ToolboxInitRsrc();
@@ -78,7 +85,24 @@ inline void RaiseHardError(const EfiCharType *ErrorCode,
(kHandoverHeader->f_GOP.f_Height - NEWBOOTFATAL_HEIGHT) / 2);
ToolboxClearRsrc();
-#endif // ifdef __NEWBOOT__
+
+ /// Show the QR code now.
+
+ constexpr auto ver = 7;
+ auto ecc = qr::Ecc::H;
+ auto str = "https://www.mahrouss-logic.com/help";
+ auto len = BStrLen(L"https://www.mahrouss-logic.com/help");
+
+ qr::Qr<ver> encoder;
+ qr::QrDelegate encoderDelegate;
+
+ encoder.encode(str, len, ecc, -1); // Automatic mask.
+
+ /// tell delegate to draw encoded QR.
+ encoderDelegate.draw<ver>(encoder, (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) / 2,
+ (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) - 20);
+
+#endif // ifdef __NEWBOOT__
EFI::Stop();
}
diff --git a/Private/FirmwareKit/Handover.hxx b/Private/FirmwareKit/Handover.hxx
index 5ab19fdf..4131467d 100644
--- a/Private/FirmwareKit/Handover.hxx
+++ b/Private/FirmwareKit/Handover.hxx
@@ -81,10 +81,11 @@ struct HandoverInformationHeader {
} f_GOP;
};
-/**
- @brief Handover Jump Proc
-*/
-typedef void (*HandoverProc)(HandoverInformationHeader* pHandover);
+/// @brief Bootloader main type.
+typedef void (*BootMainKind)(NewOS::HEL::HandoverInformationHeader* handoverInfo);
+
+/// @brief Alias of bootloader main type.
+typedef void (*HandoverProc)(HandoverInformationHeader* handoverInfo);
} // namespace NewOS::HEL
diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp
index 17ea9d38..b7f78ebd 100644
--- a/Private/KernelKit/SMPManager.hpp
+++ b/Private/KernelKit/SMPManager.hpp
@@ -29,6 +29,9 @@ enum ThreadKind {
kHartCount,
};
+typedef enum ThreadKind SmThreadKind;
+typedef ThreadID SmThreadID;
+
///
/// \name HardwareThread
/// @brief CPU Hardware Thread (POWER, x64, or 64x0)
diff --git a/Private/NewBoot/BootKit/BitManip.hxx b/Private/NewBoot/BootKit/BitManip.hxx
new file mode 100644
index 00000000..dcb786cf
--- /dev/null
+++ b/Private/NewBoot/BootKit/BitManip.hxx
@@ -0,0 +1,20 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#ifndef __BITMANIP_H__
+#define __BITMANIP_H__
+
+/// Name: Bits API.
+/// Purpose: Bit manip helpers, based on CoreBoot header.
+
+#define bk_set_bit(X, O) X = (1 << O) | X
+#define bk_clear_bit(X, O) X = ~(1 << O) & X
+#define bk_toogle(X, O) X = (1 << O) ^ X
+#define bk_lsb(X) X = X & -X
+#define bk_msb(X) X = -(mp_lsb(X)) & X
+#define bk_look_for_bit(X, O) (1 << O) | X
+
+#endif // ifndef __BITMANIP_H__
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 1a992166..5c3a531d 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -29,19 +29,11 @@ class BVersionString;
/// Include other APIs.
/***********************************************************************************/
-#include <BootKit/Platform.hxx>
-#include <BootKit/Protocol.hxx>
+#include <NewKit/Defines.hpp>
///! @note This address is reserved to NewKernel.
#define kBootVirtualAddress (0xfffffff80000000)
-#ifdef __EFI_x86_64__
-#include <FirmwareKit/EFI.hxx>
-#endif // ifdef __EFI_x86_64__
-
-#include <FirmwareKit/EPM.hxx>
-#include <NewKit/Defines.hpp>
-
using namespace NewOS;
typedef Char *PEFImagePtr;
@@ -147,9 +139,6 @@ class BVersionString final {
static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; }
};
-/// @brief Bootloader main type.
-typedef void (*BootMainKind)(HEL::HandoverInformationHeader *handoverInfo);
-
/***********************************************************************************/
/// Provide some useful processor features.
/***********************************************************************************/
diff --git a/Private/NewBoot/BootKit/Vendor/Qr.hxx b/Private/NewBoot/BootKit/Vendor/Qr.hxx
new file mode 100644
index 00000000..7fec429e
--- /dev/null
+++ b/Private/NewBoot/BootKit/Vendor/Qr.hxx
@@ -0,0 +1,837 @@
+#ifndef QR_H
+#define QR_H
+
+#include <math.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <BootKit/Vendor/QrPrelude.hxx>
+#include <BootKit/Vendor/Support.hxx>
+#include <Builtins/Toolbox/Toolbox.hxx>
+#include <cstdint>
+
+namespace qr {
+inline uint8_t min_poly =
+ 0b11101, /* Minimal polynomial x^8 + x^4 + x^3 + x^2 + 1 */
+ generator = 0b10; /* Generator of Galois field */
+
+/// @brief galois finite field multiplication.
+inline uint8_t gf_mul(uint8_t a, uint8_t b) {
+ uint8_t res = 0;
+
+ for (; b; b >>= 1) {
+ if (b & 1) res ^= a;
+ if (a & 0x80)
+ a = (a << 1) ^ min_poly;
+ else
+ a <<= 1;
+ }
+
+ return res;
+}
+
+// Size of Ecc block with respect to level and version. 0 version is for
+// padding.
+constexpr int ECC_CODEWORDS_PER_BLOCK[4][41] = {
+ {0, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26,
+ 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30,
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30},
+ {0, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22,
+ 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28},
+ {0, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24,
+ 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30,
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30},
+ {0, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22,
+ 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30,
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30},
+};
+
+// Number of Ecc blocks with respect to level and version. 0 version is for
+// padding.
+constexpr int N_ECC_BLOCKS[4][41] = {
+ {0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4,
+ 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12,
+ 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25},
+ {0, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9,
+ 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25,
+ 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49},
+ {0, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12,
+ 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34,
+ 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68},
+ {0, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16,
+ 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40,
+ 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81},
+};
+
+// Positions of central modules of alignment patterns according to version. 0
+// version is for padding.
+constexpr int ALIGN_POS[41][7] = {
+ {},
+ {0},
+ {6, 18},
+ {6, 22},
+ {6, 26},
+ {6, 30},
+ {6, 34},
+ {6, 22, 38},
+ {6, 24, 42},
+ {6, 26, 46},
+ {6, 28, 50},
+ {6, 30, 54},
+ {6, 32, 58},
+ {6, 34, 62},
+ {6, 26, 46, 66},
+ {6, 26, 48, 70},
+ {6, 26, 50, 74},
+ {6, 30, 54, 78},
+ {6, 30, 56, 82},
+ {6, 30, 58, 86},
+ {6, 34, 62, 90},
+ {6, 28, 50, 72, 94},
+ {6, 26, 50, 74, 98},
+ {6, 30, 54, 78, 102},
+ {6, 28, 54, 80, 106},
+ {6, 32, 58, 84, 110},
+ {6, 30, 58, 86, 114},
+ {6, 34, 62, 90, 118},
+ {6, 26, 50, 74, 98, 122},
+ {6, 30, 54, 78, 102, 126},
+ {6, 26, 52, 78, 104, 130},
+ {6, 30, 56, 82, 108, 134},
+ {6, 34, 60, 86, 112, 138},
+ {6, 30, 58, 86, 114, 142},
+ {6, 34, 62, 90, 118, 146},
+ {6, 30, 54, 78, 102, 126, 150},
+ {6, 24, 50, 76, 102, 128, 154},
+ {6, 28, 54, 80, 106, 132, 158},
+ {6, 32, 58, 84, 110, 136, 162},
+ {6, 26, 54, 82, 110, 138, 166},
+ {6, 30, 58, 86, 114, 142, 170},
+};
+
+// Return n-th bit of arr starting from MSB.
+constexpr uint8_t get_bit_r(uint8_t *arr, int n) {
+ return (arr[n >> 3] >> (7 - (n & 7))) & 1;
+}
+
+// Add up to 16 bits to arr. Data starts from MSB as well as each byte of an
+// array.
+constexpr void add_bits(uint16_t data, int n, uint8_t *arr, size_t &pos) {
+ while (n--) {
+ arr[pos >> 3] |= ((data >> n) & 1) << (7 - (pos & 7));
+ ++pos;
+ }
+}
+
+// Translate char to alphanumeric encoding value,
+constexpr int alphanumeric(char c) {
+ if (c >= '0' && c <= '9') return c - '0';
+
+ if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
+
+ switch (c) {
+ case ' ':
+ return 36;
+ case '$':
+ return 37;
+ case '%':
+ return 38;
+ case '*':
+ return 39;
+ case '+':
+ return 40;
+ case '-':
+ return 41;
+ case '.':
+ return 42;
+ case '/':
+ return 43;
+ case ':':
+ return 44;
+ }
+ return -1;
+}
+
+// Check if string can be encoded in alphanumeric mode.
+constexpr bool is_alphanumeric(const char *str, size_t len) {
+ for (size_t i = 0; i < len; ++i)
+ if (alphanumeric(str[i]) == -1) return false;
+ return true;
+}
+
+// Check if string can be encoded in numeric mode.
+constexpr bool is_numeric(const char *str, size_t len) {
+ for (size_t i = 0; i < len; ++i)
+ if (str[i] < '0' || str[i] > '9') return false;
+ return true;
+}
+
+// Check if string can be encoded in kanji mode.
+constexpr bool is_kanji(const char *str, size_t len) {
+ for (size_t i = 0; i < len; i += 2) {
+ uint16_t val = uint16_t(str[i]) | (uint16_t(str[i + 1]) << 8);
+ if (val < 0x8140 || val > 0xebbf || (val > 0x9ffc && val < 0xe040))
+ return false;
+ }
+ return true;
+}
+
+// Reed-Solomon Ecc generator polynomial for the given degree.
+constexpr void gf_gen_poly(int degree, uint8_t *poly) {
+ SetMem(poly, 0, degree);
+
+ uint8_t root = poly[degree - 1] = 1;
+
+ for (int i = 0; i < degree; ++i) {
+ for (int j = 0; j < degree - 1; ++j)
+ poly[j] = gf_mul(poly[j], root) ^ poly[j + 1];
+ poly[degree - 1] = gf_mul(poly[degree - 1], root);
+ root = (root << 1) ^ ((root >> 7) * 0x11d);
+ }
+}
+
+// Polynomial division if Galois Field.
+constexpr void gf_poly_div(uint8_t *dividend, size_t len, uint8_t *divisor,
+ int degree, uint8_t *result) {
+ SetMem(result, 0, degree);
+
+ for (size_t i = 0; i < len; ++i) {
+ uint8_t factor = dividend[i] ^ result[0];
+ MoveMem(&result[0], &result[1], degree - 1);
+ result[degree - 1] = 0;
+ for (int j = 0; j < degree; ++j) result[j] ^= gf_mul(divisor[j], factor);
+ }
+}
+
+enum Ecc {
+ L,
+ M,
+ Q,
+ H,
+};
+
+enum Mode {
+ M_NUMERIC,
+ M_ALPHANUMERIC,
+ M_BYTE,
+ M_KANJI,
+};
+
+// Select appropriate encoding mode for string.
+constexpr Mode select_mode(const char *str, size_t len) {
+ if (is_numeric(str, len)) return M_NUMERIC;
+ if (is_alphanumeric(str, len)) return M_ALPHANUMERIC;
+ if (is_kanji(str, len)) return M_KANJI;
+ return M_BYTE;
+}
+
+// Return size of Character Control Indicator in bits for given version and
+// mode.
+constexpr int cci(int ver, Mode mode) {
+ constexpr int cnt[4][3] = {
+ {10, 12, 14},
+ {9, 11, 13},
+ {8, 16, 16},
+ {8, 10, 12},
+ };
+ if (ver < 10) return cnt[mode][0];
+ if (ver < 27) return cnt[mode][1];
+ return cnt[mode][2];
+}
+
+template <int V>
+struct Qr {
+private:
+ friend class QrDelegate;
+ bool draw(int x, int y) noexcept;
+
+public:
+ constexpr auto side_size() const { return SIDE; }
+ constexpr auto data_size() const { return N_BITS; }
+ constexpr auto data_ptr() const { return code; }
+
+ bool module(int x, int y);
+ bool encode(const char *str, size_t len, Ecc ecc, int mask = -1);
+
+ private:
+ bool encode_data(const char *data, size_t len, Ecc ecc, uint8_t *out);
+ void encode_ecc(uint8_t *data, Ecc ecc, uint8_t *out);
+
+ void add_data(uint8_t *data, uint8_t *patterns);
+ void add_patterns();
+ void add_version();
+ void add_format(Ecc ecc, int mask);
+ void reserve_patterns(uint8_t *out);
+
+ template <bool Black>
+ void draw_rect(int y, int x, int height, int width, uint8_t *out);
+ template <bool Black>
+ void draw_bound(int y, int x, int height, int width, uint8_t *out);
+
+ template <bool Horizontal>
+ int rule_1_3_score();
+ int penalty_score();
+ int select_mask(Ecc ecc, uint8_t *patterns);
+ void apply_mask(int mask, uint8_t *patterns);
+
+ private:
+ static_assert(V <= 40, "invalid version");
+ static constexpr int SIDE = 17 + V * 4;
+ static constexpr int N_BITS = SIDE * SIDE;
+ static constexpr int N_ALIGN = V == 1 ? 0 : V / 7 + 2;
+ static constexpr int N_ALIGN_BITS = V > 1 ? (N_ALIGN *N_ALIGN - 3) * 25 : 0;
+ static constexpr int N_TIMING_BITS =
+ (SIDE - 16) * 2 - (10 * (V > 1 ? N_ALIGN - 2 : 0));
+ static constexpr int N_VER_BITS = V > 6 ? 36 : 0;
+ static constexpr int N_DAT_BITS =
+ N_BITS - (192 + N_ALIGN_BITS + N_TIMING_BITS + 31 + N_VER_BITS);
+ static constexpr int N_BYTES = N_BITS; // Actual number of bytes_in_bits
+ // required to store whole Qr code
+ static constexpr int N_DAT_BYTES =
+ N_DAT_BITS; // Actual number of bytes_in_bits required to store
+ // [data + ecc]
+ static constexpr int N_DAT_CAPACITY =
+ N_DAT_BITS >> 3; // Capacity of [data + ecc] without remainder bits
+ private:
+ /// @brief internal function to retrieve bit from a bitset.
+ uint8_t get_arr_bit(uint8_t *arr, uint64_t bit) const {
+ return ((volatile uint8_t *)arr)[bit];
+ }
+
+ /// @brief internal function to set bit from a bitset.
+ bool set_arr_bit(uint8_t *arr, uint64_t bit) {
+ if (((volatile uint8_t *)arr)[bit] == 0) {
+ ((volatile uint8_t *)arr)[bit] = 1;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /// @brief internal function to clear bit from a bitset.
+ bool clr_arr_bit(uint8_t *arr, uint64_t bit) {
+ if (((volatile uint8_t *)arr)[bit] == 1) {
+ ((volatile uint8_t *)arr)[bit] = 0;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ uint8_t code[N_BITS] = {0};
+
+ bool status = false;
+};
+
+// Get color of a module from left-to-right and top-to-bottom. Black is true.
+template <int V>
+bool Qr<V>::module(int x, int y) {
+ return get_arr_bit(code, y * SIDE + x);
+}
+
+/// @brief draw a new QR code.
+template <int V>
+bool Qr<V>::draw(int whereX, int whereY) noexcept {
+ if (!this->status) return false; // it may be invalid.
+
+ for (int y = 0; y < (this->side_size()); ++y) {
+ for (int x = 0; x < (this->side_size()); ++x) {
+ ToolboxDrawZone(
+ (this->module(x, y) ? RGB(00, 00, 00) : RGB(FF, FF, FF)),
+ 1, 1,
+ x + whereX, y + whereY);
+ }
+ }
+
+ return false;
+}
+
+// Create Qr code with given error correction level. If mask == -1,
+// then best mask selected automatically. NOTE: Automatic mask is the
+// most expensive operation. Takes about 95 % of all computation time.
+template <int V>
+bool Qr<V>::encode(const char *str, size_t len, Ecc ecc, int mask) {
+ uint8_t data[N_DAT_BYTES] = {};
+ uint8_t data_with_ecc[N_DAT_BYTES] = {};
+ uint8_t patterns[N_BYTES] = {};
+
+ if (!encode_data(str, len, ecc, data)) {
+ return status = false;
+ }
+
+ encode_ecc(data, ecc, data_with_ecc);
+
+ reserve_patterns(patterns);
+ CopyMem(code, patterns, N_BYTES);
+
+ add_data(data_with_ecc, patterns);
+ add_patterns();
+ add_version();
+
+ mask = mask != -1 ? mask & 7 : select_mask(ecc, patterns);
+
+ add_format(ecc, mask);
+ apply_mask(mask, patterns);
+
+ return status = true;
+}
+
+template <int V>
+bool Qr<V>::encode_data(const char *data, size_t len, Ecc ecc, uint8_t *out) {
+ Mode mode = select_mode(data, len);
+
+ size_t n_bits =
+ (N_DAT_CAPACITY - ECC_CODEWORDS_PER_BLOCK[ecc][V] * N_ECC_BLOCKS[ecc][V])
+ << 3;
+ size_t pos = 0;
+
+ add_bits(1 << mode, 4, out, pos);
+ add_bits(len, cci(V, mode), out, pos);
+
+ if (mode == M_NUMERIC) {
+ const size_t triplets = len / 3;
+ const size_t triplets_size = triplets * 3;
+ const size_t rem = len % 3;
+ const size_t rem_bits = rem == 2 ? 7 : rem == 1 ? 4 : 0;
+ const size_t total_size = 10 * triplets + rem_bits;
+
+ if (pos + total_size > n_bits) return false;
+
+ char buf[4] = {};
+
+ for (size_t i = 0; i < triplets_size; i += 3) {
+ buf[0] = data[i];
+ buf[1] = data[i + 1];
+ buf[2] = data[i + 2];
+
+ uint16_t num = StringToLong(buf, NULL, 10);
+ add_bits(num, 10, out, pos);
+ }
+
+ if (rem) {
+ buf[0] = data[triplets_size];
+ buf[1] = data[triplets_size + 1];
+ buf[rem] = 0;
+
+ uint16_t num = StringToLong(buf, NULL, 10);
+ add_bits(num, rem_bits, out, pos);
+ }
+ } else if (mode == M_ALPHANUMERIC) {
+ if (pos + 11 * (int(len & ~1ul) / 2) > n_bits) return false;
+
+ for (int i = 0; i < int(len & ~1ul); i += 2) {
+ uint16_t num = alphanumeric(data[i]) * 45 + alphanumeric(data[i + 1]);
+ add_bits(num, 11, out, pos);
+ }
+ if (len & 1) {
+ if (pos + 6 > n_bits) return false;
+
+ add_bits(alphanumeric(data[len - 1]), 6, out, pos);
+ }
+
+ } else if (mode == M_BYTE) {
+ if (pos + len * 8 > n_bits) return false;
+
+ for (size_t i = 0; i < len; ++i) add_bits(data[i], 8, out, pos);
+
+ } else {
+ if (pos + 13 * (len / 2) > n_bits) return false;
+
+ for (size_t i = 0; i < len; i += 2) {
+ uint16_t val = ((uint8_t)data[i]) | (((uint8_t)data[i + 1]) << 8);
+ uint16_t res = 0;
+ val -= val < 0x9FFC ? 0x8140 : 0xC140;
+ res += val & 0xff;
+ res += (val >> 8) * 0xc0;
+ add_bits(res, 13, out, pos);
+ }
+ }
+
+ size_t padding = n_bits - pos;
+ size_t i = 0;
+
+ add_bits(0, padding > 4 ? 4 : padding, out, pos);
+
+ if (pos & 7) add_bits(0, (8 - pos) & 7, out, pos);
+
+ while (pos < n_bits) add_bits(++i & 1 ? 0xec : 0x11, 8, out, pos);
+
+ return true;
+}
+
+template <int V>
+void Qr<V>::encode_ecc(uint8_t *data, Ecc ecc, uint8_t *out) {
+ int n_blocks = N_ECC_BLOCKS[ecc][V];
+ int ecc_len = ECC_CODEWORDS_PER_BLOCK[ecc][V];
+
+ int n_data_bytes = N_DAT_CAPACITY - ecc_len * n_blocks;
+
+ int n_short_blocks = n_blocks - N_DAT_CAPACITY % n_blocks;
+ int short_len = N_DAT_CAPACITY / n_blocks - ecc_len;
+
+ uint8_t gen_poly[30];
+ uint8_t ecc_buf[30];
+
+ gf_gen_poly(ecc_len, gen_poly);
+
+ uint8_t *data_ptr = data;
+
+ for (int i = 0; i < n_blocks; ++i) {
+ int data_len = short_len;
+
+ if (i >= n_short_blocks) ++data_len;
+
+ gf_poly_div(data_ptr, data_len, gen_poly, ecc_len, ecc_buf);
+
+ for (int j = 0, k = i; j < data_len; ++j, k += n_blocks) {
+ if (j == short_len) k -= n_short_blocks;
+ out[k] = data_ptr[j];
+ }
+ for (int j = 0, k = n_data_bytes + i; j < ecc_len; ++j, k += n_blocks)
+ out[k] = ecc_buf[j];
+
+ data_ptr += data_len;
+ }
+}
+
+template <int V>
+void Qr<V>::add_data(uint8_t *data, uint8_t *patterns) {
+ int data_pos = 0;
+
+ for (int x = SIDE - 1; x >= 1; x -= 2) {
+ if (x == 6) x = 5;
+
+ for (int i = 0; i < SIDE; ++i) {
+ int y = !((x + 1) & 2) ? SIDE - 1 - i : i;
+ int coord = y * SIDE + x;
+
+ if (!get_arr_bit(patterns, coord)) {
+ if (get_bit_r(data, data_pos)) set_arr_bit(code, coord);
+
+ ++data_pos;
+ }
+
+ if (!get_arr_bit(patterns, coord - 1)) {
+ if (get_bit_r(data, data_pos)) set_arr_bit(code, coord - 1);
+
+ ++data_pos;
+ }
+ }
+ }
+}
+
+template <int V>
+void Qr<V>::add_patterns() {
+ // White bounds inside finders
+ draw_bound<false>(1, 1, 5, 5, code);
+ draw_bound<false>(1, SIDE - 6, 5, 5, code);
+ draw_bound<false>(SIDE - 6, 1, 5, 5, code);
+
+ // Finish alignment patterns
+ for (int i = 0; i < N_ALIGN; ++i) {
+ for (int j = 0; j < N_ALIGN; ++j) {
+ if ((!i && !j) || (!i && j == N_ALIGN - 1) || (!j && i == N_ALIGN - 1))
+ continue;
+ draw_bound<false>(ALIGN_POS[V][i] - 1, ALIGN_POS[V][j] - 1, 3, 3, code);
+ }
+ }
+
+ // Draw white separators
+ draw_rect<false>(7, 0, 1, 8, code);
+ draw_rect<false>(0, 7, 8, 1, code);
+ draw_rect<false>(SIDE - 8, 0, 1, 8, code);
+ draw_rect<false>(SIDE - 8, 7, 8, 1, code);
+ draw_rect<false>(7, SIDE - 8, 1, 8, code);
+ draw_rect<false>(0, SIDE - 8, 8, 1, code);
+
+ // Perforate timing patterns
+ for (int i = 7; i < SIDE - 7; i += 2) {
+ clr_arr_bit(code, 6 * SIDE + i);
+ clr_arr_bit(code, i * SIDE + 6);
+ }
+}
+
+template <int V>
+void Qr<V>::add_version() {
+ if (V < 7) return;
+
+ uint32_t rem = V;
+
+ for (uint8_t i = 0; i < 12; ++i) rem = (rem << 1) ^ ((rem >> 11) * 0x1F25);
+
+ uint32_t data = V << 12 | rem;
+
+ for (int x = 0; x < 6; ++x) {
+ for (int j = 0; j < 3; ++j) {
+ int y = SIDE - 11 + j;
+
+ bool black = (data >> (x * 3 + j)) & 1;
+
+ if (!black) {
+ clr_arr_bit(code, y * SIDE + x);
+ clr_arr_bit(code, y + SIDE * x);
+ }
+ }
+ }
+}
+
+template <int V>
+void Qr<V>::add_format(Ecc ecc, int mask) {
+ int data = (ecc ^ 1) << 3 | mask;
+ int rem = data;
+
+ for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >> 9) * 0b10100110111);
+
+ int res = (data << 10 | rem) ^ 0b101010000010010;
+
+ for (int i = 0; i < 6; ++i) {
+ if ((res >> i) & 1) {
+ set_arr_bit(code, SIDE * 8 + SIDE - 1 - i);
+ set_arr_bit(code, SIDE * i + 8);
+ } else {
+ clr_arr_bit(code, SIDE * 8 + SIDE - 1 - i);
+ clr_arr_bit(code, SIDE * i + 8);
+ }
+ }
+
+ for (int i = 6; i < 8; ++i) {
+ if ((res >> i) & 1) {
+ set_arr_bit(code, SIDE * 8 + SIDE - 1 - i);
+ set_arr_bit(code, SIDE * (i + 1) + 8);
+ } else {
+ clr_arr_bit(code, SIDE * 8 + SIDE - 1 - i);
+ clr_arr_bit(code, SIDE * (i + 1) + 8);
+ }
+ }
+
+ if ((res >> 8) & 1) {
+ set_arr_bit(code, SIDE * 8 + 7);
+ set_arr_bit(code, SIDE * (SIDE - 7) + 8);
+ } else {
+ clr_arr_bit(code, SIDE * 8 + 7);
+ clr_arr_bit(code, SIDE * (SIDE - 7) + 8);
+ }
+
+ for (int i = 9, j = 5; i < 15; ++i, --j) {
+ if ((res >> i) & 1) {
+ set_arr_bit(code, SIDE * 8 + j);
+ set_arr_bit(code, SIDE * (SIDE - 1 - j) + 8);
+ } else {
+ clr_arr_bit(code, SIDE * 8 + j);
+ clr_arr_bit(code, SIDE * (SIDE - 1 - j) + 8);
+ }
+ }
+}
+
+template <int V>
+template <bool B>
+void Qr<V>::draw_rect(int y, int x, int height, int width, uint8_t *out) {
+ if (B) {
+ for (int dy = y * SIDE; dy < (y + height) * SIDE; dy += SIDE)
+ for (int dx = x; dx < x + width; ++dx) set_arr_bit(out, dy + dx);
+ } else {
+ for (int dy = y * SIDE; dy < (y + height) * SIDE; dy += SIDE)
+ for (int dx = x; dx < x + width; ++dx) clr_arr_bit(out, dy + dx);
+ }
+}
+
+template <int V>
+template <bool B>
+void Qr<V>::draw_bound(int y, int x, int height, int width, uint8_t *out) {
+ if (B) {
+ for (int i = y * SIDE + x; i < y * SIDE + x + width; ++i)
+ set_arr_bit(out, i);
+ for (int i = (y + height - 1) * SIDE + x;
+ i < (y + height - 1) * SIDE + x + width; ++i)
+ set_arr_bit(out, i);
+ for (int i = (y + 1) * SIDE + x; i < (y + height - 1) * SIDE + x; i += SIDE)
+ set_arr_bit(out, i);
+ for (int i = (y + 1) * SIDE + x + width - 1;
+ i < (y + height - 1) * SIDE + x + width - 1; i += SIDE)
+ set_arr_bit(out, i);
+ } else {
+ for (int i = y * SIDE + x; i < y * SIDE + x + width; ++i)
+ clr_arr_bit(out, i);
+ for (int i = (y + height - 1) * SIDE + x;
+ i < (y + height - 1) * SIDE + x + width; ++i)
+ clr_arr_bit(out, i);
+ for (int i = (y + 1) * SIDE + x; i < (y + height - 1) * SIDE + x; i += SIDE)
+ clr_arr_bit(out, i);
+ for (int i = (y + 1) * SIDE + x + width - 1;
+ i < (y + height - 1) * SIDE + x + width - 1; i += SIDE)
+ clr_arr_bit(out, i);
+ }
+}
+
+template <int V>
+void Qr<V>::reserve_patterns(uint8_t *out) {
+ draw_rect<true>(0, 6, SIDE, 1, out);
+ draw_rect<true>(6, 0, 1, SIDE, out);
+
+ draw_rect<true>(0, 0, 9, 9, out);
+ draw_rect<true>(SIDE - 8, 0, 8, 9, out);
+ draw_rect<true>(0, SIDE - 8, 9, 8, out);
+
+ for (int i = 0; i < N_ALIGN; ++i) {
+ for (int j = 0; j < N_ALIGN; ++j) {
+ if ((!i && !j) || (!i && j == N_ALIGN - 1) || (!j && i == N_ALIGN - 1))
+ continue;
+ draw_rect<true>(ALIGN_POS[V][i] - 2, ALIGN_POS[V][j] - 2, 5, 5, out);
+ }
+ }
+
+ if (V >= 7) {
+ draw_rect<true>(SIDE - 11, 0, 3, 6, out);
+ draw_rect<true>(0, SIDE - 11, 6, 3, out);
+ }
+}
+
+template <int V>
+template <bool H>
+int Qr<V>::rule_1_3_score() {
+ constexpr int y_max = H ? N_BITS : SIDE;
+ constexpr int x_max = H ? SIDE : N_BITS;
+ constexpr int y_step = H ? SIDE : 1;
+ constexpr int x_step = H ? 1 : SIDE;
+
+ int res = 0;
+
+ for (int y = 0; y < y_max; y += y_step) {
+ bool color = get_arr_bit(code, y);
+ int finder = color;
+ int cnt = 1;
+ for (int x = 1; x < x_max; x += x_step) {
+ if (get_arr_bit(code, y + x) == color) {
+ ++cnt;
+ if (cnt == 5) res += 3;
+ if (cnt > 5) ++res;
+ } else {
+ color = !color;
+ cnt = 1;
+ }
+ // Finder-like
+ finder = ((finder << 1) & 0x7ff) | color;
+ if (x >= x_step * 10) {
+ if (finder == 0x05d || finder == 0x5d0) res += 40;
+ }
+ }
+ }
+ return res;
+}
+
+template <int V>
+int Qr<V>::penalty_score() {
+ int res = 0;
+
+ res += rule_1_3_score<true>();
+ res += rule_1_3_score<false>();
+
+ for (int y = 0; y < N_BITS - SIDE; y += SIDE) {
+ for (int x = 0; x < SIDE - 1; ++x) {
+ bool c = get_arr_bit(code, y + x);
+
+ if (c == get_arr_bit(code, y + x + 1) &&
+ c == get_arr_bit(code, y + x + SIDE) &&
+ c == get_arr_bit(code, y + x + SIDE + 1))
+ res += 3;
+ }
+ }
+
+ int black = 0;
+ for (int y = 0; y < N_BITS; y += SIDE) {
+ for (int x = 0; x < SIDE; ++x) black += get_arr_bit(code, y + x);
+ }
+ res += abs((black * 100) / N_BITS - 50) / 5 * 10;
+
+ return res;
+}
+
+template <int V>
+int Qr<V>::select_mask(Ecc ecc, uint8_t *patterns) {
+ unsigned min_score = -1;
+ unsigned score = 0;
+ uint8_t mask = 0;
+
+ for (int i = 0; i < 8; ++i) {
+ add_format(ecc, i);
+ apply_mask(i, patterns);
+ score = penalty_score();
+ if (score < min_score) {
+ mask = i;
+ min_score = score;
+ }
+ apply_mask(i, patterns);
+ }
+ return mask;
+}
+
+template <int V>
+void Qr<V>::apply_mask(int mask, uint8_t *patterns) {
+ for (int y = 0, dy = 0; y < SIDE; ++y, dy += SIDE) {
+ for (int x = 0; x < SIDE; ++x) {
+ int coord = dy + x;
+
+ if (get_arr_bit(patterns, coord)) continue;
+
+ bool keep = true;
+
+ switch (mask) {
+ case 0:
+ keep = (x + y) & 1;
+ break;
+ case 1:
+ keep = y & 1;
+ break;
+ case 2:
+ keep = x % 3;
+ break;
+ case 3:
+ keep = (x + y) % 3;
+ break;
+ case 4:
+ keep = (y / 2 + x / 3) & 1;
+ break;
+ case 5:
+ keep = x * y % 2 + x * y % 3;
+ break;
+ case 6:
+ keep = (x * y % 2 + x * y % 3) & 1;
+ break;
+ case 7:
+ keep = ((x + y) % 2 + x * y % 3) & 1;
+ break;
+ }
+
+ if (!keep) {
+ if (get_arr_bit(code, coord))
+ clr_arr_bit(code, coord);
+ else
+ set_arr_bit(code, coord);
+ }
+ }
+ }
+}
+
+/// @brief QR code encoder class.
+class QrDelegate final {
+public:
+ explicit QrDelegate() = default;
+ ~QrDelegate() = default;
+
+ /// @brief Draw method delegate.
+ template <int V>
+ bool draw(Qr<V>& subject, int x, int y) noexcept {
+ return subject.draw(x, y);
+ }
+
+};
+} // namespace qr
+
+namespace NewOS::Qr {
+ using namespace qr;
+} // namespace NewOS
+
+#endif
diff --git a/Private/NewBoot/BootKit/Vendor/QrPrelude.hxx b/Private/NewBoot/BootKit/Vendor/QrPrelude.hxx
new file mode 100644
index 00000000..31bd93da
--- /dev/null
+++ b/Private/NewBoot/BootKit/Vendor/QrPrelude.hxx
@@ -0,0 +1 @@
+#include <BootKit/BitManip.hxx>
diff --git a/Private/NewBoot/BootKit/Vendor/Support.hxx b/Private/NewBoot/BootKit/Vendor/Support.hxx
new file mode 100644
index 00000000..4d35b4cb
--- /dev/null
+++ b/Private/NewBoot/BootKit/Vendor/Support.hxx
@@ -0,0 +1,90 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+/// @file Purpose of this file is to help port libs into the bootloader.
+
+#include <BootKit/BootKit.hxx>
+
+#define LONG_MAX ((long)(~0UL>>1))
+#define LONG_MIN (~LONG_MAX)
+
+#define SetMem(dst, c, sz) BSetMem((CharacterTypeUTF16 *)dst, c, sz)
+#define MoveMem(dst, src, sz) BCopyMem((CharacterTypeUTF16 *)dst, (CharacterTypeUTF16 *)src, sz)
+#define CopyMem(dst, src, sz) BCopyMem((CharacterTypeUTF16 *)dst, (CharacterTypeUTF16 *)src, sz)
+
+inline int isspace(int c) { return c == ' '; }
+
+inline long StringToLong(const char * nptr, char ** endptr, int base) {
+ const char *p = nptr, *endp;
+ bool is_neg = 0, overflow = 0;
+ /* Need unsigned so (-LONG_MIN) can fit in these: */
+ unsigned long n = 0UL, cutoff;
+ int cutlim;
+ if (base < 0 || base == 1 || base > 36) {
+ return 0L;
+ }
+ endp = nptr;
+ while (isspace(*p))
+ p++;
+ if (*p == '+') {
+ p++;
+ } else if (*p == '-') {
+ is_neg = 1, p++;
+ }
+ if (*p == '0') {
+ p++;
+ /* For strtol(" 0xZ", &endptr, 16), endptr should point to 'x';
+ * pointing to ' ' or '0' is non-compliant.
+ * (Many implementations do this wrong.) */
+ endp = p;
+ if (base == 16 && (*p == 'X' || *p == 'x')) {
+ p++;
+ } else if (base == 2 && (*p == 'B' || *p == 'b')) {
+ /* C23 standard supports "0B" and "0b" prefixes. */
+ p++;
+ } else if (base == 0) {
+ if (*p == 'X' || *p == 'x') {
+ base = 16, p++;
+ } else if (*p == 'B' || *p == 'b') {
+ base = 2, p++;
+ } else {
+ base = 8;
+ }
+ }
+ } else if (base == 0) {
+ base = 10;
+ }
+ cutoff = (is_neg) ? -(LONG_MIN / base) : LONG_MAX / base;
+ cutlim = (is_neg) ? -(LONG_MIN % base) : LONG_MAX % base;
+ while (1) {
+ int c;
+ if (*p >= 'A')
+ c = ((*p - 'A') & (~('a' ^ 'A'))) + 10;
+ else if (*p <= '9')
+ c = *p - '0';
+ else
+ break;
+ if (c < 0 || c >= base) break;
+ endp = ++p;
+ if (overflow) {
+ /* endptr should go forward and point to the non-digit character
+ * (of the given base); required by ANSI standard. */
+ if (endptr) continue;
+ break;
+ }
+ if (n > cutoff || (n == cutoff && c > cutlim)) {
+ overflow = 1; continue;
+ }
+ n = n * base + c;
+ }
+ if (endptr) *endptr = (char *)endp;
+ if (overflow) {
+ return ((is_neg) ? LONG_MIN : LONG_MAX);
+ }
+ return (long)((is_neg) ? -n : n);
+}
diff --git a/Private/NewBoot/Source/CDROM/SplashScreen.fmt b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
index a3dba676..339b94e7 100644
--- a/Private/NewBoot/Source/CDROM/SplashScreen.fmt
+++ b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
@@ -1,4 +1,4 @@
-Welcome to the NeWS.
+Welcome to NeWS.
Brought to you by:
* MicroKernel, Bootloader: Amlal EL Mahrouss.
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
index d736ac59..d04a94d3 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
@@ -15,4 +15,7 @@
*
*/
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/HW/SATA.hxx>
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
index 4e41ba2e..d3573064 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
@@ -15,8 +15,9 @@
*
*/
-#include <BootKit/HW/ATA.hxx>
+#include <FirmwareKit/EFI.hxx>
#include <BootKit/BootKit.hxx>
+#include <BootKit/HW/ATA.hxx>
/// bugs: 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
index 33067380..aab5db1f 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
@@ -8,6 +8,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
#include <FirmwareKit/Handover.hxx>
#include <cstddef>
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 42852b5d..d314c949 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -4,6 +4,7 @@
------------------------------------------- */
+#include <FirmwareKit/EFI.hxx>
#include <BootKit/BootKit.hxx>
#include <BootKit/Rsrc/NewBoot.rsrc>
#include <Builtins/Toolbox/Toolbox.hxx>
@@ -58,9 +59,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
.Write(SystemTable->FirmwareVendor)
.Write(L"\r\n");
- BootDeviceATA ataDev;
- Boolean isGptFound = No;
-
UInt32 MapKey = 0;
UInt32* SizePtr = nullptr;
EfiMemoryDescriptor* Descriptor = nullptr;
@@ -185,7 +183,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
L"New Boot can't run this architecture.");
}
- BootMainKind main = (BootMainKind) nullptr;
+ NewOS::HEL::BootMainKind main = (NewOS::HEL::BootMainKind) nullptr;
if (!main) {
EFI::RaiseHardError(L"Bad-Exec",
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
index d0da09b7..f47e3532 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
@@ -4,6 +4,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
EXTERN_C void rt_hlt() { asm volatile("hlt"); }
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
index 1c6b528e..ef0e4744 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
@@ -11,6 +11,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
/// bugs 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
index 2ebde023..81aa6c9d 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
@@ -11,6 +11,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
/// BUGS: 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
index 1bb2d9ca..77552ef8 100644
--- a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
@@ -4,6 +4,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
#include <cstddef> /* Since we're using GCC for this EFI program. */
diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
new file mode 100644
index 00000000..c6b62630
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
@@ -0,0 +1,32 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <FirmwareKit/EFI/EFI.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <BootKit/Vendor/Support.hxx>
+
+/// @brief memset definition in C++.
+/// @param dst destination pointer.
+/// @param byte value to fill in.
+/// @param len length of of src.
+EXTERN_C VoidPtr memset(void *dst, int byte,
+ long long unsigned int len) {
+ SetMem(dst, byte, len);
+ return dst;
+}
+
+/// @brief memcpy definition in C++.
+/// @param dst destination pointer.
+/// @param src source pointer.
+/// @param len length of of src.
+EXTERN_C VoidPtr memcpy(void *dst, const void *src,
+ long long unsigned int len) {
+ CopyMem(dst, src, len);
+ return dst;
+}
+
+/// @brief somthing specific to the microsoft ABI, regarding checking the stack.
+EXTERN_C void ___chkstk_ms(void) {}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 2f9e3756..11c1da75 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -36,7 +36,7 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__
invalid-recipe:
@echo "invalid-recipe: Use make bootloader-<arch> instead."
-KERNEL_OBJ=kernel.bin
+KERNEL_OBJ=boot.bin
DD=dd
IMG_CREATE=qemu-img
MAX_KERNEL_SIZE=1024K
diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx
index 6d766d27..69236c18 100644
--- a/Private/Source/ProcessScheduler.cxx
+++ b/Private/Source/ProcessScheduler.cxx
@@ -25,8 +25,10 @@ namespace NewOS {
/// Exit Code stuff
/***********************************************************************************/
-static Int32 kExitCode = 0;
+STATIC Int32 kExitCode = 0U;
+/// @brief Gets the latest exit code.
+/// @note Not thread-safe.
const Int32 &rt_get_exit_code() noexcept { return kExitCode; }
/***********************************************************************************/
@@ -65,8 +67,8 @@ VoidPtr ProcessHeader::New(const SizeT &sz) {
/* @brief checks if runtime pointer is in region. */
bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz) {
- Char *_pool_ptr = (Char *)pool_ptr;
- Char *_pool = (Char *)pool;
+ UIntPtr *_pool_ptr = (UIntPtr *)pool_ptr;
+ UIntPtr *_pool = (UIntPtr *)pool;
for (SizeT index = sz; _pool[sz] != kUserHeapMag; --index) {
if (&_pool[index] > &_pool_ptr[sz]) continue;
@@ -97,10 +99,13 @@ Boolean ProcessHeader::Delete(VoidPtr ptr, const SizeT &sz) {
return false;
}
+/// @brief process name getter.
const Char *ProcessHeader::GetName() { return this->Name; }
+/// @brief process selector getter.
const ProcessSelector &ProcessHeader::GetSelector() { return this->Selector; }
+/// @brief process status getter.
const ProcessStatus &ProcessHeader::GetStatus() { return this->Status; }
/***********************************************************************************/