diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-19 08:56:33 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-19 09:18:29 +0200 |
| commit | 7b6e3242a0e136c9a525c25152034f449dbf319c (patch) | |
| tree | da935f0b77530523b8074c64f229012982908265 /Private/NewBoot/BootKit | |
| parent | 0ae4062bfe9936cc9fd2c7bb924442480b067d93 (diff) | |
MHR-5: Made BootKit more portable.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/BootKit')
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 141 |
1 files changed, 44 insertions, 97 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index be16c2c5..da178624 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -11,6 +11,12 @@ #pragma once +/***********************************************************************************/ +/// Framebuffer helpers. +/***********************************************************************************/ + +#define RGB(R, G, B) (UInt32)(0x##R##G##B) + class BTextWriter; class BFileReader; class BFileRunner; @@ -19,6 +25,13 @@ class BVersionString; #include <BootKit/HW/ATA.hxx> #include <CompilerKit/Version.hxx> +/***********************************************************************************/ +/// Include other APIs. +/***********************************************************************************/ + +#include <BootKit/Platform.hxx> +#include <BootKit/Protocol.hxx> + #ifdef __EFI_x86_64__ #define kBootVirtualAddress (0xffffff80000000) #include <FirmwareKit/EFI.hxx> @@ -27,6 +40,8 @@ class BVersionString; #include <FirmwareKit/EPM.hxx> #include <NewKit/Defines.hpp> +#define kMaxReadSize (320) + using namespace NewOS; typedef Char *PEFImagePtr; @@ -88,6 +103,7 @@ class BFileReader final { EfiHandlePtr ImageHandle); ~BFileReader(); + public: Void ReadAll(); enum { @@ -99,15 +115,17 @@ class BFileReader final { kCount, }; - Int32 &Error() { return mErrorCode; } - VoidPtr Blob() { return mBlob; } - EfiFileProtocolPtr File() { return mFile; } - UInt64 &Size() { return mSizeFile; } + /// @brief error code getter. + /// @return the error code. + Int32 &Error(); - UInt64 &Size(const UInt64 &Sz) { - mSizeFile = Sz; - return mSizeFile; - } + /// @brief blob getter. + /// @return the blob. + VoidPtr Blob(); + + /// @breif Size getter. + /// @return the size of the file. + UInt64 &Size(); public: BFileReader &operator=(const BFileReader &) = default; @@ -124,14 +142,13 @@ class BFileReader final { typedef UInt8 *BlobType; -#define kMaxReadSize (320) - -/***********************************************************************************/ -/// Include other APIs. -/***********************************************************************************/ +class BVersionString final { + public: + static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; } +}; -#include <BootKit/Platform.hxx> -#include <BootKit/Protocol.hxx> +/// @brief Bootloader main type. +typedef void (*BootMainKind)(HEL::HandoverInformationHeader *handoverInfo); /***********************************************************************************/ /// Provide some useful processor features. @@ -139,43 +156,17 @@ typedef UInt8 *BlobType; #ifdef __EFI_x86_64__ -inline void Out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -inline void Out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -inline void Out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -inline UInt8 In8(UInt16 port) { - UInt8 value; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -inline UInt16 In16(UInt16 port) { - UInt16 value; - asm volatile("inw %%dx, %%ax" : "=a"(value) : "d"(port)); - - return value; -} - -inline UInt32 In32(UInt16 port) { - UInt32 value; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - /*** * Common processor instructions. */ +EXTERN_C void Out8(UInt16 port, UInt8 value); +EXTERN_C void Out16(UInt16 port, UInt16 value); +EXTERN_C void Out32(UInt16 port, UInt32 value); +EXTERN_C UInt8 In8(UInt16 port); +EXTERN_C UInt16 In16(UInt16 port); +EXTERN_C UInt32 In32(UInt16 port); + EXTERN_C void rt_hlt(); EXTERN_C void rt_cli(); EXTERN_C void rt_sti(); @@ -184,52 +175,8 @@ EXTERN_C void rt_std(); #endif // __EFI_x86_64__ -/***********************************************************************************/ -/// Framebuffer. -/***********************************************************************************/ - -#define RGB(R, G, B) (UInt32)(0x##R##G##B) - -const UInt32 kRgbRed = 0x000000FF; -const UInt32 kRgbGreen = 0x0000FF00; -const UInt32 kRgbBlue = 0x00FF0000; -const UInt32 kRgbBlack = 0x00000000; -const UInt32 kRgbWhite = 0x00FFFFFF; - -#ifdef __EFI_x86_64__ -/** GOP and related. */ -inline EfiGraphicsOutputProtocol *kGop; -inline UInt16 kStride; -inline EfiGUID kGopGuid; - -/** -@brief Inits the QuickTemplate GUI framework. -*/ -inline Void InitGOP() noexcept { - kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); - kGop = nullptr; - - extern EfiBootServices *BS; - - BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr *)&kGop); - - kStride = 4; -} -#endif // __EFI_x86_64__ - -class BVersionString final { - public: - static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; } -}; - -/// @brief Writes an EPM partition on the main disk. -/// @param namePart the partition's name -/// @param namePartLength the partition name's length -/// @param bootDev the disk interface. -/// @return -EXTERN_C Boolean boot_write_epm_partition(const Char *namePart, - SizeT namePartLength, - BootDevice *bootDev); - -/// @brief Bootloader main type. -typedef void (*BootMainKind)(HEL::HandoverInformationHeader* handoverInfo); +static inline const UInt32 kRgbRed = 0x000000FF; +static inline const UInt32 kRgbGreen = 0x0000FF00; +static inline const UInt32 kRgbBlue = 0x00FF0000; +static inline const UInt32 kRgbBlack = 0x00000000; +static inline const UInt32 kRgbWhite = 0x00FFFFFF; |
