From 5563deabd8f7ce3fc713ea23f8cf5bbac33b4024 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 Feb 2024 02:58:39 +0100 Subject: Kernel: add heap information (allocator) - Force use of itanium ABI even of MPCC. - Revision of handover has been done. (it is not assuming any starting address) Signed-off-by: Amlal El Mahrouss --- Private/EFIKit/Handover.hxx | 5 +-- Private/HALKit/AMD64/HalPageAlloc.cpp | 2 +- Private/NewBoot/Source/FileReader.cxx | 4 +- Private/NewBoot/Source/bundle.mk | 2 +- Private/NewKit/KernelCheck.hpp | 60 +++++++++++++++++++++++++ Private/NewKit/KernelHeap.hpp | 1 - Private/NewKit/NewKit.hpp | 20 ++++----- Private/NewKit/OwnPtr.hpp | 2 +- Private/NewKit/Ref.hpp | 2 +- Private/NewKit/RuntimeCheck.hpp | 60 ------------------------- Private/NewKit/String.hpp | 2 +- Private/NewKit/UserHeap.hpp | 1 - Private/Source/CxxAbi.cxx | 26 ++--------- Private/Source/KernelCheck.cxx | 83 +++++++++++++++++++++++++++++++++++ Private/Source/KernelHeap.cxx | 76 ++++++++++++++++++++++---------- Private/Source/KernelMain.cxx | 6 +-- Private/Source/NewFS+FileManager.cxx | 6 +-- Private/Source/PEFCodeManager.cxx | 2 +- Private/Source/PermissionSelector.cxx | 2 +- Private/Source/ProcessManager.cxx | 2 - Private/Source/RuntimeCheck.cxx | 83 ----------------------------------- Private/Source/ThreadLocalStorage.cxx | 6 +-- Private/Source/UserHeap.cxx | 7 --- 23 files changed, 225 insertions(+), 235 deletions(-) create mode 100644 Private/NewKit/KernelCheck.hpp delete mode 100644 Private/NewKit/RuntimeCheck.hpp create mode 100644 Private/Source/KernelCheck.cxx delete mode 100644 Private/Source/RuntimeCheck.cxx diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx index 42926a3e..b668dd60 100644 --- a/Private/EFIKit/Handover.hxx +++ b/Private/EFIKit/Handover.hxx @@ -11,8 +11,8 @@ * @file Handover.hxx * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) * @brief Handover protocol. - * @version 0.1 - * @date 2024-02-02 + * @version 0.2 + * @date 2024-02-23 * * @copyright Copyright (c) 2024, Mahrouss Logic * @@ -26,7 +26,6 @@ #define kHandoverMagic 0xBADCC -#define kHandoverStartKernel 0xffffffff10000000 #define kHandoverStructSz sizeof(HEL::HandoverHeader) namespace HCore::HEL { diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 64752520..fd691be2 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include // this files handles paging. diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index d81248ea..6696a1b4 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -99,6 +99,8 @@ BFileReader::~BFileReader() { BSetMem(this->mPath, 0, kPathLen); } +#define hTransferBufferAddress 0xffffffff10000000 + /** @brief this reads all of the buffer. @param ImageHandle used internally. @@ -107,7 +109,7 @@ Void BFileReader::ReadAll() { /// Allocate Handover page. if (mBlob == nullptr) { - UInt8* blob = (UInt8*)kHandoverStartKernel; + UInt8* blob = (UInt8*)hTransferBufferAddress; if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1, (EfiPhysicalAddress*)&blob) != kEfiOk) { diff --git a/Private/NewBoot/Source/bundle.mk b/Private/NewBoot/Source/bundle.mk index c5a83ffb..cf4ac376 100644 --- a/Private/NewBoot/Source/bundle.mk +++ b/Private/NewBoot/Source/bundle.mk @@ -28,7 +28,7 @@ bootloader-amd64: .PHONY: run-efi-amd64 run-efi-amd64: wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - qemu-system-x86_64 -net none -smp 2 -m 8G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio + qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio .PHONY: clean clean: diff --git a/Private/NewKit/KernelCheck.hpp b/Private/NewKit/KernelCheck.hpp new file mode 100644 index 00000000..9f37eb8e --- /dev/null +++ b/Private/NewKit/KernelCheck.hpp @@ -0,0 +1,60 @@ + +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include + +namespace HCore { +void ke_runtime_check(bool bExpression, const char *file, const char *line); +} + +#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG) +#define __MUST_PASS(EXPR, FILE, LINE) \ + HCore::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE)) +#define MUST_PASS(EXPR) __MUST_PASS(EXPR, __FILE__, __LINE__) +#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION) + +enum RUNTIME_CHECK { + RUNTIME_CHECK_FAILED = -1, + RUNTIME_CHECK_POINTER = 0, + RUNTIME_CHECK_EXPRESSION, + RUNTIME_CHECK_FILE, + RUNTIME_CHECK_IPC, + RUNTIME_CHECK_TLS, + RUNTIME_CHECK_LD, + RUNTIME_CHECK_HANDSHAKE, + RUNTIME_CHECK_ACPI, + RUNTIME_CHECK_INVALID_PRIVILEGE, + RUNTIME_CHECK_PROCESS, + RUNTIME_CHECK_BAD_BEHAVIOR, + RUNTIME_CHECK_COUNT, + RUNTIME_CHECK_BOOTSTRAP, +}; + +namespace HCore { +class DumpManager final { + public: + static void Dump(void) { + // TODO: + } +}; + +void ke_stop(const Int &id); +} // namespace HCore + +#ifdef TRY +#undef TRY +#endif + +#define TRY(FN) \ + if (!FN()) { \ + MUST_PASS(false); \ + } diff --git a/Private/NewKit/KernelHeap.hpp b/Private/NewKit/KernelHeap.hpp index 80934caf..fba25b70 100644 --- a/Private/NewKit/KernelHeap.hpp +++ b/Private/NewKit/KernelHeap.hpp @@ -17,7 +17,6 @@ #include namespace HCore { -Void ke_init_ke_heap() noexcept; Int32 ke_delete_ke_heap(voidPtr allocatedPtr); voidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user); } // namespace HCore diff --git a/Private/NewKit/NewKit.hpp b/Private/NewKit/NewKit.hpp index 8e560914..fc18a900 100644 --- a/Private/NewKit/NewKit.hpp +++ b/Private/NewKit/NewKit.hpp @@ -10,18 +10,16 @@ #pragma once -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include -#include -#include - - diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp index e24eba3e..69e3389f 100644 --- a/Private/NewKit/OwnPtr.hpp +++ b/Private/NewKit/OwnPtr.hpp @@ -11,8 +11,8 @@ #pragma once #include +#include #include -#include namespace HCore { template diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp index 9988c213..f97e3a90 100644 --- a/Private/NewKit/Ref.hpp +++ b/Private/NewKit/Ref.hpp @@ -11,7 +11,7 @@ #pragma once #include -#include +#include namespace HCore { template diff --git a/Private/NewKit/RuntimeCheck.hpp b/Private/NewKit/RuntimeCheck.hpp deleted file mode 100644 index 9f37eb8e..00000000 --- a/Private/NewKit/RuntimeCheck.hpp +++ /dev/null @@ -1,60 +0,0 @@ - -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include - -namespace HCore { -void ke_runtime_check(bool bExpression, const char *file, const char *line); -} - -#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG) -#define __MUST_PASS(EXPR, FILE, LINE) \ - HCore::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE)) -#define MUST_PASS(EXPR) __MUST_PASS(EXPR, __FILE__, __LINE__) -#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION) - -enum RUNTIME_CHECK { - RUNTIME_CHECK_FAILED = -1, - RUNTIME_CHECK_POINTER = 0, - RUNTIME_CHECK_EXPRESSION, - RUNTIME_CHECK_FILE, - RUNTIME_CHECK_IPC, - RUNTIME_CHECK_TLS, - RUNTIME_CHECK_LD, - RUNTIME_CHECK_HANDSHAKE, - RUNTIME_CHECK_ACPI, - RUNTIME_CHECK_INVALID_PRIVILEGE, - RUNTIME_CHECK_PROCESS, - RUNTIME_CHECK_BAD_BEHAVIOR, - RUNTIME_CHECK_COUNT, - RUNTIME_CHECK_BOOTSTRAP, -}; - -namespace HCore { -class DumpManager final { - public: - static void Dump(void) { - // TODO: - } -}; - -void ke_stop(const Int &id); -} // namespace HCore - -#ifdef TRY -#undef TRY -#endif - -#define TRY(FN) \ - if (!FN()) { \ - MUST_PASS(false); \ - } diff --git a/Private/NewKit/String.hpp b/Private/NewKit/String.hpp index e6bc745e..6979739a 100644 --- a/Private/NewKit/String.hpp +++ b/Private/NewKit/String.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include namespace HCore { class StringView final { diff --git a/Private/NewKit/UserHeap.hpp b/Private/NewKit/UserHeap.hpp index 05430bf4..5c0b7134 100644 --- a/Private/NewKit/UserHeap.hpp +++ b/Private/NewKit/UserHeap.hpp @@ -38,7 +38,6 @@ struct HeapHeader final { UIntPtr Pad; }; -Void ke_init_heap(); VoidPtr ke_new_heap(Int32 flags); Int32 ke_free_heap(voidPtr pointer); } // namespace HCore diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx index c062219b..41c8587b 100644 --- a/Private/Source/CxxAbi.cxx +++ b/Private/Source/CxxAbi.cxx @@ -9,16 +9,16 @@ #include #include -#include - -#ifdef __GNUC__ +#include void *__dso_handle; atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS]; uarch_t __atexit_func_count; -extern "C" void __cxa_pure_virtual() { HCore::kcout << "[C++] Placeholder\n"; } +extern "C" void __cxa_pure_virtual() { + HCore::kcout << "Krnl\\Abi: Placeholder method.\n"; +} extern "C" void ___chkstk_ms() {} @@ -67,21 +67,3 @@ extern "C" int __cxa_guard_release(__guard *g) { extern "C" void __cxa_guard_abort(__guard *g) { (void)g; } } // namespace cxxabiv1 - -#else - -namespace cxxkit { -extern "C" void __unwind(void (**finis)(void), int cnt) { - for (int i = 0; i < cnt; ++i) (finis[i])(); -} - -extern "C" void __init_local(void (**init)(void), int cnt) { - for (int i = 0; i < cnt; ++i) (init[i])(); -} - -extern "C" void __fini_local(void (**finis)(void), int cnt) { - for (int i = 0; i < cnt; ++i) (finis[i])(); -} -} // namespace cxxkit - -#endif diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx new file mode 100644 index 00000000..4fc24918 --- /dev/null +++ b/Private/Source/KernelCheck.cxx @@ -0,0 +1,83 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include + +extern "C" [[noreturn]] void ke_wait_for_debugger() { + while (true) { + HCore::HAL::rt_cli(); + HCore::HAL::rt_halt(); + } +} + +/* Each error code is attributed with an ID, which will prompt a string onto the + * screen. Wait for debugger... */ + +namespace HCore { +void ke_stop(const HCore::Int &id) { + kcout << "*** STOP *** \r\n"; + kcout << "*** HCoreKrnl.exe has trigerred a runtime stop. *** \r\n"; + + switch (id) { + case RUNTIME_CHECK_PROCESS: { + kcout << "*** CAUSE: RUNTIME_CHECK_PROCESS *** \r\n"; + break; + } + case RUNTIME_CHECK_ACPI: { + kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r\n"; + break; + } + case RUNTIME_CHECK_POINTER: { + kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r\n"; + break; + } + case RUNTIME_CHECK_BAD_BEHAVIOR: { + kcout << "*** CAUSE: RUNTIME_CHECK_BAD_BEHAVIOR *** \r\n"; + break; + } + case RUNTIME_CHECK_BOOTSTRAP: { + kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r\n"; + break; + } + case RUNTIME_CHECK_HANDSHAKE: { + kcout << "*** CAUSE: RUNTIME_CHECK_HANDSHAKE *** \r\n"; + break; + } + case RUNTIME_CHECK_LD: { + kcout << "*** CAUSE: RUNTIME_CHECK_LD *** \r\n"; + break; + } + case RUNTIME_CHECK_INVALID_PRIVILEGE: { + kcout << "*** CAUSE: RUNTIME_CHECK_INVALID_PRIVILEGE *** \r\n"; + break; + } + }; + + DumpManager::Dump(); + +#ifdef __DEBUG__ + ke_wait_for_debugger(); +#endif // ifdef __DEBUG__ +} + +void ke_runtime_check(bool expr, const char *file, const char *line) { + if (!expr) { +#ifdef __DEBUG__ + kcout << "Krnl: File: " << file << "\n"; + kcout << "Krnl: Line: " << line << "\n"; + +#endif // __DEBUG__ + + HCore::ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed + } +} +} // namespace HCore diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 10d3fdd2..fdc4dc4f 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -7,22 +7,34 @@ * ======================================================== */ +#include #include //! @file KernelHeap.cpp //! @brief Kernel allocator. -#define kMaxWrappers (4096 * 8) +#define kHeapMaxWrappers (4096 * 8) +#define kHeapMagic 0xAA55 namespace HCore { -static Ref kWrapperList[kMaxWrappers]; -static SizeT kWrapperCount = 0UL; -static Ref kLastWrapper; -static PageManager kPageManager; +STATIC Ref kWrapperList[kHeapMaxWrappers]; +STATIC SizeT kHeapCount = 0UL; +STATIC Ref kLastWrapper; +STATIC PageManager kPageManager; namespace Detail { +/// @brief +struct HeapInformationBlock final { + Int16 hMagic; + Boolean hPresent; + Int64 hSize; + Int32 hCRC32; + VoidPtr hPtr; +}; + STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) { - for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) { + for (SizeT indexWrapper = 0; indexWrapper < kHeapMaxWrappers; + ++indexWrapper) { if (!kWrapperList[indexWrapper]->Present()) { kWrapperList[indexWrapper] ->Reclaim(); /* very straight-forward as you can see. */ @@ -35,7 +47,7 @@ STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) { } } // namespace Detail -/// @brief Page allocation routine. +/// @brief Allocate pointer. /// @param sz size of pointer /// @param rw read write (true to enable it) /// @param user is it accesible by user processes? @@ -49,10 +61,20 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { kLastWrapper = wrapper; - kWrapperList[kWrapperCount] = wrapper; - ++kWrapperCount; + Detail::HeapInformationBlock *heapInfo = + reinterpret_cast( + wrapper->VirtualAddress()); + + heapInfo->hSize = sz; + heapInfo->hMagic = kHeapMagic; + heapInfo->hCRC32 = ke_calculate_crc32((Char *)wrapper->VirtualAddress(), sz); + heapInfo->hPtr = (VoidPtr)wrapper->VirtualAddress(); + + kWrapperList[kHeapCount] = wrapper; + ++kHeapCount; - return reinterpret_cast(wrapper->VirtualAddress()); + return reinterpret_cast(wrapper->VirtualAddress() + + sizeof(Detail::HeapInformationBlock)); } /// @brief Declare pointer as free. @@ -60,10 +82,15 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { /// @return Int32 ke_delete_ke_heap(voidPtr ptr) { if (ptr) { - const UIntPtr virtualAddress = reinterpret_cast(ptr); + Detail::HeapInformationBlock *virtualAddress = + reinterpret_cast(ptr) - + sizeof(Detail::HeapInformationBlock); - if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) { + if (kLastWrapper && + (UIntPtr)virtualAddress->hPtr == kLastWrapper->VirtualAddress()) { if (kPageManager.Free(kLastWrapper)) { + virtualAddress->hSize = 0UL; + virtualAddress->hPresent = false; kLastWrapper->NoExecute(false); return true; } @@ -73,13 +100,18 @@ Int32 ke_delete_ke_heap(voidPtr ptr) { Ref wrapper{nullptr}; - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { + for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) { + if (kWrapperList[indexWrapper]->VirtualAddress() == + (UIntPtr)virtualAddress->hPtr) { wrapper = kWrapperList[indexWrapper]; // if page is no more, then mark it also as non executable. if (kPageManager.Free(wrapper)) { + virtualAddress->hSize = 0UL; + virtualAddress->hPresent = false; + wrapper->NoExecute(false); + return true; } @@ -98,14 +130,17 @@ Boolean kernel_valid_ptr(voidPtr ptr) { if (ptr) { const UIntPtr virtualAddress = reinterpret_cast(ptr); - if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) { + if (kLastWrapper && + virtualAddress == (kLastWrapper->VirtualAddress() + + sizeof(Detail::HeapInformationBlock))) { return true; } Ref wrapper; - for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) { - if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) { + for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) { + if ((kLastWrapper->VirtualAddress() + + sizeof(Detail::HeapInformationBlock)) == virtualAddress) { wrapper = kWrapperList[indexWrapper]; return true; } @@ -114,11 +149,4 @@ Boolean kernel_valid_ptr(voidPtr ptr) { return false; } - -/// @brief The Kernel heap initializer function. -/// @return -Void ke_init_ke_heap() noexcept { - kWrapperCount = 0UL; - Ref kLastWrapper = Ref(nullptr); -} } // namespace HCore diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx index 171deff1..e293cbf2 100644 --- a/Private/Source/KernelMain.cxx +++ b/Private/Source/KernelMain.cxx @@ -24,16 +24,12 @@ EXTERN_C void RuntimeMain( kKernelPhysicalSize = HandoverHeader->f_VirtualSize; kKernelPhysicalStart = HandoverHeader->f_VirtualStart; - /// Init memory managers. - HCore::ke_init_ke_heap(); - HCore::ke_init_heap(); - /// Init the HAL. MUST_PASS(HCore::ke_init_hal()); /// Mount a New partition. // HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); - HCore::PEFLoader img("/System/HCoreShell.exe"); + HCore::PEFLoader img("C:/System/HCoreShell.exe"); /// Run the shell. if (!HCore::Utils::execute_from_image(img)) { diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx index d1ea58f6..51959d0b 100644 --- a/Private/Source/NewFS+FileManager.cxx +++ b/Private/Source/NewFS+FileManager.cxx @@ -11,6 +11,7 @@ #ifdef __FSKIT_NEWFS__ +/// @brief NewFS File manager. /// BUGS: 0 namespace HCore { @@ -18,11 +19,6 @@ NewFilesystemManager::NewFilesystemManager() = default; NewFilesystemManager::~NewFilesystemManager() = default; -/** - * Unallocates a file from disk. - * @param node_name it's path. - * @return operation status boolean. - */ bool NewFilesystemManager::Remove(const char* node_name) { if (node_name == nullptr || *node_name == 0) return false; diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index 68c5b556..ee535057 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -13,9 +13,9 @@ #include #include #include +#include #include #include -#include #include #include "KernelKit/PEF.hpp" diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx index 34760b8f..87680b06 100644 --- a/Private/Source/PermissionSelector.cxx +++ b/Private/Source/PermissionSelector.cxx @@ -11,7 +11,7 @@ */ #include -#include +#include /// bugs 0 diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index ccf037ae..46533f00 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -18,8 +18,6 @@ #include #include -#include "NewKit/RuntimeCheck.hpp" - ///! bugs = 0 /***********************************************************************************/ diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/RuntimeCheck.cxx deleted file mode 100644 index 03660076..00000000 --- a/Private/Source/RuntimeCheck.cxx +++ /dev/null @@ -1,83 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include - -extern "C" [[noreturn]] void ke_wait_for_debugger() { - while (true) { - HCore::HAL::rt_cli(); - HCore::HAL::rt_halt(); - } -} - -/* Each error code is attributed with an ID, which will prompt a string onto the - * screen. Wait for debugger... */ - -namespace HCore { -void ke_stop(const HCore::Int &id) { - kcout << "*** STOP *** \r\n"; - kcout << "*** HCoreKrnl.exe has trigerred a runtime stop. *** \r\n"; - - switch (id) { - case RUNTIME_CHECK_PROCESS: { - kcout << "*** CAUSE: RUNTIME_CHECK_PROCESS *** \r\n"; - break; - } - case RUNTIME_CHECK_ACPI: { - kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r\n"; - break; - } - case RUNTIME_CHECK_POINTER: { - kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r\n"; - break; - } - case RUNTIME_CHECK_BAD_BEHAVIOR: { - kcout << "*** CAUSE: RUNTIME_CHECK_BAD_BEHAVIOR *** \r\n"; - break; - } - case RUNTIME_CHECK_BOOTSTRAP: { - kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r\n"; - break; - } - case RUNTIME_CHECK_HANDSHAKE: { - kcout << "*** CAUSE: RUNTIME_CHECK_HANDSHAKE *** \r\n"; - break; - } - case RUNTIME_CHECK_LD: { - kcout << "*** CAUSE: RUNTIME_CHECK_LD *** \r\n"; - break; - } - case RUNTIME_CHECK_INVALID_PRIVILEGE: { - kcout << "*** CAUSE: RUNTIME_CHECK_INVALID_PRIVILEGE *** \r\n"; - break; - } - }; - - DumpManager::Dump(); - -#ifdef __DEBUG__ - ke_wait_for_debugger(); -#endif // ifdef __DEBUG__ -} - -void ke_runtime_check(bool expr, const char *file, const char *line) { - if (!expr) { -#ifdef __DEBUG__ - kcout << "Krnl: File: " << file << "\n"; - kcout << "Krnl: Line: " << line << "\n"; - -#endif // __DEBUG__ - - HCore::ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed - } -} -} // namespace HCore diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 8aeb0431..9a9c8477 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -29,7 +29,7 @@ Boolean hcore_tls_check(VoidPtr ptr) { const char* _ptr = (const char*)ptr; - kcout << "TLS: Checking for cookie...\n"; + kcout << "Krnl\\TLS: Checking for cookie...\n"; return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && _ptr[2] == kCookieMag2; @@ -42,9 +42,9 @@ Boolean hcore_tls_check(VoidPtr ptr) { */ Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept { if (!hcore_tls_check(ptr.Cookie)) { - kcout << "TLS: Verification failure, Crashing...\n"; + kcout << "Krnl\\TLS: Verification failure, Crashing...\n"; ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } - kcout << "TLS: Verification succeeded! Keeping on...\n"; + kcout << "Krnl\\TLS: Verification succeeded! Keeping on...\n"; } diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index d3d60f6b..cc243904 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -182,11 +182,4 @@ Int32 ke_free_heap(VoidPtr ptr) { return -1; } - -/// @brief Init HeapManager, set Count to zero and IsEnabled to true. -/// @return -Void ke_init_heap() { - HeapManager::Count() = 0UL; - HeapManager::IsEnabled() = true; -} } // namespace HCore -- cgit v1.2.3