From 8153dc983802115951836f2b164af371ee6e3d73 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 24 Apr 2024 19:57:10 +0200 Subject: MHR-16: Add QR-code when bootloader crashes alongside other welcomed changes. Signed-off-by: Amlal El Mahrouss --- Private/FirmwareKit/EFI/API.hxx | 40 ++++++++++++++++++++++++++++++++-------- Private/FirmwareKit/Handover.hxx | 9 +++++---- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'Private/FirmwareKit') 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 -#include -#endif // ifdef __NEWBOOT__ - #include #include #include #include +#ifdef __NEWBOOT__ +// forward decl. +class BTextWriter; + +#define __BOOTKIT_NO_INCLUDE__ 1 + +#include +#include +#include +#include +#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 encoder; + qr::QrDelegate encoderDelegate; + + encoder.encode(str, len, ecc, -1); // Automatic mask. + + /// tell delegate to draw encoded QR. + encoderDelegate.draw(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 -- cgit v1.2.3 From f6a38d6c14b314d7b85855f311527ede869db96f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 08:19:06 +0200 Subject: MHR-16: see below. - Use QR-code to redirect to support page inside bootloader. - Start working on NewLoader, since the PEF linker is done. Signed-off-by: Amlal El Mahrouss --- Doxyfile | 5 +- Private/Docs/SPECIFICATION.md | 62 ++++++ Private/Docs/TODO-LIST.md | 23 ++ Private/Documentation/.gitkeep | 0 Private/Documentation/Spec.md | 62 ------ Private/Documentation/Todo.md | 21 -- Private/Documentation/kernel-design.drawio | 70 ------ Private/FirmwareKit/EFI/API.hxx | 18 +- Private/NewBoot/BootKit/Vendor/Qr.hxx | 36 ++- Private/NewBoot/BootKit/Vendor/QrVendor/base.h | 25 +++ Private/NewBoot/BootKit/Vendor/QrVendor/bit.h | 245 +++++++++++++++++++++ .../NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 6 +- Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 10 +- Private/NewLoader/Source/.gitkeep | 0 Private/makefile | 5 +- 15 files changed, 393 insertions(+), 195 deletions(-) create mode 100644 Private/Docs/SPECIFICATION.md create mode 100644 Private/Docs/TODO-LIST.md delete mode 100644 Private/Documentation/.gitkeep delete mode 100644 Private/Documentation/Spec.md delete mode 100644 Private/Documentation/Todo.md delete mode 100644 Private/Documentation/kernel-design.drawio create mode 100644 Private/NewBoot/BootKit/Vendor/QrVendor/base.h create mode 100644 Private/NewBoot/BootKit/Vendor/QrVendor/bit.h create mode 100644 Private/NewLoader/Source/.gitkeep (limited to 'Private/FirmwareKit') diff --git a/Doxyfile b/Doxyfile index a52de5be..7fd58842 100644 --- a/Doxyfile +++ b/Doxyfile @@ -943,7 +943,8 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ./Private/ \ +INPUT = ./ \ + ./Private/ \ ./Public/ \ # This tag can be used to specify the character encoding of the source files @@ -1159,7 +1160,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = ./ReadMe.md # The Fortran standard specifies that for fixed formatted Fortran code all # characters from position 72 are to be considered as comment. A common diff --git a/Private/Docs/SPECIFICATION.md b/Private/Docs/SPECIFICATION.md new file mode 100644 index 00000000..e218947e --- /dev/null +++ b/Private/Docs/SPECIFICATION.md @@ -0,0 +1,62 @@ +=================================== + +# 0: General Information + +=================================== + +- ABI and Format: PEF/PE32+. +- Kernel architecture: Portable hybrid kernel. +- Language: C++/(Assembly (AMD64, X64000, X86S, ARM64, POWER, RISCV)) + +=================================== + +# 1: The NewKernel + +=================================== + +- Drive/Device Abstraction. +- SMP, Preemptive Multi Threading. +- Separation of Files/Devices. +- Networking. +- Hardware Abstraction Layer. +- Native Filesystem support (NewFS, FAT32 and ffs2). +- Program Loaders. +- Thread Local Storage. +- Semaphore, Locks, Timers. +- Canary mechanisms. +- Dynamic Libraries. +- Cross Platform. +- Permission Selectors. + +=================================== + +# 2: The Filesystem + +=================================== + +- Catalog object with associated forks. +- Large storage support. +- Long file names. +- UNIX path style. + +================================== + +# 3: Common naming conventions: + +================================== + +- Kernel -> ke_init_x +- RunTime -> rt_copy_mem +- Hal -> hal_foo_bar + +=================================== + +# 4: The NewBoot + +=================================== + +- Capable of booting from a network drive. +- Loads a PE file which is the kernel. +- Sanity checks, based on the number of sections. +- Handover compliant. +- Does check for a valid partition (useful in the case of recovering) diff --git a/Private/Docs/TODO-LIST.md b/Private/Docs/TODO-LIST.md new file mode 100644 index 00000000..c997ce10 --- /dev/null +++ b/Private/Docs/TODO-LIST.md @@ -0,0 +1,23 @@ +# TODO list. + +- We need preemptive multi-threading. [ X ] +- We then need sync primitives. [ X ] +- We also need a system library for the OS. [ X ] +- We need a bootloader for AMD64 [ X ] + - Implement Boot Services [ X ] + - Design Handover [ X ] + - Load kernel into memory [ X ] + - Fix bug in kernel loader, which causes a 06 #UD. [ X ] + - Load Kernel [ X ] + - Add IDT [ X ] + - AHCI driver [ WiP ] +- Context switch x87/SSE/AVX registers [ X ] +- Framebuffer [ X ] +- AHCI support [ ] +- Make installer [ ] + +Status: + +NewBoot: Need to boot from EPM partition. +
+NewKernel: New Filesystem in progress. diff --git a/Private/Documentation/.gitkeep b/Private/Documentation/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/Documentation/Spec.md b/Private/Documentation/Spec.md deleted file mode 100644 index e218947e..00000000 --- a/Private/Documentation/Spec.md +++ /dev/null @@ -1,62 +0,0 @@ -=================================== - -# 0: General Information - -=================================== - -- ABI and Format: PEF/PE32+. -- Kernel architecture: Portable hybrid kernel. -- Language: C++/(Assembly (AMD64, X64000, X86S, ARM64, POWER, RISCV)) - -=================================== - -# 1: The NewKernel - -=================================== - -- Drive/Device Abstraction. -- SMP, Preemptive Multi Threading. -- Separation of Files/Devices. -- Networking. -- Hardware Abstraction Layer. -- Native Filesystem support (NewFS, FAT32 and ffs2). -- Program Loaders. -- Thread Local Storage. -- Semaphore, Locks, Timers. -- Canary mechanisms. -- Dynamic Libraries. -- Cross Platform. -- Permission Selectors. - -=================================== - -# 2: The Filesystem - -=================================== - -- Catalog object with associated forks. -- Large storage support. -- Long file names. -- UNIX path style. - -================================== - -# 3: Common naming conventions: - -================================== - -- Kernel -> ke_init_x -- RunTime -> rt_copy_mem -- Hal -> hal_foo_bar - -=================================== - -# 4: The NewBoot - -=================================== - -- Capable of booting from a network drive. -- Loads a PE file which is the kernel. -- Sanity checks, based on the number of sections. -- Handover compliant. -- Does check for a valid partition (useful in the case of recovering) diff --git a/Private/Documentation/Todo.md b/Private/Documentation/Todo.md deleted file mode 100644 index 2c4af6e5..00000000 --- a/Private/Documentation/Todo.md +++ /dev/null @@ -1,21 +0,0 @@ -- We need preemptive multi-threading. [ X ] -- We then need sync primitives. [ X ] -- We also need a system library for the OS. [ X ] -- We need a bootloader for AMD64 [ X ] - - Implement Boot Services [ X ] - - Design Handover [ X ] - - Load kernel into memory [ X ] - - Fix bug in kernel loader, which causes a 06 #UD. [ X ] - - Load Kernel [ X ] - - Add IDT [ X ] - - AHCI driver [ WiP ] -- Context switch x87/SSE/AVX registers [ X ] -- Framebuffer [ X ] -- AHCI support [ ] -- Make installer [ ] - -Status: - -NewBoot: Need to boot from EPM partition. -NewKernel: New Filesystem in progress. - diff --git a/Private/Documentation/kernel-design.drawio b/Private/Documentation/kernel-design.drawio deleted file mode 100644 index d78ac170..00000000 --- a/Private/Documentation/kernel-design.drawio +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx index 212f3686..0e2ef200 100644 --- a/Private/FirmwareKit/EFI/API.hxx +++ b/Private/FirmwareKit/EFI/API.hxx @@ -61,9 +61,11 @@ enum { inline UInt32 Platform() noexcept { return kPEMachineAMD64; } /*** - * @brief Raise Hard kernel error. + * @brief Throw an error, stop execution as well. + * @param ErrorCode error code to be print. + * @param Reason reason to be print. */ -inline void RaiseHardError(const EfiCharType *ErrorCode, +inline void ThrowError(const EfiCharType *ErrorCode, const EfiCharType *Reason) noexcept { #ifdef __DEBUG__ ST->ConOut->OutputString(ST->ConOut, L"\r\n*** STOP ***\r\n"); @@ -88,19 +90,19 @@ inline void RaiseHardError(const EfiCharType *ErrorCode, /// Show the QR code now. - constexpr auto ver = 7; + constexpr auto ver = 4; auto ecc = qr::Ecc::H; - auto str = "https://www.mahrouss-logic.com/help"; - auto len = BStrLen(L"https://www.mahrouss-logic.com/help"); + auto str = "https://el-mahrouss-logic.com/"; + auto len = BStrLen(L"https://el-mahrouss-logic.com/"); qr::Qr encoder; qr::QrDelegate encoderDelegate; - encoder.encode(str, len, ecc, -1); // Automatic mask. + encoder.encode(str, len, ecc, 0); // Manual mask 0 /// tell delegate to draw encoded QR. - encoderDelegate.draw(encoder, (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) / 2, - (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) - 20); + encoderDelegate.draw(encoder, (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) - 20, + (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) / 2); #endif // ifdef __NEWBOOT__ diff --git a/Private/NewBoot/BootKit/Vendor/Qr.hxx b/Private/NewBoot/BootKit/Vendor/Qr.hxx index 7fec429e..ca5eb566 100644 --- a/Private/NewBoot/BootKit/Vendor/Qr.hxx +++ b/Private/NewBoot/BootKit/Vendor/Qr.hxx @@ -5,6 +5,9 @@ #include #include +#include +#include + #include #include #include @@ -276,7 +279,7 @@ public: void apply_mask(int mask, uint8_t *patterns); private: - static_assert(V <= 40, "invalid version"); + static_assert(V >= 1 && 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; @@ -286,42 +289,29 @@ public: 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 + static constexpr int N_BYTES = utl::bytes_in_bits(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 + static constexpr int N_DAT_BYTES = utl::bytes_in_bits(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]; + uint8_t get_arr_bit(uint8_t *arr, unsigned bit) const { + return utl::get_arr_bit(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; + void set_arr_bit(uint8_t *arr, unsigned bit) { + utl::set_arr_bit(arr, bit); } /// @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; + void clr_arr_bit(uint8_t *arr, unsigned bit) { + utl::clr_arr_bit(arr, bit); } - uint8_t code[N_BITS] = {0}; + uint8_t code[N_BYTES] = {}; bool status = false; }; diff --git a/Private/NewBoot/BootKit/Vendor/QrVendor/base.h b/Private/NewBoot/BootKit/Vendor/QrVendor/base.h new file mode 100644 index 00000000..d8261d1e --- /dev/null +++ b/Private/NewBoot/BootKit/Vendor/QrVendor/base.h @@ -0,0 +1,25 @@ +#ifndef UTL_BASE_H +#define UTL_BASE_H + +#include +#include +#include + +namespace utl { + +/** + * @brief Helper to get number of elements in array. + * + * @tparam T Auto-deduced element type + * @tparam N Auto-deduced number of elements + * @return Array size + */ +template +constexpr size_t countof(T(&)[N]) +{ + return N; +} + +} + +#endif \ No newline at end of file diff --git a/Private/NewBoot/BootKit/Vendor/QrVendor/bit.h b/Private/NewBoot/BootKit/Vendor/QrVendor/bit.h new file mode 100644 index 00000000..646151b6 --- /dev/null +++ b/Private/NewBoot/BootKit/Vendor/QrVendor/bit.h @@ -0,0 +1,245 @@ +#ifndef UTL_BIT_H +#define UTL_BIT_H + +#include + +namespace utl { + +/** + * @brief Size of object in terms of bits. + * + * @tparam T Object type + * @return Number of bits + */ +template +constexpr auto bit_size() +{ + return sizeof(T) * 8; +} + +/** + * @brief Integer with all bits set to 1. + * + * @tparam T Integer type + * @return All set integer + */ +template +constexpr T bit_full() +{ + return T(-1); +} + +/** + * @brief Wrap around mask for power of two number of bits + * within given integer type. For example: + * [ bit_wrap = 8 - 1 = 0b111 ] + * [ bit_wrap = 16 - 1 = 0b1111 ] + * [ bit_wrap = 32 - 1 = 0b11111 ] + * + * @tparam T Integer type + * @return Wrap around mask for number of bits + */ +template +constexpr T bit_wrap() +{ + return bit_size() - 1; +} + +/** + * @brief Number of bits to fit bit_wrap result, in other words + * bit width of (sizeof(T) * 8 - 1). For example: + * [ bit_shft = bit_width(0b111) = 3 ] + * [ bit_shft = bit_width(0b1111) = 4 ] + * [ bit_shft = bit_width(0b11111) = 5 ] + * + * @tparam T Integer type + * @return Number of bits to shift to divide by sizeof(T) * 8 + */ +template +constexpr auto bit_shft() +{ + return std::bit_width(bit_wrap()); +} + +/** + * @brief Round up division by number of bits within given integer type, + * which sizeof(T) * 8 is power of two. + * + * @tparam T Inetegr type + * @param x Dividend + * @return Quotient + */ +template +constexpr auto bit_ceil(auto x) +{ + return (x + bit_wrap()) >> bit_shft(); +} + +/** + * @brief Count leading zeros. + * + * @param x Unsigned integer argument + * @return Number of leading zeros + */ +constexpr unsigned cntlz(auto x) +{ + if constexpr (std::is_same_v) + return std::countl_zero(unsigned(x)); + else + return std::countl_zero(x); +} + +/** + * @brief Count trailing zeros. + * + * @param x Unsigned integer argument + * @return Number of trailing zeros + */ +constexpr unsigned cnttz(auto x) +{ + if constexpr (std::is_same_v) + return std::countr_zero(unsigned(x)); + else + return std::countr_zero(x); +} + +/** + * @brief Get number of words (integers) required to store N bits. + * + * @tparam T Word integer type + * @param n Number of bits to store + * @return Number of words + */ +template +constexpr size_t words_in_bits(size_t n) +{ + return (n >> bit_shft()) + !!(n & bit_wrap()); +} + +/** + * @brief Get number of bytes required to store N bits. + * + * @param n Number of bits to store + * @return Number of bytes + */ +constexpr size_t bytes_in_bits(size_t n) +{ + return words_in_bits(n); +} + +/** + * @brief Make integer with bit at given position. + * + * @tparam T Inetegr type + * @param n Bit position + * @return Integer with set bit + */ +template +constexpr T bit(int n) +{ + return T(1) << n; +} + +/** + * @brief Get n-th bit of an integer. + * + * @tparam T Integer type + * @param x Integer + * @param n Bit position from LSB + * @return true if set + */ +template +constexpr bool get_bit(T x, int n) +{ + return (x >> n) & 1; +} + +/** + * @brief Set n-th bit of an integer. + * + * @tparam T Integer type + * @param x Integer + * @param n Bit position from LSB + */ +template +constexpr void set_bit(T& x, int n) +{ + x |= 1 << n; +} + +/** + * @brief Clear n-th bit of an integer. + * + * @tparam T Integer type + * @param x Integer + * @param n Bit position from LSB + */ +template +constexpr void clr_bit(T& x, int n) +{ + x &= ~(1 << n); +} + +/** + * @brief Get n-th bit in array of words (starting from LSB). + * + * @tparam T Word type + * @param p Array of words + * @param n Index of bit to get + * @return true if set + */ +template +constexpr bool get_arr_bit(const T* p, unsigned n) +{ + return get_bit(p[n >> bit_shft()], n & bit_wrap()); +} + +/** + * @brief Set n-th bit in array of words (starting from LSB). + * + * @tparam T Word type + * @param p Array of words + * @param n Index of bit to set + */ +template +constexpr void set_arr_bit(T* p, unsigned n) +{ + set_bit(p[n >> bit_shft()], n & bit_wrap()); +} + +/** + * @brief Clear n-th bit in array of words (starting from LSB). + * + * @tparam T Word type + * @param p Array of words + * @param n Index of bit to clear + */ +template +constexpr void clr_arr_bit(T* p, unsigned n) +{ + clr_bit(p[n >> bit_shft()], n & bit_wrap()); +} + +/** + * @brief Shift bits left in array of integer elements from least significant bit + * and considering 0-th byte as the right most. + * uint16_t example: 0b10000000'11100001 ==> 0b00000001'11000010. + * + * @tparam T Integer type + * @tparam L Length of array + * @param x Array of integers, nullptr not acceptable! + * @param len Number of elements + */ +template +constexpr void shift_left(T (&x)[L]) +{ + for (int i = L - 1; i > 0; --i) { + x[i] <<= 1; + x[i] |= x[i - 1] >> bit_wrap(); + } + x[0] <<= 1; +} + +} + +#endif diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index aab5db1f..0e126ada 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -66,7 +66,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r\n"); - EFI::RaiseHardError(L"NoSuchVolume", L"No Such volume."); + EFI::ThrowError(L"NoSuchVolume", L"No Such volume."); this->mErrorCode = kNotSupported; return; } @@ -78,7 +78,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ") .Write(mPath) .Write(L"\r\n"); - EFI::RaiseHardError(L"NoSuchPath", L"No Such file on filesystem."); + EFI::ThrowError(L"NoSuchPath", L"No Such file on filesystem."); this->mErrorCode = kNotSupported; return; } @@ -110,7 +110,7 @@ Void BFileReader::ReadAll(SizeT until, SizeT chunk) { if (auto err = BS->AllocatePool(EfiLoaderCode, until, (VoidPtr*)&mBlob) != kEfiOk) { mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r\n"); - EFI::RaiseHardError(L"NewBoot_PageError", L"Allocation error."); + EFI::ThrowError(L"NewBoot_PageError", L"Allocation error."); } } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index d314c949..7120bcd9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -67,7 +67,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) != kEfiOk) { - EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!"); + EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!"); } /**** @@ -80,7 +80,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor), (VoidPtr*)&Descriptor) != kEfiOk) { - EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!"); + EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!"); } HEL::HandoverInformationHeader* handoverHdrPtr = nullptr; @@ -179,14 +179,14 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, headerKind->Magic[3] == kPefMagic[3] && headerKind->Magic[4] == kPefMagic[4]) { if (headerKind->Abi != kPefAbi || headerKind->Cpu != kPefArchAMD64) { - EFI::RaiseHardError(L"Bad-Architecture", + EFI::ThrowError(L"Bad-Architecture", L"New Boot can't run this architecture."); } NewOS::HEL::BootMainKind main = (NewOS::HEL::BootMainKind) nullptr; if (!main) { - EFI::RaiseHardError(L"Bad-Exec", + EFI::ThrowError(L"Bad-Exec", L"New Boot can't recognize this executable."); } @@ -200,7 +200,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, } } - EFI::RaiseHardError(L"Invalid-PEF-Executable", L"PEF executable expected. Got something else."); + EFI::ThrowError(L"Invalid-PEF-Executable", L"PEF executable expected. Got something else."); return kEfiFail; } diff --git a/Private/NewLoader/Source/.gitkeep b/Private/NewLoader/Source/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/makefile b/Private/makefile index 41f70c81..673a4b56 100644 --- a/Private/makefile +++ b/Private/makefile @@ -28,10 +28,12 @@ COPY = cp # Add assembler, linker, and object files variables. ASMFLAGS = -f win64 + +# NewOS subsystem is 17. LDFLAGS = -e Main --subsystem=17 LDOBJ = Objects/*.obj -# This file is the kernel, responsible of task management, memory, drivers and more. +# This file is the kernel, responsible of task management and memory. KERNEL = NewKernel.exe # The kernel entrypoint @@ -39,6 +41,7 @@ SCRIPT = --script=Linker/Platforms/PC.lds .PHONY: error error: + @echo "=== ERROR ===" @echo "=> Use a specific target." MOVEALL=./MoveAll.sh -- cgit v1.2.3 From 4b7ec5d5d2351f47f3ce423147b956247997d532 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 10:12:17 +0200 Subject: MHR-16: Update EPM specs. Signed-off-by: Amlal El Mahrouss --- Private/FirmwareKit/EPM.hxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Private/FirmwareKit') diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx index b7f77742..3b3585be 100644 --- a/Private/FirmwareKit/EPM.hxx +++ b/Private/FirmwareKit/EPM.hxx @@ -29,6 +29,7 @@ typedef struct BlockGUID { /** * @brief The EPM bootloader block. + * @note NumBlock and LbaStart are ignored on UEFI. */ struct PACKED BootBlock { NewOS::Char Magic[kEPMMagicLength]; @@ -42,7 +43,7 @@ struct PACKED BootBlock { /** * @brief The EPM partition block. - * used to describe a partition inside a media. + * used to describe a partition inside a media, doesn't exist on uefi. */ struct PACKED PartitionBlock { NewOS::Char Name[kEPMNameLength]; @@ -75,6 +76,10 @@ struct PACKED PartitionBlock { #define kEPMMagicPPC "EPMPC" +/* @brief UEFI magic for EPM */ + +#define kEPMMagicUEFI "EPMUE" + /* @brief Invalid magic for EPM */ #define kEPMMagicError "EPM??" @@ -109,7 +114,10 @@ typedef struct PartitionBlock PartitionBlockType; #define kEPMStartPartitionBlk (0) ///! @brief Current EPM revision (2) -#define kEPMRevision (21) +#define kEPMRevision (2) + +///! @brief Current EPM revision (2) +#define kEPMRevisionUEFI (0xF) /// END SPECS -- cgit v1.2.3 From 8b46ad6f40df85c1939196f0f75e46d212193756 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 10:21:19 +0200 Subject: MHR-16: Prevent other EFI from booting. Signed-off-by: Amlal El Mahrouss --- Private/FirmwareKit/EFI/API.hxx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Private/FirmwareKit') diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx index 0e2ef200..093d10b3 100644 --- a/Private/FirmwareKit/EFI/API.hxx +++ b/Private/FirmwareKit/EFI/API.hxx @@ -121,6 +121,13 @@ inline void InitEFI(EfiSystemTable *SystemTable) noexcept { ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); ST->ConOut->EnableCursor(ST->ConOut, false); + + if (ST->FirmwareVendor[0] != '@' || + ST->FirmwareVendor[1] != 'M' || + ST->FirmwareVendor[1] != 'H' || + ST->FirmwareVendor[1] != 'R') { + EFI::ThrowError(L"Unsupported Firmware", L"Firmware is unsupported, please build OVMF by yourself."); + } } #ifdef __BOOTLOADER__ -- cgit v1.2.3 From d3c9b5287789534340146ffdb696f67aa8b7308d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 12:12:19 +0200 Subject: MHR-16: Format, and revert previous staged commit. Signed-off-by: Amlal El Mahrouss --- Private/FirmwareKit/EFI/API.hxx | 7 ------- Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 18 +++++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'Private/FirmwareKit') diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx index 093d10b3..0e2ef200 100644 --- a/Private/FirmwareKit/EFI/API.hxx +++ b/Private/FirmwareKit/EFI/API.hxx @@ -121,13 +121,6 @@ inline void InitEFI(EfiSystemTable *SystemTable) noexcept { ST->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); ST->ConOut->EnableCursor(ST->ConOut, false); - - if (ST->FirmwareVendor[0] != '@' || - ST->FirmwareVendor[1] != 'M' || - ST->FirmwareVendor[1] != 'H' || - ST->FirmwareVendor[1] != 'R') { - EFI::ThrowError(L"Unsupported Firmware", L"Firmware is unsupported, please build OVMF by yourself."); - } } #ifdef __BOOTLOADER__ diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index cdbb2f36..356db88b 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -4,13 +4,13 @@ ------------------------------------------- */ -#include -#include #include #include +#include #include #include #include +#include /** Graphics related. */ @@ -178,16 +178,19 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, containerKind->Magic[2] == kPefMagic[2] && containerKind->Magic[3] == kPefMagic[3] && containerKind->Magic[4] == kPefMagic[4]) { - if (containerKind->Abi != kPefAbi || containerKind->Cpu != kPefArchAMD64) { + if (containerKind->Abi != kPefAbi || + containerKind->Cpu != kPefArchAMD64) { EFI::ThrowError(L"Bad-Architecture", - L"New Boot can't run this architecture."); + L"New Boot can't run this architecture."); } - NewOS::HEL::BootMainKind main = reinterpret_cast(containerKind + containerKind->Start); + NewOS::HEL::BootMainKind main = + reinterpret_cast(containerKind + + containerKind->Start); if (!main) { EFI::ThrowError(L"Bad-Exec", - L"New Boot can't recognize this executable."); + L"New Boot can't recognize this executable."); } EFI::ExitBootServices(MapKey, ImageHandle); @@ -200,7 +203,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, } } - EFI::ThrowError(L"Invalid-PEF-Executable", L"PEF executable expected. Got something else."); + EFI::ThrowError(L"Invalid-PEF-Executable", + L"PEF executable expected. Got something else."); return kEfiFail; } -- cgit v1.2.3