From 800977c96cd64b3beeccaa7d373daed3987b1c2a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 2 Feb 2024 14:26:01 +0100 Subject: Kernel: Improvements and fixes regarding the VMMers and assembly code. Signed-off-by: Amlal El Mahrouss --- Private/ArchKit/Arch.hpp | 86 ------------------- Private/ArchKit/ArchKit.hpp | 91 ++++++++++++++++++++ Private/ArchKit/SyscallImpl.hpp | 3 +- Private/EFIKit/BootProtocol.hxx | 2 + Private/HALKit/AMD64/CPUID.hxx | 1 + Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp | 2 +- Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp | 2 +- Private/HALKit/AMD64/DebugOutput.cxx | 2 +- Private/HALKit/AMD64/DebugPort.cxx | 2 +- Private/HALKit/AMD64/HalHardwareAPIC.cpp | 2 +- Private/HALKit/AMD64/HalHardwareInit.cpp | 2 +- Private/HALKit/AMD64/HalPageAlloc.cpp | 9 +- Private/HALKit/AMD64/HalPageAlloc.hpp | 5 +- Private/HALKit/AMD64/HalPlatformAMD64.cpp | 2 +- Private/HALKit/AMD64/PCI/Device.cpp | 2 +- Private/HALKit/AMD64/SMPCoreManager.asm | 2 + Private/HALKit/AMD64/StartSequence.asm | 3 +- Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 2 +- .../HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp | 2 +- Private/KernelKit/Framebuffer.hpp | 2 +- Private/KernelKit/PCI/IO.hpp | 2 +- Private/KernelKit/PEF.hpp | 6 +- Private/KernelKit/PermissionSelector.hxx | 3 +- Private/KernelKit/ProcessManager.hpp | 2 +- Private/KernelKit/SMPManager.hpp | 2 +- Private/KernelKit/Timer.hpp | 2 +- Private/NewKit/Macros.hpp | 3 + Private/Source/Framebuffer.cxx | 18 +++- Private/Source/GUIDWizard.cxx | 18 ++-- Private/Source/PageAllocator.cxx | 2 +- Private/Source/RuntimeCheck.cxx | 2 +- Private/Source/RuntimeMain.cxx | 10 ++- Private/Source/SMPManager.cxx | 2 +- Private/Source/Storage/ATA.cxx | 2 +- Private/Source/Stream.cxx | 18 ++-- Private/Source/URL.cxx | 6 +- Private/Source/UserHeap.cxx | 99 ++++++++++++---------- Private/StorageKit/ATA.hpp | 4 +- 38 files changed, 242 insertions(+), 183 deletions(-) delete mode 100644 Private/ArchKit/Arch.hpp create mode 100644 Private/ArchKit/ArchKit.hpp diff --git a/Private/ArchKit/Arch.hpp b/Private/ArchKit/Arch.hpp deleted file mode 100644 index 4216f9b3..00000000 --- a/Private/ArchKit/Arch.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include -#include -#include - -#ifdef __x86_64__ -# include -# include -# include -#elif defined(__powerpc64__) -# include -#else -# error Unknown architecture -#endif - -namespace HCore -{ - class SystemCallDefaultImpl final - { - public: - static Int32 Exec() { return 0; } - - }; - - template - class SystemCall - { - public: - explicit SystemCall() - { - kcout << "SystemCall::SystemCall"; - } - - virtual ~SystemCall() - { - kcout << "SystemCall::~SystemCall"; - } - - SystemCall &operator=(const SystemCall &) = default; - SystemCall(const SystemCall &) = default; - - // Should not be called alone! - virtual bool Exec() const - { - kcout << "SystemCall->Exec()"; - return false; - } - - }; - - constexpr static inline SSizeT syscall_hash(const char *seed, int mul) - { - SSizeT hash = 0; - - for (SSizeT idx = 0; seed[idx] != 0; ++idx) - { - hash += seed[idx]; - hash ^= mul; - } - - return hash; - } - - bool ke_init_hal(); -} // namespace HCore - -#define kMaxSyscalls 0x100 -#define kSyscallGate 0x21 - -extern HCore::Array kSyscalls; - -extern "C" void rt_wait_for_io(); -extern "C" void rt_syscall_handle(HCore::HAL::StackFrame* stackFrame); -extern "C" HCore::HAL::StackFrame* rt_get_current_context(); -extern "C" int rt_do_context_switch(HCore::HAL::StackFrame* stackFrame); - diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp new file mode 100644 index 00000000..eefd6f5f --- /dev/null +++ b/Private/ArchKit/ArchKit.hpp @@ -0,0 +1,91 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include +#include +#include + +#ifdef __x86_64__ +# include +# include +# include +#elif defined(__powerpc64__) +# include +#else +# error Unknown architecture +#endif + +namespace HCore +{ + class SystemCallDefaultImpl final + { + public: + static Int32 Exec() { return 0; } + + }; + + template + class SystemCall + { + public: + explicit SystemCall() + { + kcout << "SystemCall::SystemCall"; + } + + virtual ~SystemCall() + { + kcout << "SystemCall::~SystemCall"; + } + + SystemCall &operator=(const SystemCall &) = default; + SystemCall(const SystemCall &) = default; + + // Should not be called alone! + virtual bool Exec() const + { + kcout << "SystemCall->Exec()"; + return false; + } + + }; + + constexpr static inline SSizeT syscall_hash(const char *seed, int mul) + { + SSizeT hash = 0; + + for (SSizeT idx = 0; seed[idx] != 0; ++idx) + { + hash += seed[idx]; + hash ^= mul; + } + + return hash; + } + + bool ke_init_hal(); +} // namespace HCore + +#define kMaxSyscalls 0x100 +#define kSyscallGate 0x21 + +extern HCore::Array kSyscalls; + +extern "C" void rt_wait_for_io(); +extern "C" void rt_syscall_handle(HCore::HAL::StackFrame* stackFrame); +extern "C" HCore::HAL::StackFrame* rt_get_current_context(); +extern "C" int rt_do_context_switch(HCore::HAL::StackFrame* stackFrame); + +inline HCore::VoidPtr kKernelVirtualStart; +inline HCore::UIntPtr kKernelVirtualSize; + +inline HCore::VoidPtr kKernelPhysicalStart; +inline HCore::UIntPtr kKernelPhysicalSize; diff --git a/Private/ArchKit/SyscallImpl.hpp b/Private/ArchKit/SyscallImpl.hpp index 7d379197..26acdd38 100644 --- a/Private/ArchKit/SyscallImpl.hpp +++ b/Private/ArchKit/SyscallImpl.hpp @@ -9,4 +9,5 @@ #pragma once -#include \ No newline at end of file +#include + diff --git a/Private/EFIKit/BootProtocol.hxx b/Private/EFIKit/BootProtocol.hxx index 2978cfed..1acfcc18 100644 --- a/Private/EFIKit/BootProtocol.hxx +++ b/Private/EFIKit/BootProtocol.hxx @@ -71,6 +71,8 @@ struct HandoverInformationHeader { voidPtr f_RsdPtr; voidPtr f_SmBIOS; voidPtr f_RTC; + voidPtr f_GOP; + voidPtr f_GOPSize; }; /** diff --git a/Private/HALKit/AMD64/CPUID.hxx b/Private/HALKit/AMD64/CPUID.hxx index 16e73eb6..85eb4893 100644 --- a/Private/HALKit/AMD64/CPUID.hxx +++ b/Private/HALKit/AMD64/CPUID.hxx @@ -76,3 +76,4 @@ typedef enum { CPU_FEATURE_EDX_IA64 = 1 << 30, CPU_FEATURE_EDX_PBE = 1 << 31 } CPU_FEATURE; + diff --git a/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp index 8399d9ce..caf891d1 100644 --- a/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include diff --git a/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp index b41b8285..4f1ed4da 100644 --- a/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/CoreSyscallHandlerAMD64.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include diff --git a/Private/HALKit/AMD64/DebugOutput.cxx b/Private/HALKit/AMD64/DebugOutput.cxx index ad9fc8c5..c4e9cc48 100644 --- a/Private/HALKit/AMD64/DebugOutput.cxx +++ b/Private/HALKit/AMD64/DebugOutput.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include diff --git a/Private/HALKit/AMD64/DebugPort.cxx b/Private/HALKit/AMD64/DebugPort.cxx index b0f2f6d1..d292f95d 100644 --- a/Private/HALKit/AMD64/DebugPort.cxx +++ b/Private/HALKit/AMD64/DebugPort.cxx @@ -10,7 +10,7 @@ //! @file DebuggerPort.cxx //! @brief UART debug via packets. -#include +#include #define kDebugMaxPorts 16 diff --git a/Private/HALKit/AMD64/HalHardwareAPIC.cpp b/Private/HALKit/AMD64/HalHardwareAPIC.cpp index c2bcc007..4e985f8e 100644 --- a/Private/HALKit/AMD64/HalHardwareAPIC.cpp +++ b/Private/HALKit/AMD64/HalHardwareAPIC.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include // bugs = 0 diff --git a/Private/HALKit/AMD64/HalHardwareInit.cpp b/Private/HALKit/AMD64/HalHardwareInit.cpp index bc002e3d..adcacce4 100644 --- a/Private/HALKit/AMD64/HalHardwareInit.cpp +++ b/Private/HALKit/AMD64/HalHardwareInit.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include // bugs = 0 diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 86631e57..6d6e4ba5 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -8,12 +8,12 @@ */ #include -#include #include +#include // this files handles paging. -static HCore::UIntPtr kPagePtr = kPagePtrAddress; +static HCore::UIntPtr kPagePtr = 0; static HCore::SizeT kPageCnt = 0UL; namespace HCore { @@ -23,6 +23,7 @@ static auto hal_try_alloc_new_page(SizeT sz, Boolean rw, Boolean user) char *ptr = &(reinterpret_cast(kPagePtr))[kPageCnt + 1]; PageTable64 *pte = reinterpret_cast(ptr); + pte->Rw = rw; pte->User = user; pte->Present = true; @@ -52,5 +53,9 @@ auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr { return reinterpret_cast(new_pte); } + +UIntPtr& hal_get_page_ptr() noexcept { return kPagePtr; } + +void hal_set_page_ptr(const UIntPtr& newPagePtr) noexcept { kPagePtr = newPagePtr; } } // namespace HAL } // namespace HCore diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index 3f9428b9..711dc27d 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -19,8 +19,6 @@ #define PTE_ALIGN (4096) #endif //! PTE_ALIGN -#define kPagePtrAddress 0x9000000 - extern "C" void flush_tlb(HCore::UIntPtr VirtualAddr); extern "C" void write_cr3(HCore::UIntPtr pde); extern "C" void write_cr0(HCore::UIntPtr bit); @@ -44,6 +42,7 @@ struct PageTable64 { }; PageTable64 *hal_alloc_page(SizeT sz, Boolean rw, Boolean user); - +UIntPtr& hal_get_page_ptr() noexcept; +void hal_set_page_ptr(const UIntPtr& newPagePtr) noexcept; UIntPtr hal_create_page(Boolean rw, Boolean user); } // namespace HCore::HAL diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp index ab03659a..6374d06b 100644 --- a/Private/HALKit/AMD64/HalPlatformAMD64.cpp +++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include namespace HCore::HAL { namespace Detail { diff --git a/Private/HALKit/AMD64/PCI/Device.cpp b/Private/HALKit/AMD64/PCI/Device.cpp index 815043c9..b353d2a6 100644 --- a/Private/HALKit/AMD64/PCI/Device.cpp +++ b/Private/HALKit/AMD64/PCI/Device.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include HCore::UInt LumiaPCIReadRaw(HCore::UInt bar, HCore::UShort bus, diff --git a/Private/HALKit/AMD64/SMPCoreManager.asm b/Private/HALKit/AMD64/SMPCoreManager.asm index 1a994258..9741d092 100644 --- a/Private/HALKit/AMD64/SMPCoreManager.asm +++ b/Private/HALKit/AMD64/SMPCoreManager.asm @@ -14,6 +14,8 @@ section .text rt_do_context_switch: + mov rcx, r15 + mov [r15+0], rax mov [r15+8], rbx mov [r15+16], rcx diff --git a/Private/HALKit/AMD64/StartSequence.asm b/Private/HALKit/AMD64/StartSequence.asm index 5ef8ed55..c8e0a4e2 100644 --- a/Private/HALKit/AMD64/StartSequence.asm +++ b/Private/HALKit/AMD64/StartSequence.asm @@ -15,7 +15,6 @@ ;; External symbols needed by this unit. [extern RuntimeMain] -[extern __SYSTEM_STACK_END] %define kTypeKernel 100 %define kArchAmd64 122 @@ -32,7 +31,9 @@ section .text ;; Just a simple setup, we'd also need to tell some before Main: + push rcx jmp RuntimeMain + pop rcx L0: cli hlt diff --git a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 11965ff7..5d1c6d2b 100644 --- a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include HCore::Array kSyscalls; diff --git a/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp b/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp index 7c7d7683..c1672e68 100644 --- a/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp +++ b/Private/HALKit/PowerPC/CoreSyscallHandlerPowerPC.cpp @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include HCore::Array diff --git a/Private/KernelKit/Framebuffer.hpp b/Private/KernelKit/Framebuffer.hpp index 8ad23571..feb34d3a 100644 --- a/Private/KernelKit/Framebuffer.hpp +++ b/Private/KernelKit/Framebuffer.hpp @@ -37,7 +37,7 @@ class Framebuffer final { Framebuffer &operator=(const Framebuffer &) = delete; Framebuffer(const Framebuffer &) = default; - volatile UIntPtr *operator[](const UIntPtr &width_and_height); + volatile UIntPtr *operator[](const UIntPtr &pos); operator bool() { return m_FrameBufferAddr && m_Colour != FramebufferColorKind::INVALID; diff --git a/Private/KernelKit/PCI/IO.hpp b/Private/KernelKit/PCI/IO.hpp index 778650b6..4511fca1 100644 --- a/Private/KernelKit/PCI/IO.hpp +++ b/Private/KernelKit/PCI/IO.hpp @@ -9,7 +9,7 @@ #pragma once -#include +#include #include #include #include diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index 8c67c6ae..0cee2e90 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -22,7 +22,11 @@ #define kPefVersion 1 #define kPefNameLen 64 -// @brief Preferred Executable Format, a format designed for any computer. +/// @brief Preferred Executable Format, a format designed +/// for RISC/CISC Von-neumann processor types. + +/// The PEF also uses the x64 PE calling convention and ABI. +/// It's just that the container are different. namespace HCore { enum { diff --git a/Private/KernelKit/PermissionSelector.hxx b/Private/KernelKit/PermissionSelector.hxx index 7b799c50..14bb5a9e 100644 --- a/Private/KernelKit/PermissionSelector.hxx +++ b/Private/KernelKit/PermissionSelector.hxx @@ -28,7 +28,8 @@ enum class RingKind { kRingUser = 3, kRingDriver = 2, kRingKernel = 0, - kUnknown = -1, + kRingUnknown = -1, + kRingCount = 4, }; class PermissionSelector final { diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp index 14c6eb28..8c536a3b 100644 --- a/Private/KernelKit/ProcessManager.hpp +++ b/Private/KernelKit/ProcessManager.hpp @@ -10,7 +10,7 @@ #ifndef __PROCESS_MANAGER__ #define __PROCESS_MANAGER__ -#include +#include #include #include #include diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index f7b048ad..0a71a165 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -10,7 +10,7 @@ #ifndef _INC_SMP_MANAGER_HPP #define _INC_SMP_MANAGER_HPP -#include +#include #include #include diff --git a/Private/KernelKit/Timer.hpp b/Private/KernelKit/Timer.hpp index af03a7d0..eeeeac3e 100644 --- a/Private/KernelKit/Timer.hpp +++ b/Private/KernelKit/Timer.hpp @@ -9,7 +9,7 @@ #pragma once -#include +#include #include #include diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp index 94fd8fe8..50d44946 100644 --- a/Private/NewKit/Macros.hpp +++ b/Private/NewKit/Macros.hpp @@ -86,3 +86,6 @@ #define PACKED ATTRIBUTE(packed) #define NO_EXEC ATTRIBUTE(noexec) + +#define EXTERN extern +#define STATIC static \ No newline at end of file diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx index 3b8fa229..61f946a7 100644 --- a/Private/Source/Framebuffer.cxx +++ b/Private/Source/Framebuffer.cxx @@ -3,20 +3,32 @@ Copyright Mahrouss Logic File: Framebuffer.cxx - Purpose: EFI C++ library + Purpose: Framebuffer object Revision History: 01/02/24: Added file (amlel) + 02/02/24: Add documentation (amlel) ------------------------------------------- */ #include +/** + * @brief Framebuffer object implementation. + * + */ + using namespace HCore; -volatile UIntPtr *Framebuffer::operator[](const UIntPtr &width_and_height) { - return (UIntPtr *)(m_FrameBufferAddr->m_Base * width_and_height); +/** + * @brief Get Pixel at + * + * @param pos position of pixel. + * @return volatile* + */ +volatile UIntPtr *Framebuffer::operator[](const UIntPtr &pos) { + return (UIntPtr *)(m_FrameBufferAddr->m_Base * pos); } const FramebufferColorKind &Framebuffer::Color( diff --git a/Private/Source/GUIDWizard.cxx b/Private/Source/GUIDWizard.cxx index 96c00efc..8befb071 100644 --- a/Private/Source/GUIDWizard.cxx +++ b/Private/Source/GUIDWizard.cxx @@ -1,11 +1,13 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: GUIDWizard.cxx + Purpose: GUID helper code + + Revision History: + +------------------------------------------- */ #include #include diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx index c2de0232..060ce011 100644 --- a/Private/Source/PageAllocator.cxx +++ b/Private/Source/PageAllocator.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/RuntimeCheck.cxx index bbeecb74..a84a0b7a 100644 --- a/Private/Source/RuntimeCheck.cxx +++ b/Private/Source/RuntimeCheck.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include #include diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx index 8c18c0a3..0cbdac1c 100644 --- a/Private/Source/RuntimeMain.cxx +++ b/Private/Source/RuntimeMain.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include #include @@ -20,6 +20,14 @@ extern "C" void RuntimeMain( HCore::ke_init_heap(); HCore::ke_init_ke_heap(); + kKernelVirtualSize = HandoverHeader->f_VirtualSize; + kKernelVirtualStart = HandoverHeader->f_VirtualStart; + + kKernelPhysicalSize = HandoverHeader->f_VirtualSize; + kKernelPhysicalStart = HandoverHeader->f_VirtualStart; + + HCore::HAL::hal_set_page_ptr((HCore::UIntPtr)kKernelVirtualStart); + MUST_PASS(HCore::ke_init_hal()); HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx index 37c2e592..87e82da1 100644 --- a/Private/Source/SMPManager.cxx +++ b/Private/Source/SMPManager.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx index 184bb043..9d7a204e 100644 --- a/Private/Source/Storage/ATA.cxx +++ b/Private/Source/Storage/ATA.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include //! @brief ATA DMA Driver diff --git a/Private/Source/Stream.cxx b/Private/Source/Stream.cxx index 668d5aee..ab1ca742 100644 --- a/Private/Source/Stream.cxx +++ b/Private/Source/Stream.cxx @@ -1,10 +1,12 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: Stream.cxx + Purpose: Stream object + + Revision History: + +------------------------------------------- */ #include diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx index f1df4ee1..ab289a66 100644 --- a/Private/Source/URL.cxx +++ b/Private/Source/URL.cxx @@ -18,7 +18,7 @@ Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {} Url::~Url() = default; -constexpr const char *kProtos[] = { +constexpr const char *kURLProtocols[] = { "https", // http with the secure. "http", // http without the secure "file", // filesystem protocol @@ -43,8 +43,8 @@ static ErrorOr url_extract_location(const char *url) { for (; i < string_length(url); ++i) { if (!scheme_found) { for (int y = 0; kProtosCount; ++y) { - if (rt_string_in_string(view.CData(), kProtos[y])) { - i += string_length(kProtos[y]) + kUrlOutSz; + if (rt_string_in_string(view.CData(), kURLProtocols[y])) { + i += string_length(kURLProtocols[y]) + kUrlOutSz; scheme_found = true; break; diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index 0b6680a3..e22fe4f9 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -11,25 +11,30 @@ #include /// @file Heap.cxx -/// @brief Heap Manager, user mode allocator. -/// @note if you want to look at kernel allocs, please look for KHeap.cxx +/// @brief Heap Manager, Process heap allocator. +/// @note if you want to look at the kernel allocator, please look for KernelHeap.cxx /// bugs: 0 namespace HCore { +/** + * @brief Heap Manager class, takes care of allocating the process pools. + * @note This rely on Virtual Memory! Consider adding good vmem support when + * @note porting to a new arch. + */ class HeapManager final { public: - static SizeT& GetCount() { return s_NumPools; } - static Ref& GetPmm() { return s_Pmm; } - static Boolean& IsEnabled() { return s_PoolsAreEnabled; } - static Array, kPoolMaxSz>& The() { return s_Pool; } + STATIC SizeT& Count() { return s_NumPools; } + STATIC Ref& Leak() { return s_Pmm; } + STATIC Boolean& IsEnabled() { return s_PoolsAreEnabled; } + STATIC Array, kPoolMaxSz>& The() { return s_Pool; } private: - static Size s_NumPools; - static Ref s_Pmm; + STATIC Size s_NumPools; + STATIC Ref s_Pmm; private: - static Boolean s_PoolsAreEnabled; - static Array, kPoolMaxSz> s_Pool; + STATIC Boolean s_PoolsAreEnabled; + STATIC Array, kPoolMaxSz> s_Pool; }; //! declare fields @@ -39,16 +44,16 @@ Ref HeapManager::s_Pmm; Boolean HeapManager::s_PoolsAreEnabled = true; Array, kPoolMaxSz> HeapManager::s_Pool; -static voidPtr ke_find_unused_heap(Int flags); -static void ke_free_heap_internal(voidPtr vaddr); -static voidPtr ke_make_heap(voidPtr vaddr, Int flags); -static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr); +STATIC voidPtr ke_find_unused_heap(Int flags); +STATIC void ke_free_heap_internal(voidPtr vaddr); +STATIC voidPtr ke_make_heap(voidPtr vaddr, Int flags); +STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr); -static voidPtr ke_find_unused_heap(Int flags) { +STATIC voidPtr ke_find_unused_heap(Int flags) { for (SizeT index = 0; index < kPoolMaxSz; ++index) { if (HeapManager::The()[index] && !HeapManager::The()[index].Leak().Leak().Leak()->Present()) { - HeapManager::GetPmm().Leak().TogglePresent( + HeapManager::Leak().Leak().TogglePresent( HeapManager::The()[index].Leak().Leak(), true); kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n"; @@ -64,7 +69,7 @@ static voidPtr ke_find_unused_heap(Int flags) { return nullptr; } -static voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) { +STATIC voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) { if (virtualAddress) { HeapHeader* pool_hdr = reinterpret_cast(virtualAddress); @@ -86,7 +91,7 @@ static voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) { return nullptr; } -static void ke_free_heap_internal(voidPtr virtualAddress) { +STATIC void ke_free_heap_internal(voidPtr virtualAddress) { HeapHeader* pool_hdr = reinterpret_cast( reinterpret_cast(virtualAddress) - sizeof(HeapHeader)); @@ -98,23 +103,29 @@ static void ke_free_heap_internal(voidPtr virtualAddress) { } } -static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { +/** + * @brief Check for the ptr and frees it. + * + * @param index Where to look at. + * @param ptr The ptr to check. + * @return Boolean true if successful. + */ +STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { if (HeapManager::The()[index]) { - // ErrorOr<>::operator bool - if (!HeapManager::The()[index].Leak().Leak().IsStrong()) { - // we want them to be weak - // because we allocated it. - if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() == - (UIntPtr)ptr) { - HeapManager::GetPmm().Leak().FreePage( - HeapManager::The()[index].Leak().Leak()); - --HeapManager::GetCount(); - - ke_free_heap_internal(ptr); - ptr = nullptr; - - return true; - } + // ErrorOr<>::operator Boolean + /// if address matches + /// -> Free Pool. + if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() == + (UIntPtr)ptr) { + HeapManager::Leak().Leak().FreePage( + HeapManager::The()[index].Leak().Leak()); + + --HeapManager::Count(); + + ke_free_heap_internal(ptr); + ptr = nullptr; + + return true; } } @@ -127,20 +138,20 @@ static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { voidPtr ke_new_heap(Int32 flags) { if (!HeapManager::IsEnabled()) return nullptr; - if (HeapManager::GetCount() > kPoolMaxSz) return nullptr; + if (HeapManager::Count() > kPoolMaxSz) return nullptr; if (voidPtr ret = ke_find_unused_heap(flags)) return ret; // this wasn't set to true - auto ref_page = HeapManager::GetPmm().Leak().RequestPage( + auto ref_page = HeapManager::Leak().Leak().RequestPage( ((flags & kPoolUser)), (flags & kPoolRw)); + if (ref_page) { ///! reserve page. - HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page; - auto& ref = HeapManager::GetCount(); - ++ref; // increment the number of addresses we have now. + HeapManager::The()[HeapManager::Count()].Leak() = ref_page; + auto& ref = HeapManager::Count(); - kcout << "[ke_new_heap] New Address found!\r\n"; + ++ref; // increment the number of addresses we have now. // finally make the pool address. return ke_make_heap( @@ -157,7 +168,7 @@ Int32 ke_free_heap(voidPtr ptr) { if (!HeapManager::IsEnabled()) return -1; if (ptr) { - SizeT base = HeapManager::GetCount(); + SizeT base = HeapManager::Count(); if (ke_check_and_free_heap(base, ptr)) return 0; @@ -171,10 +182,10 @@ Int32 ke_free_heap(voidPtr ptr) { return -1; } -/// @brief Init HeapManager, set GetCount to zero and IsEnabled to true. -/// @return +/// @brief Init HeapManager, set Count to zero and IsEnabled to true. +/// @return Void ke_init_heap() { - HeapManager::GetCount() = 0UL; + HeapManager::Count() = 0UL; HeapManager::IsEnabled() = true; } } // namespace HCore diff --git a/Private/StorageKit/ATA.hpp b/Private/StorageKit/ATA.hpp index f44c2843..279258ca 100644 --- a/Private/StorageKit/ATA.hpp +++ b/Private/StorageKit/ATA.hpp @@ -23,7 +23,7 @@ namespace HCore kRead48, kWrite28, kWrite48, - kUnknown + kATAUnknown }; const char* ata_read_28(ULong lba); @@ -90,7 +90,7 @@ namespace HCore return {}; } - case PATAType::kUnknown: + case PATAType::kATAUnknown: { kcout << "ErrorOr ata_read: Unknown ATA Command...\n"; return {}; -- cgit v1.2.3