diff options
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/EFIKit/EFILib.hxx | 6 | ||||
| -rw-r--r-- | Private/KernelKit/PE.hpp | 2 | ||||
| -rw-r--r-- | Private/KernelKit/PermissionSelector.hxx | 56 | ||||
| -rw-r--r-- | Private/KernelKit/SharedObjectCore.hxx | 122 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 44 | ||||
| -rw-r--r-- | Private/NewBoot/CxxRuntime/unwind.cxx | 11 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootKit.cxx | 28 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 33 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/Platform.cxx | 4 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 4 |
10 files changed, 117 insertions, 193 deletions
diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx index 1648547b..eac2c618 100644 --- a/Private/EFIKit/EFILib.hxx +++ b/Private/EFIKit/EFILib.hxx @@ -15,12 +15,12 @@ inline EfiSystemTable* ST = nullptr; inline EfiBootServices* BS = nullptr; -namespace Detail { +namespace EFI { /** @brief Stop Execution of program. @param SystemTable EFI System Table. */ -Void Stop(EfiSystemTable* SystemTable) noexcept { +inline Void Stop(EfiSystemTable* SystemTable) noexcept { while (true) { rt_cli(); rt_halt(); @@ -43,7 +43,7 @@ inline void KeRuntimeStop(const EfiCharType* File, ST->ConOut->OutputString(ST->ConOut, Reason); ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); - Detail::Stop(ST); + EFI::Stop(ST); } #ifdef __BOOTLOADER__ diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp index 6ac8d428..5bb5d831 100644 --- a/Private/KernelKit/PE.hpp +++ b/Private/KernelKit/PE.hpp @@ -36,7 +36,7 @@ struct ExecHeader final { #define kMagPE32 0x010b #define kMagPE64 0x020b -struct ExecOptionalHeader { +struct ExecOptionalHeader final { U16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) U8 mMajorLinkerVersion; U8 mMinorLinkerVersion; diff --git a/Private/KernelKit/PermissionSelector.hxx b/Private/KernelKit/PermissionSelector.hxx index 805d29ff..0fe33c29 100644 --- a/Private/KernelKit/PermissionSelector.hxx +++ b/Private/KernelKit/PermissionSelector.hxx @@ -14,47 +14,43 @@ #include <NewKit/Defines.hpp> // kernel mode user. -#define kMachineUser "machine" +#define kMachineUser "Machine" // user mode users. -#define kSuperUser "super" -#define kGuestUser "guest" +#define kSuperUser "Admin" +#define kGuestUser "Guest" // hash 'user@host:password' -> base64 encoded data // use this data to then fetch specific data. -namespace HCore -{ - enum class RingKind - { - kRingUser = 3, - kRingDriver = 2, - kRingKernel = 0, - kUnknown = -1, - }; +namespace HCore { +enum class RingKind { + kRingUser = 3, + kRingDriver = 2, + kRingKernel = 0, + kUnknown = -1, +}; - class PermissionSelector final - { - private: - explicit PermissionSelector(const Int32& sel); - explicit PermissionSelector(const RingKind& kind); +class PermissionSelector final { + private: + explicit PermissionSelector(const Int32& sel); + explicit PermissionSelector(const RingKind& kind); - ~PermissionSelector(); + ~PermissionSelector(); - public: - HCORE_COPY_DEFAULT(PermissionSelector) + public: + HCORE_COPY_DEFAULT(PermissionSelector) - public: - bool operator==(const PermissionSelector& lhs); - bool operator!=(const PermissionSelector& lhs); + public: + bool operator==(const PermissionSelector& lhs); + bool operator!=(const PermissionSelector& lhs); - public: - const RingKind& Ring() noexcept; + public: + const RingKind& Ring() noexcept; - private: - RingKind fRing; - - }; -} + private: + RingKind fRing; +}; +} // namespace HCore #endif /* ifndef _INC_PERMISSION_SEL_HPP */ diff --git a/Private/KernelKit/SharedObjectCore.hxx b/Private/KernelKit/SharedObjectCore.hxx index afda0080..b896a9dc 100644 --- a/Private/KernelKit/SharedObjectCore.hxx +++ b/Private/KernelKit/SharedObjectCore.hxx @@ -11,85 +11,75 @@ #define __KERNELKIT_SHARED_OBJECT_CORE_HXX__ #include <KernelKit/CodeManager.hpp> -#include <KernelKit/PEF.hpp> #include <KernelKit/Loader.hpp> +#include <KernelKit/PEF.hpp> #include <NewKit/Defines.hpp> -namespace HCore -{ -class SharedObject final -{ - public: - struct SharedObjectTraits final - { - VoidPtr fImageObject; - VoidPtr fImageEntrypointOffset; - }; - - public: - explicit SharedObject() = default; - ~SharedObject() = default; - - public: - HCORE_COPY_DEFAULT(SharedObject); - - private: - SharedObjectTraits *fMounted{nullptr}; - - public: - SharedObjectTraits **GetAddressOf() - { - return &fMounted; - } - SharedObjectTraits *Get() - { - return fMounted; +namespace HCore { +class SharedObject final { + public: + struct SharedObjectTraits final { + VoidPtr fImageObject; + VoidPtr fImageEntrypointOffset; + }; + + public: + explicit SharedObject() = default; + ~SharedObject() = default; + + public: + HCORE_COPY_DEFAULT(SharedObject); + + private: + SharedObjectTraits *fMounted{nullptr}; + + public: + SharedObjectTraits **GetAddressOf() { return &fMounted; } + + SharedObjectTraits *Get() { return fMounted; } + + public: + void Mount(SharedObjectTraits *to_mount) { + fMounted = to_mount; + + if (fLoader && to_mount) { + delete fLoader; + fLoader = nullptr; } - public: - void Mount(SharedObjectTraits *to_mount) - { - fMounted = to_mount; - - if (fLoader && to_mount) - { - delete fLoader; - fLoader = nullptr; - } - - if (!fLoader) - { - fLoader = new PEFLoader(fMounted->fImageObject); - } + if (!fLoader) { + fLoader = new PEFLoader(fMounted->fImageObject); } - void Unmount() - { - if (fMounted) - fMounted = nullptr; - }; + } - template <typename SymbolType> SymbolType Load(const char *symbol_name) - { - auto ret = reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kPefCode)); + void Unmount() { + if (fMounted) fMounted = nullptr; + }; - if (!ret) - ret = reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kPefData)); + template <typename SymbolType> + SymbolType Load(const char *symbol_name) { + auto ret = reinterpret_cast<SymbolType>( + fLoader->FindSymbol(symbol_name, kPefCode)); - if (!ret) - ret = reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kPefZero)); + if (!ret) + ret = reinterpret_cast<SymbolType>( + fLoader->FindSymbol(symbol_name, kPefData)); - return ret; - } + if (!ret) + ret = reinterpret_cast<SymbolType>( + fLoader->FindSymbol(symbol_name, kPefZero)); + + return ret; + } - private: - PEFLoader *fLoader{nullptr}; + private: + PEFLoader *fLoader{nullptr}; }; -inline void hcore_pure_call(void) -{ - // virtual placeholder. - return; +inline void hcore_pure_call(void) { + // virtual placeholder. + return; } -} // namespace HCore +} // namespace HCore #endif /* ifndef __KERNELKIT_SHARED_OBJECT_CORE_HXX__ */ diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 70607a9c..9c0ec863 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -18,7 +18,8 @@ using namespace HCore; -typedef void *PEFImage; +typedef VoidPtr PEFImagePtr; +typedef VoidPtr PEImagePtr; enum { kSegmentCode = 2, @@ -26,50 +27,27 @@ enum { kSegmentBss = 6, }; +typedef wchar_t CharacterType; + /** * @brief BootKit Text Writer class * Writes to VGA. */ -class BKTextWriter final { - volatile UInt16 *fWhere{nullptr}; - +class BTextWriter final { public: - void WriteString(const char *c, unsigned char forecolour, - unsigned char backcolour, int x, int y); + void WriteString(const CharacterType *str); - void WriteCharacter(char c, unsigned char forecolour, - unsigned char backcolour, int x, int y); + void WriteCharacter(CharacterType c); public: - BKTextWriter() = default; - ~BKTextWriter() = default; + BTextWriter() = default; + ~BTextWriter() = default; public: - BKTextWriter &operator=(const BKTextWriter &) = default; - BKTextWriter(const BKTextWriter &) = default; -}; - -enum { - kBlack, - kBlue, - kGreen, - kCyan, - kRed, - kMagenta, - kBrown, - kLightGray, - kDarkGray, - kLightBlue, - kLightGreen, - kLightCyan, - kLightRed, - kLightMagenta, - kYellow, - kWhite, + BTextWriter &operator=(const BTextWriter &) = default; + BTextWriter(const BTextWriter &) = default; }; -#define BK_START_KERNEL (0x8000000) - HCore::SizeT BStrLen(const char *ptr); HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len); diff --git a/Private/NewBoot/CxxRuntime/unwind.cxx b/Private/NewBoot/CxxRuntime/unwind.cxx index acfc0b6b..f679bdd5 100644 --- a/Private/NewBoot/CxxRuntime/unwind.cxx +++ b/Private/NewBoot/CxxRuntime/unwind.cxx @@ -1,11 +1,8 @@ -namespace cxxkit -{ +namespace cxxkit { ///! @brief C++ ABI unwinding ///! finis array (r1) ///! n of finis (r2) -extern "C" void __unwind(void (**finis)(void), int cnt) -{ - for (int i = 0; i < cnt; ++i) - (finis[i])(); +extern "C" void __unwind(void (**finis)(void), int cnt) { + for (int i = 0; i < cnt; ++i) (finis[i])(); } -} // namespace cxxkit +} // namespace cxxkit diff --git a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx index 68971e0c..19df55b0 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx @@ -8,8 +8,9 @@ */ #include <BootKit/BootKit.hxx> +#include <EFIKit/EFILib.hxx> -constexpr HCore::UInt32 kVGABaseAddress = 0xb8000; +#include "EFIKit/EFI.hxx" HCore::SizeT BStrLen(const char *ptr) { long long int cnt = 0; @@ -40,29 +41,18 @@ HCore::SizeT BSetMem(char *src, const char byte, const HCore::SizeT len) { /** @brief puts wrapper over VGA. */ -void BKTextWriter::WriteString(const char *str, unsigned char forecolour, - unsigned char backcolour, int x, int y) { +void BTextWriter::WriteString(const CharacterType *str) { if (*str == 0 || !str) return; - for (SizeT idx = 0; idx < BStrLen(str); ++idx) { - this->WriteCharacter(str[idx], forecolour, backcolour, x, y); - ++x; - } + ST->ConOut->OutputString(ST->ConOut, str); } /** @brief putc wrapper over VGA. */ -void BKTextWriter::WriteCharacter(char c, unsigned char forecolour, - unsigned char backcolour, int x, int y) { - UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F); - - // Video Graphics Array - // Reads at kVGABaseAddress - // Decodes UInt16, gets attributes (back colour, fore colour) - // Gets character, send it to video display with according colour in the - // registry. - - fWhere = (volatile UInt16 *)kVGABaseAddress + (y * 80 + x); - *fWhere = c | (attrib << 8); +void BTextWriter::WriteCharacter(CharacterType c) { + EfiCharType str[2]; + str[0] = c; + str[1] = 0; + ST->ConOut->OutputString(ST->ConOut, str); } diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index b3e63bd9..89b3ece2 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -18,38 +18,11 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { KeInitEFI(SystemTable); - SystemTable->ConOut->OutputString(SystemTable->ConOut, - L"HCoreLdr: Initializing...\r\n"); - - EfiLoadImageProtocol* protocol = nullptr; - EfiGUID guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; - - Int32 statusCode = SystemTable->BootServices->OpenProtocol( - ImageHandle, &guid, (VoidPtr*)&protocol, ImageHandle, nullptr, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - if (statusCode != kEfiOk) { - SystemTable->ConOut->OutputString( - SystemTable->ConOut, - L"HCoreLdr: Could not locate EfiLoadImageProtocol! Aborting...\r\n"); - - Detail::Stop(SystemTable); - return kEfiFail; - } - - SystemTable->BootServices->OpenProtocol( - ImageHandle, &guid, (VoidPtr*)&protocol, ImageHandle, ImageHandle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); - - if (SystemTable->BootServices->ExitBootServices(ImageHandle, 0) != kEfiOk) { - SystemTable->ConOut->OutputString( - SystemTable->ConOut, L"HCoreLdr: Could not exit Boot Services!\r\n"); - - Detail::Stop(SystemTable); - } + BTextWriter writer; + writer.WriteString(L"HCoreLdr: Booting from disk...\r\n"); // TODO: Jump Code - Detail::Stop(SystemTable); + EFI::Stop(SystemTable); return kEfiOk; } diff --git a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx index a0c93ab5..f72e0be1 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx @@ -9,8 +9,8 @@ /* * - * @file Processor.cxx - * @brief Processor Specific Functions. + * @file Platform.cxx + * @brief Platform Specific Functions. * */ diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 2e092da2..74ab7878 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -12,8 +12,8 @@ FLAG_GNU=-fshort-wchar -fPIC -D__DBG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I. invalid-recipe: @echo "invalid-recipe: Use make arch-<arch> all instead." -.PHONY: arch-amd64 -arch-amd64: +.PHONY: bootloader-amd64 +bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx $(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI |
