diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-24 09:04:34 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-24 09:04:34 +0100 |
| commit | 917eae9453ecac6d9aeb04254d5d5c97e5a6c9e1 (patch) | |
| tree | 767f6aeabb24f02c119e073e3efd2c710aabed5d | |
| parent | 5563deabd8f7ce3fc713ea23f8cf5bbac33b4024 (diff) | |
Kernel: MS-1: Microkernel and bootloader.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
| -rw-r--r-- | Private/EFIKit/EFI.hxx | 14 | ||||
| -rw-r--r-- | Private/EFIKit/EPM.hxx | 3 | ||||
| -rw-r--r-- | Private/EFIKit/Handover.hxx | 11 | ||||
| -rw-r--r-- | Private/Executives/.gitkeep (renamed from Private/Servers/.gitkeep) | 0 | ||||
| -rw-r--r-- | Private/KernelKit/DeviceManager.hpp | 23 | ||||
| -rw-r--r-- | Private/KernelKit/HError.hpp | 7 | ||||
| -rw-r--r-- | Private/KernelKit/Loader.hpp | 36 | ||||
| -rw-r--r-- | Private/NewBoot/Source/BootMain.cxx | 6 | ||||
| -rw-r--r-- | Private/NewBoot/Source/bundle.mk | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/standard.mk | 1 | ||||
| -rw-r--r-- | Private/NewKit/Defines.hpp | 5 | ||||
| -rw-r--r-- | Private/Source/HError.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/KernelHeap.cxx | 44 | ||||
| -rw-r--r-- | Private/Source/KernelMain.cxx | 22 | ||||
| -rw-r--r-- | Private/Source/NewFS+IO.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/ProcessManager.cxx | 6 | ||||
| -rw-r--r-- | Private/makefile | 2 |
17 files changed, 116 insertions, 70 deletions
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index 2ccbb625..aeadfc01 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -27,7 +27,7 @@ using namespace HCore; #define EFI_API __attribute__((ms_abi)) #endif // ifndef EPI_API -// Forwar decls +// Forward decls struct EfiTableHeader; struct EfiLoadFileProtocol; @@ -244,6 +244,13 @@ typedef struct EfiTableHeader { UInt32 Reserved; } EfiTableHeader; +#define EFI_ACPI_TABLE_PROTOCOL_GUID \ + { \ + 0xffe06bdd, 0x6107, 0x46a6, { \ + 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ + } \ + } + #define EFI_LOAD_FILE_PROTOCOL_GUID \ { \ 0x56EC3091, 0x954C, 0x11d2, { \ @@ -559,7 +566,10 @@ typedef struct EfiSystemTable { VoidPtr RuntimeServices; EfiBootServices *BootServices; UInt64 NumberOfTableEntries; - VoidPtr ConfigurationTable; + struct { + EfiGUID VendorGUID; + VoidPtr VendorTable; + } *ConfigurationTable; } EfiSystemTable; #define EfiMain efi_main diff --git a/Private/EFIKit/EPM.hxx b/Private/EFIKit/EPM.hxx index bd0e07ff..db6b8b2f 100644 --- a/Private/EFIKit/EPM.hxx +++ b/Private/EFIKit/EPM.hxx @@ -8,8 +8,7 @@ */ /** - @brief The Explicit Partition Map is used to tell how many NewFS and other - EPM compatible Filesystems. We have in this computer. + @brief The Explicit Partition Map scheme. */ #ifndef __PARTITION_MAP__ diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx index b668dd60..319a951a 100644 --- a/Private/EFIKit/Handover.hxx +++ b/Private/EFIKit/Handover.hxx @@ -10,7 +10,7 @@ /** * @file Handover.hxx * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) - * @brief Handover protocol. + * @brief The handover boot protocol. * @version 0.2 * @date 2024-02-23 * @@ -66,11 +66,12 @@ struct HandoverInformationHeader { SizeT f_PhysicalSize; WideChar f_FirmwareVendorName[32]; SizeT f_FirmwareVendorLen; - voidPtr f_RsdPtr; - voidPtr f_SmBIOS; - voidPtr f_RTC; - voidPtr f_GOP; + VoidPtr f_AcpiTable; + VoidPtr f_SmBIOS; + VoidPtr f_RTC; + VoidPtr f_GOP; SizeT f_GOPSize; + Boolean f_LiteEdition; }; /** diff --git a/Private/Servers/.gitkeep b/Private/Executives/.gitkeep index e69de29b..e69de29b 100644 --- a/Private/Servers/.gitkeep +++ b/Private/Executives/.gitkeep diff --git a/Private/KernelKit/DeviceManager.hpp b/Private/KernelKit/DeviceManager.hpp index 9a689b26..582d1194 100644 --- a/Private/KernelKit/DeviceManager.hpp +++ b/Private/KernelKit/DeviceManager.hpp @@ -24,6 +24,8 @@ #include <NewKit/ErrorOr.hpp> #include <NewKit/Ref.hpp> +#include "NewKit/KernelCheck.hpp" + namespace HCore { template <typename T> class DeviceInterface; @@ -61,10 +63,18 @@ class DeviceInterface { void (*m_In)(T Data); }; +/// +/// +/// @brief Input Output Buffer +/// Used mainly to communicate between hardware. +/// template <typename T> class IOBuf final { public: - explicit IOBuf(T Dat) : m_Data(Dat) {} + explicit IOBuf(T Dat) : m_Data(Dat) { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } IOBuf &operator=(const IOBuf<T> &) = default; IOBuf(const IOBuf<T> &) = default; @@ -72,8 +82,15 @@ class IOBuf final { ~IOBuf() = default; public: - T operator->() const { return m_Data; } - T &operator[](Size index) const { return m_Data[index]; } + template <typename R> + R operator->() const { + return m_Data; + } + + template <typename R> + R &operator[](Size index) const { + return m_Data[index]; + } private: T m_Data; diff --git a/Private/KernelKit/HError.hpp b/Private/KernelKit/HError.hpp index 0d412154..247608f9 100644 --- a/Private/KernelKit/HError.hpp +++ b/Private/KernelKit/HError.hpp @@ -31,5 +31,8 @@ inline constexpr HError kErrorHeapOutOfMemory = 44; Boolean ke_bug_check(void) noexcept; } // namespace HCore -#define KernIsOk(HERR) (HERR == HCore::kErrorSuccess) -#define KernHasFailed(HERR) (HERR != HCore::kErrorSuccess) +#define IsOk(HERR) (HERR == HCore::kErrorSuccess) +#define HasFailed(HERR) (HERR != HCore::kErrorSuccess) +#define GetLastError() LastError + +inline HCore::HError LastError = 0; diff --git a/Private/KernelKit/Loader.hpp b/Private/KernelKit/Loader.hpp index a293e2e4..36da444f 100644 --- a/Private/KernelKit/Loader.hpp +++ b/Private/KernelKit/Loader.hpp @@ -9,26 +9,24 @@ #pragma once -#include <NewKit/ErrorOr.hpp> -#include <NewKit/Defines.hpp> #include <CompilerKit/CompilerKit.hpp> +#include <NewKit/Defines.hpp> +#include <NewKit/ErrorOr.hpp> -namespace HCore -{ - class Loader - { - public: - Loader() = default; - virtual ~Loader() = default; - - HCORE_COPY_DEFAULT(Loader); +namespace HCore { +/// This interface is used to make loader contracts (MSCOFF, PEF). +class Loader { + public: + Loader() = default; + virtual ~Loader() = default; - public: - virtual const char* Format() = 0; - virtual const char* MIME() = 0; - virtual const char* Path() = 0; - virtual ErrorOr<VoidPtr> LoadStart() = 0; - virtual VoidPtr FindSymbol(const char* name, Int32 kind) = 0; + HCORE_COPY_DEFAULT(Loader); - }; -} + public: + virtual const char* Format() = 0; + virtual const char* MIME() = 0; + virtual const char* Path() = 0; + virtual ErrorOr<VoidPtr> LoadStart() = 0; + virtual VoidPtr FindSymbol(const char* name, Int32 kind) = 0; +}; +} // namespace HCore diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx index 0db90e6f..ea83e1f4 100644 --- a/Private/NewBoot/Source/BootMain.cxx +++ b/Private/NewBoot/Source/BootMain.cxx @@ -11,6 +11,7 @@ #include <BootKit/BootKit.hxx> #include <EFIKit/Api.hxx> +#include <HALKit/AMD64/ACPI/ACPI.hpp> #include <KernelKit/MSDOS.hpp> #include <KernelKit/PE.hpp> #include <NewKit/Ref.hpp> @@ -144,10 +145,11 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, handoverHdrPtr->f_FirmwareVendorLen); #ifdef __BUNDLE_KERNEL__ + handoverHdrPtr->f_LiteEdition = true; writer.WriteString(L"HCoreLite: Exit Boot...").WriteString(L"\r\n"); #else - writer.WriteString(L"HCoreLdr: Load File succeeded, running it...") - .WriteString(L"\r\n"); + handoverHdrPtr->f_LiteEdition = false; + writer.WriteString(L"HCoreLdr: Exit Boot...").WriteString(L"\r\n"); #endif EFI::ExitBootServices(MapKey, ImageHandle); diff --git a/Private/NewBoot/Source/bundle.mk b/Private/NewBoot/Source/bundle.mk index cf4ac376..3f1df9e0 100644 --- a/Private/NewBoot/Source/bundle.mk +++ b/Private/NewBoot/Source/bundle.mk @@ -22,7 +22,7 @@ bootloader-amd64: $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreKrnl.exe cp HCoreKrnl.exe CDROM/EFI/BOOT/BOOTX64.EFI - cp HCoreKrnl.exe CDROM/HCOREKRNL.EXE + cp HCoreKrnl.exe CDROM/HCOREKRNL.DLL cp ../../Root/System/LookAndFeel.css CDROM/LOOK.CSS .PHONY: run-efi-amd64 diff --git a/Private/NewBoot/Source/standard.mk b/Private/NewBoot/Source/standard.mk index fab7453d..2ca70592 100644 --- a/Private/NewBoot/Source/standard.mk +++ b/Private/NewBoot/Source/standard.mk @@ -22,7 +22,6 @@ bootloader-amd64: $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI - cp ../../HCoreKrnl.exe CDROM/HCOREKRNL.EXE && cp ../../Root/System/LookAndFeel.css CDROM/LOOK.CSS .PHONY: run-efi-amd64 run-efi-amd64: diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp index 9a766f5a..a1bbe6b0 100644 --- a/Private/NewKit/Defines.hpp +++ b/Private/NewKit/Defines.hpp @@ -80,6 +80,11 @@ template <typename Args> Args &&move(Args &&arg) { return static_cast<Args &&>(arg); } + +/// Handle type. +typedef struct { + UIntPtr _Unused; +} *Handle; } // namespace HCore #define DEDUCE_ENDIAN(address, value) \ diff --git a/Private/Source/HError.cxx b/Private/Source/HError.cxx index 6722e9d8..b82d4296 100644 --- a/Private/Source/HError.cxx +++ b/Private/Source/HError.cxx @@ -12,5 +12,5 @@ using namespace HCore; namespace HCore { -Boolean ke_bug_check(void) noexcept { return true; } +Boolean ke_bug_check(void) noexcept { return false; } } // namespace HCore diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index fdc4dc4f..a1032394 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -23,22 +23,26 @@ STATIC Ref<PTEWrapper *> kLastWrapper; STATIC PageManager kPageManager; namespace Detail { -/// @brief +/// @brief Kernel heap information block. +/// Located before the address. +/// | HIB | ADDRESS | struct HeapInformationBlock final { - Int16 hMagic; + UInt16 hMagic; Boolean hPresent; - Int64 hSize; Int32 hCRC32; - VoidPtr hPtr; + Int64 hSizeAddress; + VoidPtr hAddress; }; -STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) { +typedef HeapInformationBlock *HeapInformationBlockPtr; + +STATIC VoidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) { for (SizeT indexWrapper = 0; indexWrapper < kHeapMaxWrappers; ++indexWrapper) { if (!kWrapperList[indexWrapper]->Present()) { kWrapperList[indexWrapper] ->Reclaim(); /* very straight-forward as you can see. */ - return reinterpret_cast<voidPtr>( + return reinterpret_cast<VoidPtr>( kWrapperList[indexWrapper]->VirtualAddress()); } } @@ -61,35 +65,35 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { kLastWrapper = wrapper; - Detail::HeapInformationBlock *heapInfo = - reinterpret_cast<Detail::HeapInformationBlock *>( + Detail::HeapInformationBlockPtr heapInfo = + reinterpret_cast<Detail::HeapInformationBlockPtr>( wrapper->VirtualAddress()); - heapInfo->hSize = sz; + heapInfo->hSizeAddress = sz; heapInfo->hMagic = kHeapMagic; heapInfo->hCRC32 = ke_calculate_crc32((Char *)wrapper->VirtualAddress(), sz); - heapInfo->hPtr = (VoidPtr)wrapper->VirtualAddress(); + heapInfo->hAddress = (VoidPtr)wrapper->VirtualAddress(); kWrapperList[kHeapCount] = wrapper; ++kHeapCount; - return reinterpret_cast<voidPtr>(wrapper->VirtualAddress() + + return reinterpret_cast<VoidPtr>(wrapper->VirtualAddress() + sizeof(Detail::HeapInformationBlock)); } /// @brief Declare pointer as free. /// @param ptr the pointer. /// @return -Int32 ke_delete_ke_heap(voidPtr ptr) { +Int32 ke_delete_ke_heap(VoidPtr ptr) { if (ptr) { - Detail::HeapInformationBlock *virtualAddress = - reinterpret_cast<Detail::HeapInformationBlock *>(ptr) - + Detail::HeapInformationBlockPtr virtualAddress = + reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) - sizeof(Detail::HeapInformationBlock); - if (kLastWrapper && - (UIntPtr)virtualAddress->hPtr == kLastWrapper->VirtualAddress()) { + if (kLastWrapper && virtualAddress->hMagic == kHeapMagic && + (UIntPtr)virtualAddress->hAddress == kLastWrapper->VirtualAddress()) { if (kPageManager.Free(kLastWrapper)) { - virtualAddress->hSize = 0UL; + virtualAddress->hSizeAddress = 0UL; virtualAddress->hPresent = false; kLastWrapper->NoExecute(false); return true; @@ -102,12 +106,12 @@ Int32 ke_delete_ke_heap(voidPtr ptr) { for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) { if (kWrapperList[indexWrapper]->VirtualAddress() == - (UIntPtr)virtualAddress->hPtr) { + (UIntPtr)virtualAddress->hAddress) { wrapper = kWrapperList[indexWrapper]; // if page is no more, then mark it also as non executable. if (kPageManager.Free(wrapper)) { - virtualAddress->hSize = 0UL; + virtualAddress->hSizeAddress = 0UL; virtualAddress->hPresent = false; wrapper->NoExecute(false); @@ -126,7 +130,7 @@ Int32 ke_delete_ke_heap(voidPtr ptr) { /// @brief find pointer in kernel heap /// @param ptr the pointer /// @return if it exists. -Boolean kernel_valid_ptr(voidPtr ptr) { +Boolean kernel_valid_ptr(VoidPtr ptr) { if (ptr) { const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr); diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx index e293cbf2..6050c95f 100644 --- a/Private/Source/KernelMain.cxx +++ b/Private/Source/KernelMain.cxx @@ -17,6 +17,9 @@ EXTERN_C void RuntimeMain( HCore::HEL::HandoverInformationHeader* HandoverHeader) { + HCore::kcout << "HCoreKrnl: (R) Version 1.00, (C) MahroussLogic all rights " + "reserved.\n"; + /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = HandoverHeader->f_VirtualStart; @@ -27,12 +30,19 @@ EXTERN_C void RuntimeMain( /// Init the HAL. MUST_PASS(HCore::ke_init_hal()); - /// Mount a New partition. - // HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); - HCore::PEFLoader img("C:/System/HCoreShell.exe"); + if (!HandoverHeader->f_LiteEdition) { + /// Mount a New partition. + HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); + + // Open file from first hard-drive. + HCore::PEFLoader img("A:/System/HCoreShell.exe"); - /// Run the shell. - if (!HCore::Utils::execute_from_image(img)) { - HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); + /// Run the shell. + if (!HCore::Utils::execute_from_image(img)) { + HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); + } + } else { + HCore::kcout << "HCoreKrnl: Setup is starting...\n"; + HCore::kcout << "HCoreKrnl: Mounting drive A:...\n"; } } diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx index a4299f72..681b198a 100644 --- a/Private/Source/NewFS+IO.cxx +++ b/Private/Source/NewFS+IO.cxx @@ -20,6 +20,6 @@ /// @brief This implements NewFS with Device Abstraction in mind. -/// bugs 0 +/// BUGS: 0 #endif // ifdef __FSKIT_NEWFS__ diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 46533f00..4a51acc0 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -21,9 +21,7 @@ ///! bugs = 0 /***********************************************************************************/ -/* This file handles - * The preemptive multitasking of the OS. - * For MT see SMPManager. */ +/* This file handles the process scheduling. /***********************************************************************************/ namespace HCore { @@ -39,7 +37,7 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; } void Process::Crash() { kcout << this->Name << ": Crashed, ExitCode: -1\n"; - MUST_PASS(ke_bug_check()); + MUST_PASS(!ke_bug_check()); this->Exit(-1); } diff --git a/Private/makefile b/Private/makefile index a077b2c9..b233845c 100644 --- a/Private/makefile +++ b/Private/makefile @@ -12,7 +12,7 @@ LDFLAGS = -e Main -shared --subsystem=17 LDOBJ = $(wildcard Obj/*.obj) # This file is the kernel, responsible of task management, memory, drivers and more. -KERNEL = HCoreKrnl.exe +KERNEL = HCoreKrnl.dll # The kernel entrypoint SCRIPT = --script=Linker/Platforms/PC.lds |
