From 6d7e78543509af471568cf698c58a9f526dba129 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 10:25:09 +0100 Subject: See below. Stage 1: Create API for Partition read 'EFIPartitionManager' is the main class behind it, there is still some design to do. Signed-off-by: Amlal El Mahrouss --- Private/KernelKit/DriveManager.hpp | 1 + Private/KernelKit/FileManager.hpp | 1 + Private/KernelKit/PEF.hpp | 1 + 3 files changed, 3 insertions(+) (limited to 'Private/KernelKit') diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp index da478a45..223414d2 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hpp @@ -29,6 +29,7 @@ enum { kEPMDrive = 0x11, // Explicit Partition Map. kEPTDrive = 0x12, // ESP w/ EPM partition. kMBRDrive = 0x13, // IBM PC classic partition scheme + kDriveCnt = 9, }; typedef Int64 DriveID; diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp index 6ed713c4..b65bdfe1 100644 --- a/Private/KernelKit/FileManager.hpp +++ b/Private/KernelKit/FileManager.hpp @@ -39,6 +39,7 @@ enum { kFileReadAll = 101, kFileReadChunk = 102, kFileWriteChunk = 103, + kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, }; typedef VoidPtr NodePtr; diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index afa43968..8c67c6ae 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -31,6 +31,7 @@ enum { kPefArchRISCV, kPefArch64x0, /* 64x000. */ kPefArch32x0, + kPefArchCount = (kPefArch32x0 - kPefArchIntel86S) + 1, kPefArchInvalid = 0xFF, }; -- cgit v1.2.3 From 54a426e7d11eb12a8c3710f3632b7084edf423fd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 12:46:54 +0100 Subject: See below. - Implement Framebuffer object. - Print Firmware name in NewBoot. Signed-off-by: Amlal El Mahrouss --- Private/KernelKit/Framebuffer.hpp | 82 ++++++++++++------------- Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 4 +- Private/Source/Framebuffer.cxx | 48 +++++++-------- 3 files changed, 66 insertions(+), 68 deletions(-) (limited to 'Private/KernelKit') diff --git a/Private/KernelKit/Framebuffer.hpp b/Private/KernelKit/Framebuffer.hpp index 6dc94a3b..8ad23571 100644 --- a/Private/KernelKit/Framebuffer.hpp +++ b/Private/KernelKit/Framebuffer.hpp @@ -13,47 +13,45 @@ #include #include -namespace HCore -{ - enum class FramebufferColorKind : UChar - { - RGB32, - RGB16, - RGB8, - INVALID, - }; - - class FramebufferContext final - { - public: - UIntPtr m_Base; - UIntPtr m_Bpp; - UInt m_Width; - UInt m_Height; - - }; - - class Framebuffer final - { - public: - Framebuffer(Ref &addr); - ~Framebuffer(); - - Framebuffer &operator=(const Framebuffer &) = delete; - Framebuffer(const Framebuffer &) = default; - - volatile UIntPtr* operator[](const UIntPtr &width_and_height); - operator bool(); - - const FramebufferColorKind& Color(const FramebufferColorKind &colour = FramebufferColorKind::INVALID); - - Ref& Leak(); - - private: - Ref m_FrameBufferAddr; - FramebufferColorKind m_Colour; - - }; -} // namespace HCore +namespace HCore { +enum class FramebufferColorKind : UChar { + RGB32, + RGB16, + RGB8, + INVALID, +}; + +class FramebufferContext final { + public: + UIntPtr m_Base; + UIntPtr m_Bpp; + UInt m_Width; + UInt m_Height; +}; + +class Framebuffer final { + public: + Framebuffer(Ref &addr) : m_FrameBufferAddr(addr) {} + ~Framebuffer() {} + + Framebuffer &operator=(const Framebuffer &) = delete; + Framebuffer(const Framebuffer &) = default; + + volatile UIntPtr *operator[](const UIntPtr &width_and_height); + + operator bool() { + return m_FrameBufferAddr && m_Colour != FramebufferColorKind::INVALID; + } + + const FramebufferColorKind &Color( + const FramebufferColorKind &colour = FramebufferColorKind::INVALID); + + Ref &Leak(); + + private: + Ref m_FrameBufferAddr; + FramebufferColorKind m_Colour; +}; +} // namespace HCore #endif /* ifndef __INC_FB_HPP__ */ diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index d1d230b6..d06338b5 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -19,7 +19,9 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, KeInitEFI(SystemTable); BTextWriter writer; - writer.WriteString(L"HCoreLdr: Booting from \\Volume0\\...") + writer.WriteString(L"HCoreLdr: Firmware: ") + .WriteString(SystemTable->FirmwareVendor) + .WriteString(L"\r\nHCoreLdr: Booting on \\Volume0\\ (FAT32)") .WriteString(L"\r\n"); UInt64 mapKey = 0; diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx index 251cdb93..3b8fa229 100644 --- a/Private/Source/Framebuffer.cxx +++ b/Private/Source/Framebuffer.cxx @@ -1,36 +1,34 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ +/* ------------------------------------------- -#include + Copyright Mahrouss Logic -namespace HCore { -Framebuffer::Framebuffer(HCore::Ref& addr) - : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) {} + File: Framebuffer.cxx + Purpose: EFI C++ library -Framebuffer::~Framebuffer() = default; + Revision History: -volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) { - if (m_FrameBufferAddr) - return reinterpret_cast( - m_FrameBufferAddr->m_Base + width_and_height); + 01/02/24: Added file (amlel) - return nullptr; -} +------------------------------------------- */ -Ref& Framebuffer::Leak() { return m_FrameBufferAddr; } +#include -Framebuffer::operator bool() { return m_FrameBufferAddr; } +using namespace HCore; -const FramebufferColorKind& Framebuffer::Color( - const FramebufferColorKind& colour) { - if (colour != FramebufferColorKind::INVALID) m_Colour = colour; +volatile UIntPtr *Framebuffer::operator[](const UIntPtr &width_and_height) { + return (UIntPtr *)(m_FrameBufferAddr->m_Base * width_and_height); +} + +const FramebufferColorKind &Framebuffer::Color( + const FramebufferColorKind &colour) { + if (m_Colour != FramebufferColorKind::INVALID && + colour != FramebufferColorKind::INVALID) { + m_Colour = colour; + } return m_Colour; } -} // namespace HCore + +Ref &Framebuffer::Leak() { + return this->m_FrameBufferAddr; +} -- cgit v1.2.3 From 4efd7b8a6608a9299ef8cc750c264a3be0cb12e7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 14:41:18 +0100 Subject: HCR-9 : Update EFIKit, working on Volume API. HCR-9 Related: - New EfiMountVolume, EfiUnmountVolume. Kernel Related: - Update Shared Object API, it was lacking a cleanup routine. - Add __mh_purecall as a C linked symbol for unknown symbols. Signed-off-by: Amlal El Mahrouss --- Private/EFIKit/EFILib.hxx | 6 +- Private/HALKit/AMD64/DebugManager.asm | 2 - Private/KernelKit/PEFSharedObject.hxx | 39 ++++++------ Private/NewKit/Macros.hpp | 12 ++-- Private/Source/PEFCodeManager.cxx | 2 +- Private/Source/PEFSharedObjectMain.cxx | 58 ------------------ Private/Source/PEFSharedObjectRT.cxx | 107 +++++++++++++++++++++++++++++++++ 7 files changed, 140 insertions(+), 86 deletions(-) delete mode 100644 Private/Source/PEFSharedObjectMain.cxx create mode 100644 Private/Source/PEFSharedObjectRT.cxx (limited to 'Private/KernelKit') diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx index 3f041e37..fcd5df7d 100644 --- a/Private/EFIKit/EFILib.hxx +++ b/Private/EFIKit/EFILib.hxx @@ -68,7 +68,11 @@ enum { kPartCnt, }; -class EFIPartitionManager final {}; +typedef EfiHandlePtr* EfiFilesystemHandlePtr; + +EfiFilesystemHandlePtr EfiMountVolume(const EfiCharType* MountPath, + Int32 PartitionType); +Boolean EfiUnmountVolume(EfiFilesystemHandlePtr Handle); #ifdef __BOOTLOADER__ #include diff --git a/Private/HALKit/AMD64/DebugManager.asm b/Private/HALKit/AMD64/DebugManager.asm index cf3a4539..5cc0cd10 100644 --- a/Private/HALKit/AMD64/DebugManager.asm +++ b/Private/HALKit/AMD64/DebugManager.asm @@ -14,8 +14,6 @@ __rt_debug_record_table: db "DebugMgr/HCore", 0xa, 0xd, 0 - ;; User Data goes there - resb 64 __rt_debug_int_3: push 0x6677 ;; Debug check error ;; then halt and goes back to L0, thens halts... diff --git a/Private/KernelKit/PEFSharedObject.hxx b/Private/KernelKit/PEFSharedObject.hxx index af90858e..263f08f4 100644 --- a/Private/KernelKit/PEFSharedObject.hxx +++ b/Private/KernelKit/PEFSharedObject.hxx @@ -16,10 +16,13 @@ #include namespace HCore { - /** - * @brief Shared Library class - * Load library from this class - */ +/// @brief Pure implementation, missing method/function handler. +extern "C" void __mh_purecall(void); + +/** + * @brief Shared Library class + * Load library from this class + */ class SharedObject final { public: struct SharedObjectTraits final { @@ -44,9 +47,7 @@ class SharedObject final { public: void Mount(SharedObjectTraits *to_mount) { - if (!to_mount || - !to_mount->fImageObject) - return; + if (!to_mount || !to_mount->fImageObject) return; fMounted = to_mount; @@ -65,17 +66,18 @@ class SharedObject final { }; template - SymbolType Load(const char *symbol_name) { - auto ret = reinterpret_cast( - fLoader->FindSymbol(symbol_name, kPefCode)); + SymbolType Load(const char *symbol_name, SizeT len, Int32 kind) { + if (symbol_name == nullptr || *symbol_name == 0) return nullptr; + if (len > kPathLen || len < 1) return nullptr; - if (!ret) - ret = reinterpret_cast( - fLoader->FindSymbol(symbol_name, kPefData)); + auto ret = + reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); - if (!ret) - ret = reinterpret_cast( - fLoader->FindSymbol(symbol_name, kPefZero)); + if (!ret) { + if (kind == kPefCode) return (VoidPtr)__mh_purecall; + + return nullptr; + } return ret; } @@ -84,10 +86,7 @@ class SharedObject final { PEFLoader *fLoader{nullptr}; }; -inline void hcore_pure_call(void) { - // virtual placeholder. - return; -} +typedef SharedObject *SharedObjectPtr; } // namespace HCore #endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */ diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp index 02be7180..94fd8fe8 100644 --- a/Private/NewKit/Macros.hpp +++ b/Private/NewKit/Macros.hpp @@ -65,7 +65,7 @@ #endif #ifndef ENUM_STRING -#define ENUM_STRING(NAME, VAL) constexpr const char *NAME = VAL +#define ENUM_STRING(NAME, VAL) inline constexpr const char *NAME = VAL #endif #ifndef END_STRING_ENUM @@ -76,9 +76,13 @@ #define Alloca(Sz) __builtin_alloca(Sz) #endif // #ifndef Alloca -#ifndef CantReach -#define CantReach() __builtin_unreachable() +#ifndef CANT_REACH +#define CANT_REACH() __builtin_unreachable() #endif #define kBadPtr 0xFBFBFBFBFBFBFBFB -#define kmaxAddr 0xFFFFFFFFFFFFFFFF +#define kMaxAddr 0xFFFFFFFFFFFFFFFF +#define kPathLen 255 + +#define PACKED ATTRIBUTE(packed) +#define NO_EXEC ATTRIBUTE(noexec) diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index 8804d1ca..63e8659f 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -7,9 +7,9 @@ * ======================================================== */ -#include #include #include +#include #include #include #include diff --git a/Private/Source/PEFSharedObjectMain.cxx b/Private/Source/PEFSharedObjectMain.cxx deleted file mode 100644 index c1803312..00000000 --- a/Private/Source/PEFSharedObjectMain.cxx +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include -#include - -using namespace HCore; - -/***********************************************************************************/ -/// @file SharedObjectEntry.cxx -/// @brief Shared Object Init code. -/***********************************************************************************/ - -/***********************************************************************************/ -/* @brief Allocate new library to be added to the lookup table. - */ -/***********************************************************************************/ - -extern "C" SharedObject *__LibMain(VoidPtr image) { - SharedObject *library = hcore_tls_new_class(); - - if (!library) { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Mount(hcore_tls_new_class()); - - if (!library->Get()) { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageObject = - ProcessManager::Shared().Leak().GetCurrent().Leak().Image; - - library->Get()->fImageEntrypointOffset = library->Load(kPefStart); - - kcout << "__LibMain: Done jumping to library...\n"; - - return library; -} - -/***********************************************************************************/ diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx new file mode 100644 index 00000000..0b98834c --- /dev/null +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -0,0 +1,107 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include +#include + +#include "NewKit/RuntimeCheck.hpp" + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared library ABI, except a __LibInit and __LibFini + (amlel) + + ------------------------------------------- */ + +using namespace HCore; + +/***********************************************************************************/ +/// @file SharedObjectRT.cxx +/// @brief Shared Object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Allocates a new library. */ +/***********************************************************************************/ + +extern "C" SharedObject *__LibInit() { + SharedObject *library = hcore_tls_new_class(); + + if (!library) { + kcout << "__LibInit: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(hcore_tls_new_class()); + + if (!library->Get()) { + kcout << "__LibInit: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageObject = + ProcessManager::Shared().Leak().GetCurrent().Leak().Image; + + if (!library->Get()->fImageObject) { + kcout << "__LibInit: Invalid image!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageEntrypointOffset = + library->Load(kPefStart, string_length(kPefStart, 0), kPefCode); + + kcout << "__LibMain: Task was successful... Returning library...\n"; + + return library; +} + +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Frees the library. */ +/* @note Please check if the lib got freed! */ +/* @param SharedObjectPtr the library to free. */ +/***********************************************************************************/ + +extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) { + MUST_PASS(successful); + + // sanity check (will also trigger a bug check) + if (lib == nullptr) { + kcout << "__LibFini: Invalid image!\n"; + *successful = false; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} + +/***********************************************************************************/ + +extern "C" void __mh_purecall(void) { + // virtual placeholder. + return; +} -- cgit v1.2.3 From 26ceef5cccbb40b00a302979ed297243b356feff Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 17:00:17 +0100 Subject: Kernel: Some groundwork done, this is a bumping commit. Signed-off-by: Amlal El Mahrouss --- Internal/.gitkeep | 0 Private/EFIKit/EFiLib.cxx | 14 ----------- Private/KernelKit/DebugOutput.hpp | 48 ++++++++++++++++++-------------------- Private/KernelKit/DriveManager.hpp | 2 +- Private/KernelKit/OSErr.hpp | 31 ++++++++++++------------ Private/NewBoot/Source/EFILib.cxx | 14 +++++++++++ 6 files changed, 53 insertions(+), 56 deletions(-) create mode 100644 Internal/.gitkeep delete mode 100644 Private/EFIKit/EFiLib.cxx create mode 100644 Private/NewBoot/Source/EFILib.cxx (limited to 'Private/KernelKit') diff --git a/Internal/.gitkeep b/Internal/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/EFIKit/EFiLib.cxx b/Private/EFIKit/EFiLib.cxx deleted file mode 100644 index b90cfa3a..00000000 --- a/Private/EFIKit/EFiLib.cxx +++ /dev/null @@ -1,14 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - - File: EFILib.hxx - Purpose: EFI C++ library - - Revision History: - - 01/02/24: Added file (amlel) - -------------------------------------------- */ - -#include diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index a651cb8b..875884ba 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -13,28 +13,26 @@ #include #include -namespace HCore -{ - // @brief Emulates a VT100 terminal. - class TerminalDevice final : public DeviceInterface - { - public: - TerminalDevice(void (*print)(const char *), void (*get)(const char *)) : DeviceInterface(print, get) {} - virtual ~TerminalDevice() {} - - /// @brief returns device name (terminal name) - /// @return string type (const char*) - virtual const char* Name() const override { return ("TerminalDevice"); } - - TerminalDevice &operator=(const TerminalDevice &) = default; - TerminalDevice(const TerminalDevice &) = default; - - }; - - namespace Detail - { - bool serial_init(); - } - - extern TerminalDevice kcout; -} // namespace HCore +namespace HCore { +// @brief Emulates a VT100 terminal. +class TerminalDevice final : public DeviceInterface { + public: + TerminalDevice(void (*print)(const char *), void (*get)(const char *)) + : DeviceInterface(print, get) {} + + virtual ~TerminalDevice() {} + + /// @brief returns device name (terminal name) + /// @return string type (const char*) + virtual const char *Name() const override { return ("TerminalDevice"); } + + TerminalDevice &operator=(const TerminalDevice &) = default; + TerminalDevice(const TerminalDevice &) = default; +}; + +namespace Detail { +bool serial_init(); +} + +extern TerminalDevice kcout; +} // namespace HCore diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp index 223414d2..ac39c177 100644 --- a/Private/KernelKit/DriveManager.hpp +++ b/Private/KernelKit/DriveManager.hpp @@ -34,7 +34,7 @@ enum { typedef Int64 DriveID; -// Mounted drive. +/// @brief Mounted drive traits. struct DriveTraits final { char fName[kDriveNameLen]; // /System, /Boot, /USBDevice... Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. diff --git a/Private/KernelKit/OSErr.hpp b/Private/KernelKit/OSErr.hpp index 975de898..62916959 100644 --- a/Private/KernelKit/OSErr.hpp +++ b/Private/KernelKit/OSErr.hpp @@ -11,20 +11,19 @@ #include -namespace HCore -{ - typedef Int32 OSErr; +namespace HCore { +typedef Int32 OSErr; - inline constexpr OSErr kErrorExecutable = 33; - inline constexpr OSErr kErrorExecutableLib = 34; - inline constexpr OSErr kErrorFileNotFound = 35; - inline constexpr OSErr kErrorDirectoryNotFound = 36; - inline constexpr OSErr kErrorDiskReadOnly = 37; - inline constexpr OSErr kErrorDiskIsFull = 38; - inline constexpr OSErr kErrorProcessFault = 39; - inline constexpr OSErr kErrorSocketHangUp = 40; - inline constexpr OSErr kErrorThreadLocalStorage = 41; - inline constexpr OSErr kErrorMath = 42; - inline constexpr OSErr kErrorNoNetwork = 43; - inline constexpr OSErr kErrorHeapOutOfMemory = 44; -} \ No newline at end of file +inline constexpr OSErr kErrorExecutable = 33; +inline constexpr OSErr kErrorExecutableLib = 34; +inline constexpr OSErr kErrorFileNotFound = 35; +inline constexpr OSErr kErrorDirectoryNotFound = 36; +inline constexpr OSErr kErrorDiskReadOnly = 37; +inline constexpr OSErr kErrorDiskIsFull = 38; +inline constexpr OSErr kErrorProcessFault = 39; +inline constexpr OSErr kErrorSocketHangUp = 40; +inline constexpr OSErr kErrorThreadLocalStorage = 41; +inline constexpr OSErr kErrorMath = 42; +inline constexpr OSErr kErrorNoNetwork = 43; +inline constexpr OSErr kErrorHeapOutOfMemory = 44; +} // namespace HCore diff --git a/Private/NewBoot/Source/EFILib.cxx b/Private/NewBoot/Source/EFILib.cxx new file mode 100644 index 00000000..3e30e0d3 --- /dev/null +++ b/Private/NewBoot/Source/EFILib.cxx @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: EFI.cxx + Purpose: EFI Library for NewBoot. + + Revision History: + + 01/02/24: Added file (amlel) + +------------------------------------------- */ + +#include -- cgit v1.2.3