From 8b1114ea205ef6560fb7bf5713577d1ab7deb5be Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Sep 2024 17:29:07 +0200 Subject: [ MR ] BUMP commit. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/ArchKit/ArchKit.hxx | 2 +- dev/ZKA/FSKit/IndexableProperty.hxx | 2 +- dev/ZKA/FSKit/NewFS.hxx | 2 +- dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx | 8 +- dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx | 16 +- dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm | 18 +- dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 18 +- dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 48 ++- dev/ZKA/HALKit/AMD64/Processor.hxx | 20 +- dev/ZKA/HALKit/ARM64/HalKernelMain.cxx | 10 +- dev/ZKA/KernelKit/CodeManager.hxx | 31 -- dev/ZKA/KernelKit/CodeMgr.hxx | 31 ++ dev/ZKA/KernelKit/DLLInterface.hxx | 11 +- dev/ZKA/KernelKit/DebugOutput.hxx | 2 +- dev/ZKA/KernelKit/DeviceManager.hxx | 130 -------- dev/ZKA/KernelKit/DeviceMgr.hxx | 132 ++++++++ dev/ZKA/KernelKit/DriveManager.hxx | 151 --------- dev/ZKA/KernelKit/DriveMgr.hxx | 151 +++++++++ dev/ZKA/KernelKit/FileManager.hxx | 420 ------------------------- dev/ZKA/KernelKit/FileMgr.hxx | 420 +++++++++++++++++++++++++ dev/ZKA/KernelKit/MP.hxx | 2 +- dev/ZKA/KernelKit/PCI/Dma.hxx | 2 +- dev/ZKA/KernelKit/PECodeManager.hxx | 24 -- dev/ZKA/KernelKit/PECodeMgr.hxx | 24 ++ dev/ZKA/KernelKit/PEFCodeManager.hxx | 67 ---- dev/ZKA/KernelKit/PEFCodeMgr.hxx | 67 ++++ dev/ZKA/KernelKit/PEFDLLInterface.hxx | 4 +- dev/ZKA/KernelKit/UserProcessScheduler.hxx | 5 +- dev/ZKA/NetworkKit/NetworkDevice.hxx | 2 +- dev/ZKA/NewKit/PageAllocator.hxx | 2 +- dev/ZKA/NewKit/PageManager.hxx | 79 ----- dev/ZKA/NewKit/PageMgr.hxx | 79 +++++ dev/ZKA/NewKit/Pmm.hxx | 8 +- dev/ZKA/Sources/CodeManager.cxx | 32 -- dev/ZKA/Sources/CodeMgr.cxx | 32 ++ dev/ZKA/Sources/DLLMain.cxx | 22 +- dev/ZKA/Sources/DeviceManager.cxx | 7 - dev/ZKA/Sources/DeviceMgr.cxx | 7 + dev/ZKA/Sources/DriveManager.cxx | 146 --------- dev/ZKA/Sources/DriveMgr.cxx | 146 +++++++++ dev/ZKA/Sources/FileManager.cxx | 190 ----------- dev/ZKA/Sources/FileMgr.cxx | 190 +++++++++++ dev/ZKA/Sources/Heap.cxx | 73 +++-- dev/ZKA/Sources/MP.cxx | 30 +- dev/ZKA/Sources/NewFS+FileManager.cxx | 109 ------- dev/ZKA/Sources/NewFS+FileMgr.cxx | 109 +++++++ dev/ZKA/Sources/NewFS+IO.cxx | 4 +- dev/ZKA/Sources/NewFS+Journal.cxx | 2 +- dev/ZKA/Sources/PEFCodeManager.cxx | 252 --------------- dev/ZKA/Sources/PEFCodeMgr.cxx | 252 +++++++++++++++ dev/ZKA/Sources/PageManager.cxx | 111 ------- dev/ZKA/Sources/PageMgr.cxx | 111 +++++++ dev/ZKA/Sources/Pmm.cxx | 14 +- dev/ZKA/Sources/Storage/ATADeviceInterface.cxx | 4 +- dev/ZKA/Sources/User.cxx | 2 +- dev/ZKA/Sources/UserProcessScheduler.cxx | 2 +- dev/ZKA/StorageKit/AHCI.hxx | 4 +- dev/ZKA/StorageKit/ATA.hxx | 4 +- dev/ZKA/StorageKit/NVME.hxx | 4 +- dev/ZKA/amd64-efi.make | 2 +- 60 files changed, 1930 insertions(+), 1919 deletions(-) delete mode 100644 dev/ZKA/KernelKit/CodeManager.hxx create mode 100644 dev/ZKA/KernelKit/CodeMgr.hxx delete mode 100644 dev/ZKA/KernelKit/DeviceManager.hxx create mode 100644 dev/ZKA/KernelKit/DeviceMgr.hxx delete mode 100644 dev/ZKA/KernelKit/DriveManager.hxx create mode 100644 dev/ZKA/KernelKit/DriveMgr.hxx delete mode 100644 dev/ZKA/KernelKit/FileManager.hxx create mode 100644 dev/ZKA/KernelKit/FileMgr.hxx delete mode 100644 dev/ZKA/KernelKit/PECodeManager.hxx create mode 100644 dev/ZKA/KernelKit/PECodeMgr.hxx delete mode 100644 dev/ZKA/KernelKit/PEFCodeManager.hxx create mode 100644 dev/ZKA/KernelKit/PEFCodeMgr.hxx delete mode 100644 dev/ZKA/NewKit/PageManager.hxx create mode 100644 dev/ZKA/NewKit/PageMgr.hxx delete mode 100644 dev/ZKA/Sources/CodeManager.cxx create mode 100644 dev/ZKA/Sources/CodeMgr.cxx delete mode 100644 dev/ZKA/Sources/DeviceManager.cxx create mode 100644 dev/ZKA/Sources/DeviceMgr.cxx delete mode 100644 dev/ZKA/Sources/DriveManager.cxx create mode 100644 dev/ZKA/Sources/DriveMgr.cxx delete mode 100644 dev/ZKA/Sources/FileManager.cxx create mode 100644 dev/ZKA/Sources/FileMgr.cxx delete mode 100644 dev/ZKA/Sources/NewFS+FileManager.cxx create mode 100644 dev/ZKA/Sources/NewFS+FileMgr.cxx delete mode 100644 dev/ZKA/Sources/PEFCodeManager.cxx create mode 100644 dev/ZKA/Sources/PEFCodeMgr.cxx delete mode 100644 dev/ZKA/Sources/PageManager.cxx create mode 100644 dev/ZKA/Sources/PageMgr.cxx (limited to 'dev/ZKA') diff --git a/dev/ZKA/ArchKit/ArchKit.hxx b/dev/ZKA/ArchKit/ArchKit.hxx index 60a2b2ec..fc2d7d33 100644 --- a/dev/ZKA/ArchKit/ArchKit.hxx +++ b/dev/ZKA/ArchKit/ArchKit.hxx @@ -109,4 +109,4 @@ inline Kernel::Array #include -#include +#include #define kIndexerNodeNameLength 255 #define kIndexerClaimed 0xCF diff --git a/dev/ZKA/FSKit/NewFS.hxx b/dev/ZKA/FSKit/NewFS.hxx index c5ada14b..4587b70f 100644 --- a/dev/ZKA/FSKit/NewFS.hxx +++ b/dev/ZKA/FSKit/NewFS.hxx @@ -18,7 +18,7 @@ default. #include #include -#include +#include #include /** diff --git a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx index 677b1219..7bafd075 100644 --- a/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx +++ b/dev/ZKA/HALKit/AMD64/HalBitMapMgr.cxx @@ -49,10 +49,10 @@ namespace Kernel if (user) mm_update_pte(base_ptr, eFlagsUser); - return (VoidPtr)(ptr_bit_set + 2); + return (VoidPtr)(&ptr_bit_set[2]); } - base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + size); + base_ptr = reinterpret_cast(reinterpret_cast(base_ptr) + 1 + ptr_bit_set[1]); } return nullptr; @@ -71,7 +71,7 @@ namespace Kernel ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); - return ptr_new; + return &((UIntPtr*)ptr_new)[1]; } auto mm_free_bitmap(VoidPtr page_ptr) -> Bool @@ -79,7 +79,7 @@ namespace Kernel if (!page_ptr) return false; - UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 2; + UIntPtr* ptr_bit_set = reinterpret_cast(page_ptr) - 3; if (!ptr_bit_set[0] || ptr_bit_set[0] != cVMHMagic) diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx index 19d62965..54b62b80 100644 --- a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx +++ b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx @@ -15,12 +15,15 @@ namespace Kernel::HAL STATIC Void hal_remap_intel_pic_ctrl(Void) noexcept { - // Remap PIC. + auto a1 = HAL::In8(0xa1); // save masks + auto a2 = HAL::In8(0xa2); + HAL::Out8(0x20, 0x11); + HAL::Out8(0xA0, 0x11); - HAL::Out8(0x21, 40); - HAL::Out8(0xA1, 32); + HAL::Out8(0x21, 32); + HAL::Out8(0xA1, 40); HAL::Out8(0x21, 4); HAL::Out8(0xA1, 2); @@ -28,8 +31,8 @@ namespace Kernel::HAL HAL::Out8(0x21, 0x01); HAL::Out8(0xA1, 0x01); - HAL::Out8(0x21, 0xFD); - HAL::Out8(0xA1, 0xFF); + HAL::Out8(0x21, a2); + HAL::Out8(0xA1, a1); } } // namespace Detail @@ -73,7 +76,8 @@ namespace Kernel::HAL hal_load_idt(idt); - Detail::hal_remap_intel_pic_ctrl(); + HAL::Out8(0xA1, 0xFF); + HAL::Out8(0x21, 0xFF); } void GDTLoader::Load(Ref& gdt) diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm index d59cc197..6abd28c9 100644 --- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm @@ -141,12 +141,7 @@ IntNormal 38 IntNormal 39 IntNormal 40 -extern mp_system_call_handler - -__ZKA_INT_41: - cmp rcx, 0 - jne mp_system_call_handler - iretq +IntNormal 41 IntNormal 42 IntNormal 43 @@ -222,17 +217,18 @@ section .text hal_load_gdt: lgdt [rcx] - push 0x08 - lea rax, [rel rt_reload_segments] - push rax + cli + push 8 + push hal_reload_segments o64 retf -rt_reload_segments: - mov ax, 0x10 +hal_reload_segments: + mov ax, 16 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax + sti ret global hal_load_idt diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index 33c3f689..10916b06 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -64,14 +64,14 @@ EXTERN_C void hal_user_code_start(void); EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void); /* GDT, mostly descriptors for user and kernel segments. */ -STATIC Kernel::HAL::Detail::ZKA_GDT_ENTRY cGdt[6] = { +STATIC Kernel::HAL::Detail::ZKA_GDT_ENTRY ALIGN(0x1000) cGdt[6] = { {.fLimitLow = 0, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x00, .fFlags = 0x00, .fBaseHigh = 0}, // Null entry {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x9A, .fFlags = 0xA0, .fBaseHigh = 0}, // Kernel code {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x92, .fFlags = 0xA0, .fBaseHigh = 0}, // Kernel data - {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xFA, .fFlags = 0xA0, .fBaseHigh = 0}, // User code - {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0xF2, .fFlags = 0xA0, .fBaseHigh = 0}, // User data - // reserve them for later. {.fLimitLow = 0, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x00, .fFlags = 0x00, .fBaseHigh = 0}, + {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x9A, .fFlags = 0xA0, .fBaseHigh = 0}, // User code + {.fLimitLow = 0xFFFF, .fBaseLow = 0, .fBaseMid = 0, .fAccessByte = 0x92, .fFlags = 0xA0, .fBaseHigh = 0}, // User data + // reserve them for later. }; EXTERN_C void hal_init_platform( @@ -127,11 +127,11 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemManager(); + auto fs = new Kernel::NewFilesystemMgr(); MUST_PASS(fs); - Kernel::NewFilesystemManager::Mount(fs); + Kernel::NewFilesystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index 39a80922..1f31c880 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -21,23 +21,42 @@ section .text ;; rcx: code ptr. ;; rdx: stack ptr. mp_do_context_switch: - mov rsp, rdx - mov rbp, rsp + swapgs + + mov fs, rcx + mov gs, rdx mov r9, [r8 + (8 * 2)] mov r10, [r8 + (8 * 3)] - mov fs, [r8 + (8 * 4)] + mov r12, [r8 + (8 * 5)] mov r13, [r8 + (8 * 6)] mov r14, [r8 + (8 * 7)] mov r15, [r8 + (8 * 8)] - mov gs, [r8 + (8 * 9)] - mov r8, [r8] + mov r11, gs + mov r12, fs - mov rax, rcx + ; Enable SCE that enables sysret and syscall + mov rcx, 0xc0000082 + wrmsr + mov rcx, 0xc0000080 + rdmsr + or eax, 1 + wrmsr + mov rcx, 0xc0000081 + rdmsr + mov edx, 0x00180008 + wrmsr mov r11, 0x202 + mov fs, [r8 + (8 * 4)] + mov gs, [r8 + (8 * 9)] + mov r8, [r8] + + swapgs + sti + o64 sysret ;; @brief Gets the current stack frame. @@ -67,15 +86,14 @@ mp_system_call_handler: o64 sysret mp_do_context_switch_pre: - mov rcx, 0xc0000082 - wrmsr - mov rcx, 0xc0000080 - rdmsr - or eax, 1 - wrmsr - mov rcx, 0xc0000081 - rdmsr - mov edx, 0x00180008 + xor rdx, rdx + mov rax, 0x202 + mov rcx, 0xc0000084 wrmsr + mov rdx, mp_system_call_handler + shr rdx, 32 + mov rcx, 0xc0000082 + wrmsr + ret diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index b7fa080c..0636c291 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -99,17 +99,17 @@ namespace Kernel::HAL using InterruptId = UInt16; /* For each element in the IVT */ /// @brief Stack frame (as retrieved from assembly.) - struct StackFrame final + struct PACKED StackFrame final { - UIntPtr R8{0}; - UIntPtr R9{0}; - UIntPtr R10{0}; - UIntPtr FS{0}; - UIntPtr R12{0}; - UIntPtr R13{0}; - UIntPtr R14{0}; - UIntPtr R15{0}; - UIntPtr GS{0}; + RawRegister R8{0}; + RawRegister R9{0}; + RawRegister R10{0}; + RawRegister FS{0}; + RawRegister R12{0}; + RawRegister R13{0}; + RawRegister R14{0}; + RawRegister R15{0}; + RawRegister GS{0}; }; typedef StackFrame* StackFramePtr; diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index d51f0421..ee06c305 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -94,12 +94,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemManager(); + auto fs = new Kernel::NewFilesystemMgr(); MUST_PASS(fs); MUST_PASS(fs->GetParser()); - Kernel::NewFilesystemManager::Mount(fs); + Kernel::NewFilesystemMgr::Mount(fs); const auto cPassword = "ZKA_KERNEL_AUTHORITY"; diff --git a/dev/ZKA/KernelKit/CodeManager.hxx b/dev/ZKA/KernelKit/CodeManager.hxx deleted file mode 100644 index ef9d18f4..00000000 --- a/dev/ZKA/KernelKit/CodeManager.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: CodeManager.hpp - Purpose: Code Manager and Shared Objects. - - Revision History: - - 30/01/24: Added file (amlel) - 3/8/24: Add UPP struct. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel -{ - /// @brief Main process entrypoint. - typedef void (*MainKind)(void); - - /// @brief Executes a new process from a function. Kernel code only. - /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. - /// @param main the start of the process. - /// @return if the process was started or not. - bool sched_execute_thread(MainKind main, const Char* process_name) noexcept; -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/CodeMgr.hxx b/dev/ZKA/KernelKit/CodeMgr.hxx new file mode 100644 index 00000000..8c4f090f --- /dev/null +++ b/dev/ZKA/KernelKit/CodeMgr.hxx @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: CodeMgr.hpp + Purpose: Code Mgr and Shared Objects. + + Revision History: + + 30/01/24: Added file (amlel) + 3/8/24: Add UPP struct. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel +{ + /// @brief Main process entrypoint. + typedef void (*MainKind)(void); + + /// @brief Executes a new process from a function. Kernel code only. + /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. + /// @param main the start of the process. + /// @return if the process was started or not. + bool sched_execute_thread(MainKind main, const Char* process_name) noexcept; +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DLLInterface.hxx b/dev/ZKA/KernelKit/DLLInterface.hxx index 370363b7..13f36b82 100644 --- a/dev/ZKA/KernelKit/DLLInterface.hxx +++ b/dev/ZKA/KernelKit/DLLInterface.hxx @@ -35,8 +35,15 @@ namespace Kernel virtual DLL_TRAITS** GetAddressOf() = 0; virtual DLL_TRAITS* Get() = 0; - virtual void Mount(DLL_TRAITS* to_mount) = 0; - virtual void Unmount() = 0; + virtual Void Mount(DLL_TRAITS* to_mount) = 0; + virtual Void Unmount() = 0; + + + template + SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) + { + return nullptr; + } }; /// @brief Pure implementation, missing method/function handler. diff --git a/dev/ZKA/KernelKit/DebugOutput.hxx b/dev/ZKA/KernelKit/DebugOutput.hxx index fcf18bff..66105aa1 100644 --- a/dev/ZKA/KernelKit/DebugOutput.hxx +++ b/dev/ZKA/KernelKit/DebugOutput.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include diff --git a/dev/ZKA/KernelKit/DeviceManager.hxx b/dev/ZKA/KernelKit/DeviceManager.hxx deleted file mode 100644 index 5164ae28..00000000 --- a/dev/ZKA/KernelKit/DeviceManager.hxx +++ /dev/null @@ -1,130 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -/* ------------------------------------------- - - Revision History: - - 31/01/24: Add kDeviceCnt (amlel) - - ------------------------------------------- */ - -#pragma once - -/* Kernel device interface manager. */ -/* @file KernelKit/DeviceManager.hpp */ -/* @brief Device abstraction and I/O buffer. */ - -#include -#include - -// Last Rev -// Wed, Apr 3, 2024 9:09:41 AM - -namespace Kernel -{ - template - class DeviceInterface; - - template - class DeviceInterface - { - public: - explicit DeviceInterface(void (*Out)(T), void (*In)(T)) - : fOut(Out), fIn(In) - { - } - - virtual ~DeviceInterface() = default; - - public: - DeviceInterface& operator=(const DeviceInterface&) = default; - DeviceInterface(const DeviceInterface&) = default; - - public: - virtual DeviceInterface& operator<<(T Data) - { - fOut(Data); - return *this; - } - - virtual DeviceInterface& operator>>(T Data) - { - fIn(Data); - return *this; - } - - virtual const char* Name() const - { - return "DeviceInterface"; - } - - operator bool() - { - return fOut && fIn; - } - - Bool operator!() - { - return !fOut || !fIn; - } - - private: - Void (*fOut)(T Data) = {nullptr}; - Void (*fIn)(T Data) = {nullptr}; - }; - - /// - /// @brief Input Output Buffer - /// Used mainly to communicate between hardware. - /// - template - class IOBuf final - { - public: - explicit IOBuf(T Dat) - : fData(Dat) - { - // at least pass something valid when instancating this struct. - MUST_PASS(Dat); - } - - IOBuf& operator=(const IOBuf&) = default; - IOBuf(const IOBuf&) = default; - - ~IOBuf() = default; - - public: - template - R operator->() const - { - return fData; - } - - template - R& operator[](Size index) const - { - return fData[index]; - } - - private: - T fData; - }; - - ///! @brief Device enum types. - enum - { - kDeviceTypeIDE, - kDeviceTypeEthernet, - kDeviceTypeWiFi, - kDeviceTypeRS232, - kDeviceTypeSCSI, - kDeviceTypeSHCI, - kDeviceTypeUSB, - kDeviceTypeMedia, - kDeviceTypeCount, - }; -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DeviceMgr.hxx b/dev/ZKA/KernelKit/DeviceMgr.hxx new file mode 100644 index 00000000..473af601 --- /dev/null +++ b/dev/ZKA/KernelKit/DeviceMgr.hxx @@ -0,0 +1,132 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* Device manager. */ +/* @file KernelKit/DeviceMgr.hpp */ +/* @brief Device abstraction and I/O buffer. */ + +#include +#include + +#define cDevicePath "\\Mount\\" + +// Last Rev +// Wed, Apr 3, 2024 9:09:41 AM + +namespace Kernel +{ + template + class DeviceInterface; + + template + class DeviceInterface + { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : fOut(Out), fIn(In) + { + } + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; + + public: + virtual DeviceInterface& operator<<(T Data) + { + fOut(Data); + return *this; + } + + virtual DeviceInterface& operator>>(T Data) + { + fIn(Data); + return *this; + } + + virtual const char* Name() const + { + return "DeviceInterface"; + } + + operator bool() + { + return fOut && fIn; + } + + Bool operator!() + { + return !fOut || !fIn; + } + + private: + Void (*fOut)(T Data) = {nullptr}; + Void (*fIn)(T Data) = {nullptr}; + }; + + /// + /// @brief Input Output Buffer + /// Used mainly to communicate between hardware. + /// + template + class IOBuf final + { + public: + explicit IOBuf(T Dat) + : fData(Dat) + { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } + + IOBuf& operator=(const IOBuf&) = default; + IOBuf(const IOBuf&) = default; + + ~IOBuf() = default; + + public: + template + R operator->() const + { + return fData; + } + + template + R& operator[](Size index) const + { + return fData[index]; + } + + private: + T fData; + }; + + ///! @brief Device enum types. + enum + { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeMedia, + kDeviceTypeCount, + }; +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/DriveManager.hxx b/dev/ZKA/KernelKit/DriveManager.hxx deleted file mode 100644 index 96fbd95d..00000000 --- a/dev/ZKA/KernelKit/DriveManager.hxx +++ /dev/null @@ -1,151 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef __INC_DRIVE_MANAGER_HXX__ -#define __INC_DRIVE_MANAGER_HXX__ - -#include -#include -#include -#include -#include -#include -#include - -#define kDriveManagerCount (4U) - -#define kDriveInvalidID (-1) -#define kDriveNameLen (32) - -#define drv_get_sector_count(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) - -namespace Kernel -{ - enum - { - kInvalidDrive = -1, - kBlockDevice = 0xAD, - kMassStorage = 0xDA, - kFloppyDisc = 0xCD, - kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray - /// combine with below. - kReadOnly = 0x10, // Read only drive - kEPMDrive = 0x11, // Explicit Partition Map. - kEPTDrive = 0x12, // ESP w/ EPM partition. - kMBRDrive = 0x13, // IBM PC classic partition scheme - kDriveCnt = 9, - }; - - typedef Int64 rt_drive_id_type; - - /// @brief Media drive trait type. - struct DriveTrait final - { - Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... - Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. - rt_drive_id_type fId; // Drive id. - Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive - - /// @brief Packet drive (StorageKit compilant.) - struct DrivePacket final - { - VoidPtr fPacketContent; //! packet body. - Char fPacketMime[kDriveNameLen]; //! identify what we're sending. - SizeT fPacketSize; //! packet size - UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false - Boolean fPacketGood; - Lba fLba; - } fPacket; - - Void (*fInput)(DrivePacket* packetPtr); - Void (*fOutput)(DrivePacket* packetPtr); - Void (*fVerify)(DrivePacket* packetPtr); - const Char* (*fDriveKind)(Void); - }; - - ///! drive as a device. - typedef DriveTrait* DriveTraitPtr; - - /** - * @brief Mounted drives interface. - * @note This class has all of it's drive set to nullptr, allocate them using - * GetAddressOf(index). - */ - class MountpointInterface final - { - public: - explicit MountpointInterface() = default; - ~MountpointInterface() = default; - - ZKA_COPY_DEFAULT(MountpointInterface); - - public: - DriveTrait& A() - { - return mA; - } - DriveTrait& B() - { - return mB; - } - DriveTrait& C() - { - return mC; - } - DriveTrait& D() - { - return mD; - } - - DriveTraitPtr GetAddressOf(Int32 index) - { - ErrLocal() = kErrorSuccess; - - switch (index) - { - case 0: - return &mA; - case 1: - return &mB; - case 2: - return &mC; - case 3: - return &mD; - default: { - ErrLocal() = kErrorNoSuchDisk; - kcout << "newoskrnl.exe: No such disk.\n"; - - break; - } - } - - return nullptr; - } - - private: - DriveTrait mA, mB, mC, mD; - }; - - /// @brief Unimplemented drive. - /// @param pckt - /// @return - Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt); - - /// @brief Gets the drive kind (ATA, SCSI, AHCI...) - /// @param - /// @return the drive kind (ATA, Flash, NVM) - const Char* io_drive_kind(Void); - - /// @brief Makes a new drive. - /// @return the new drive as a trait. - DriveTrait io_construct_drive(void) noexcept; - - /// @brief Fetches the main drive. - /// @return the new drive as a trait. - DriveTrait io_construct_main_drive(void) noexcept; -} // namespace Kernel - -#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */ diff --git a/dev/ZKA/KernelKit/DriveMgr.hxx b/dev/ZKA/KernelKit/DriveMgr.hxx new file mode 100644 index 00000000..4b2cdc73 --- /dev/null +++ b/dev/ZKA/KernelKit/DriveMgr.hxx @@ -0,0 +1,151 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __INC_DRIVE_MANAGER_HXX__ +#define __INC_DRIVE_MANAGER_HXX__ + +#include +#include +#include +#include +#include +#include +#include + +#define kDriveMgrCount (4U) + +#define kDriveInvalidID (-1) +#define kDriveNameLen (32) + +#define drv_get_sector_count(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) + +namespace Kernel +{ + enum + { + kInvalidDrive = -1, + kBlockDevice = 0xAD, + kMassStorage = 0xDA, + kFloppyDisc = 0xCD, + kOpticalDisc = 0xDC, // CD-ROM/DVD-ROM/Blu-Ray + /// combine with below. + kReadOnly = 0x10, // Read only drive + kEPMDrive = 0x11, // Explicit Partition Map. + kEPTDrive = 0x12, // ESP w/ EPM partition. + kMBRDrive = 0x13, // IBM PC classic partition scheme + kDriveCnt = 9, + }; + + typedef Int64 rt_drive_id_type; + + /// @brief Media drive trait type. + struct DriveTrait final + { + Char fName[kDriveNameLen]; // /System, /Boot, //./Devices/USB... + Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc. + rt_drive_id_type fId; // Drive id. + Int32 fFlags; // fReadOnly, fXPMDrive, fXPTDrive + + /// @brief Packet drive (StorageKit compilant.) + struct DrivePacket final + { + VoidPtr fPacketContent; //! packet body. + Char fPacketMime[kDriveNameLen]; //! identify what we're sending. + SizeT fPacketSize; //! packet size + UInt32 fPacketCRC32; //! sanity crc, in case if good is set to false + Boolean fPacketGood; + Lba fLba; + } fPacket; + + Void (*fInput)(DrivePacket* packetPtr); + Void (*fOutput)(DrivePacket* packetPtr); + Void (*fVerify)(DrivePacket* packetPtr); + const Char* (*fDriveKind)(Void); + }; + + ///! drive as a device. + typedef DriveTrait* DriveTraitPtr; + + /** + * @brief Mounted drives interface. + * @note This class has all of it's drive set to nullptr, allocate them using + * GetAddressOf(index). + */ + class MountpointInterface final + { + public: + explicit MountpointInterface() = default; + ~MountpointInterface() = default; + + ZKA_COPY_DEFAULT(MountpointInterface); + + public: + DriveTrait& A() + { + return mA; + } + DriveTrait& B() + { + return mB; + } + DriveTrait& C() + { + return mC; + } + DriveTrait& D() + { + return mD; + } + + DriveTraitPtr GetAddressOf(Int32 index) + { + ErrLocal() = kErrorSuccess; + + switch (index) + { + case 0: + return &mA; + case 1: + return &mB; + case 2: + return &mC; + case 3: + return &mD; + default: { + ErrLocal() = kErrorNoSuchDisk; + kcout << "newoskrnl.exe: No such disk.\n"; + + break; + } + } + + return nullptr; + } + + private: + DriveTrait mA, mB, mC, mD; + }; + + /// @brief Unimplemented drive. + /// @param pckt + /// @return + Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt); + + /// @brief Gets the drive kind (ATA, SCSI, AHCI...) + /// @param + /// @return the drive kind (ATA, Flash, NVM) + const Char* io_drive_kind(Void); + + /// @brief Makes a new drive. + /// @return the new drive as a trait. + DriveTrait io_construct_drive(void) noexcept; + + /// @brief Fetches the main drive. + /// @return the new drive as a trait. + DriveTrait io_construct_main_drive(void) noexcept; +} // namespace Kernel + +#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */ diff --git a/dev/ZKA/KernelKit/FileManager.hxx b/dev/ZKA/KernelKit/FileManager.hxx deleted file mode 100644 index 05f74a63..00000000 --- a/dev/ZKA/KernelKit/FileManager.hxx +++ /dev/null @@ -1,420 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: FileManager.hxx - Purpose: Kernel file manager. - -------------------------------------------- */ - -/* ------------------------------------------- - - Revision History: - - 31/01/24: Update documentation (amlel) - 05/07/24: NewFS support, and fork support, updated constants and specs - as well. - - ------------------------------------------- */ - -#pragma once - -#ifdef __FSKIT_USE_NEWFS__ -#include -#endif // __FSKIT_USE_NEWFS__ - -#include -#include -#include -#include -#include -#include -#include -#include - -/// @brief Filesystem manager, abstraction over mounted filesystem. -/// Works like the VFS or IFS. - -#define cRestrictR "r" -#define cRestrictRB "rb" -#define cRestrictW "w" -#define cRestrictWB "rw" -#define cRestrictRWB "rwb" - -#define cRestrictMax 5 - -#define node_cast(PTR) reinterpret_cast(PTR) - -/** - @note Refer to first enum. -*/ -#define cFileOpsCount 4 -#define cFileMimeGeneric "n-application-kind/all" - -/** @brief invalid position. (n-pos) */ -#define kNPos (SizeT)(-1); - -namespace Kernel -{ - enum - { - cFileWriteAll = 100, - cFileReadAll = 101, - cFileReadChunk = 102, - cFileWriteChunk = 103, - cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1, - // file flags - cFileFlagRsrc = 104, - cFileFlagData = 105, - }; - - typedef VoidPtr NodePtr; - - /** - @brief Filesystem Manager Interface class - @brief Used to provide common I/O for a specific filesystem. -*/ - class FilesystemManagerInterface - { - public: - explicit FilesystemManagerInterface() = default; - virtual ~FilesystemManagerInterface() = default; - - public: - ZKA_COPY_DEFAULT(FilesystemManagerInterface); - - public: - /// @brief Mounts a new filesystem into an active state. - /// @param interface the filesystem interface - /// @return - static bool Mount(FilesystemManagerInterface* interface); - - /// @brief Unmounts the active filesystem - /// @return - static FilesystemManagerInterface* Unmount(); - - /// @brief Getter, gets the active filesystem. - /// @return - static FilesystemManagerInterface* GetMounted(); - - public: - virtual NodePtr Create(_Input const Char* path) = 0; - virtual NodePtr CreateAlias(_Input const Char* path) = 0; - virtual NodePtr CreateDirectory(_Input const Char* path) = 0; - virtual NodePtr CreateSwapFile(const Char* path) = 0; - - public: - virtual bool Remove(_Input const Char* path) = 0; - - public: - virtual NodePtr Open(_Input const Char* path, _Input const Char* r) = 0; - - public: - virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; - - virtual _Output VoidPtr Read(_Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) = 0; - - virtual Void Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) = 0; - - virtual _Output VoidPtr Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) = 0; - - public: - virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; - - public: - virtual SizeT Tell(_Input NodePtr node) = 0; - virtual bool Rewind(_Input NodePtr node) = 0; - }; - -#ifdef __FSKIT_USE_NEWFS__ - /** - * @brief Based of FilesystemManagerInterface, takes care of managing NewFS - * disks. - */ - class NewFilesystemManager final : public FilesystemManagerInterface - { - public: - explicit NewFilesystemManager(); - ~NewFilesystemManager() override; - - public: - ZKA_COPY_DEFAULT(NewFilesystemManager); - - public: - NodePtr Create(const Char* path) override; - NodePtr CreateAlias(const Char* path) override; - NodePtr CreateDirectory(const Char* path) override; - NodePtr CreateSwapFile(const Char* path) override; - - public: - bool Remove(const Char* path) override; - NodePtr Open(const Char* path, const Char* r) override; - Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; - VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; - bool Seek(NodePtr node, SizeT off) override; - SizeT Tell(NodePtr node) override; - bool Rewind(NodePtr node) override; - - Void Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) override; - - _Output VoidPtr Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) override; - - public: - /// @brief Get NewFS parser class. - /// @return The filesystem parser class. - NewFSParser* GetParser() noexcept; - - private: - NewFSParser* fImpl{nullptr}; - }; - -#endif // ifdef __FSKIT_USE_NEWFS__ - - /** - * Usable FileStream - * @tparam Encoding file encoding (char, wchar_t...) - * @tparam FSClass Filesystem contract who takes care of it. - */ - template - class FileStream final - { - public: - explicit FileStream(const Encoding* path, const Encoding* restrict_type); - ~FileStream(); - - public: - FileStream& operator=(const FileStream&); - FileStream(const FileStream&); - - public: - ErrorOr WriteAll(const VoidPtr data) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return ErrorOr(kErrorInvalidData); - - if (data == nullptr) - return ErrorOr(kErrorInvalidData); - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Write(fFile, data, cFileWriteAll); - return ErrorOr(0); - } - - return ErrorOr(kErrorInvalidData); - } - - VoidPtr ReadAll() noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - VoidPtr ret = man->Read(fFile, cFileReadAll, 0); - return ret; - } - - return nullptr; - } - - ErrorOr WriteAll(const Char* fName, const VoidPtr data) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return ErrorOr(kErrorInvalidData); - - if (data == nullptr) - return ErrorOr(kErrorInvalidData); - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Write(fName, fFile, data, cFileWriteAll); - return ErrorOr(0); - } - - return ErrorOr(kErrorInvalidData); - } - - VoidPtr Read(const Char* fName) noexcept - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0); - return ret; - } - - return nullptr; - } - - VoidPtr Read(SizeT offset, SizeT sz) - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictRead && - this->fFileRestrict != eRestrictReadBinary) - return nullptr; - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Seek(fFile, offset); - auto ret = man->Read(fFile, cFileReadChunk, sz); - - return ret; - } - - return nullptr; - } - - Void Write(SizeT offset, voidPtr data, SizeT sz) - { - if (this->fFileRestrict != eRestrictReadWrite && - this->fFileRestrict != eRestrictReadWriteBinary && - this->fFileRestrict != eRestrictWrite && - this->fFileRestrict != eRestrictWriteBinary) - return; - - auto man = FSClass::GetMounted(); - - if (man) - { - man->Seek(fFile, offset); - man->Write(fFile, data, sz, cFileReadChunk); - } - } - - public: - /// @brief Leak node pointer. - /// @return The node pointer. - NodePtr Leak() - { - return fFile; - } - - /// @brief Leak MIME. - /// @return The MIME. - Char* MIME() noexcept - { - return const_cast(fMime); - } - - enum - { - eRestrictRead, - eRestrictReadBinary, - eRestrictWrite, - eRestrictWriteBinary, - eRestrictReadWrite, - eRestrictReadWriteBinary, - }; - - private: - NodePtr fFile{nullptr}; - Int32 fFileRestrict{}; - const Char* fMime{cFileMimeGeneric}; - }; - - using FileStreamUTF8 = FileStream; - using FileStreamUTF16 = FileStream; - - typedef UInt64 CursorType; - - /// @brief constructor - template - FileStream::FileStream(const Encoding* path, - const Encoding* restrict_type) - : fFile(Class::GetMounted()->Open(path, restrict_type)) - { - static const auto cLength = 255; - - /// @brief restrict information about the file descriptor. - struct RESTRICT_MAP final - { - Char fRestrict[cLength]; - Int32 fMappedTo; - }; - - const SizeT cRestrictCount = cRestrictMax; - const RESTRICT_MAP cRestrictList[] = { - { - .fRestrict = cRestrictR, - .fMappedTo = eRestrictRead, - }, - { - .fRestrict = cRestrictRB, - .fMappedTo = eRestrictReadBinary, - }, - { - .fRestrict = cRestrictRWB, - .fMappedTo = eRestrictReadWriteBinary, - }, - { - .fRestrict = cRestrictW, - .fMappedTo = eRestrictWrite, - }, - { - .fRestrict = cRestrictWB, - .fMappedTo = eRestrictReadWrite, - }}; - - for (SizeT index = 0; index < cRestrictCount; ++index) - { - if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict, - rt_string_len(cRestrictList[index].fRestrict)) == 0) - { - fFileRestrict = cRestrictList[index].fMappedTo; - break; - } - } - - kcout << "newoskrnl.exe: new file: " << path << ".\r"; - } - - /// @brief destructor - template - FileStream::~FileStream() - { - mm_delete_ke_heap(fFile); - } -} // namespace Kernel diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx new file mode 100644 index 00000000..7a97f821 --- /dev/null +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -0,0 +1,420 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: FileMgr.hxx + Purpose: Kernel file manager. + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Update documentation (amlel) + 05/07/24: NewFS support, and fork support, updated constants and specs + as well. + + ------------------------------------------- */ + +#pragma once + +#ifdef __FSKIT_USE_NEWFS__ +#include +#endif // __FSKIT_USE_NEWFS__ + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @brief Filesystem manager, abstraction over mounted filesystem. +/// Works like the VFS or IFS. + +#define cRestrictR "r" +#define cRestrictRB "rb" +#define cRestrictW "w" +#define cRestrictWB "rw" +#define cRestrictRWB "rwb" + +#define cRestrictMax 5 + +#define node_cast(PTR) reinterpret_cast(PTR) + +/** + @note Refer to first enum. +*/ +#define cFileOpsCount 4 +#define cFileMimeGeneric "n-application-kind/all" + +/** @brief invalid position. (n-pos) */ +#define kNPos (SizeT)(-1); + +namespace Kernel +{ + enum + { + cFileWriteAll = 100, + cFileReadAll = 101, + cFileReadChunk = 102, + cFileWriteChunk = 103, + cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1, + // file flags + cFileFlagRsrc = 104, + cFileFlagData = 105, + }; + + typedef VoidPtr NodePtr; + + /** + @brief Filesystem Mgr Interface class + @brief Used to provide common I/O for a specific filesystem. +*/ + class FilesystemMgrInterface + { + public: + explicit FilesystemMgrInterface() = default; + virtual ~FilesystemMgrInterface() = default; + + public: + ZKA_COPY_DEFAULT(FilesystemMgrInterface); + + public: + /// @brief Mounts a new filesystem into an active state. + /// @param interface the filesystem interface + /// @return + static bool Mount(FilesystemMgrInterface* interface); + + /// @brief Unmounts the active filesystem + /// @return + static FilesystemMgrInterface* Unmount(); + + /// @brief Getter, gets the active filesystem. + /// @return + static FilesystemMgrInterface* GetMounted(); + + public: + virtual NodePtr Create(_Input const Char* path) = 0; + virtual NodePtr CreateAlias(_Input const Char* path) = 0; + virtual NodePtr CreateDirectory(_Input const Char* path) = 0; + virtual NodePtr CreateSwapFile(const Char* path) = 0; + + public: + virtual bool Remove(_Input const Char* path) = 0; + + public: + virtual NodePtr Open(_Input const Char* path, _Input const Char* r) = 0; + + public: + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) = 0; + + virtual Void Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) = 0; + + public: + virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; + + public: + virtual SizeT Tell(_Input NodePtr node) = 0; + virtual bool Rewind(_Input NodePtr node) = 0; + }; + +#ifdef __FSKIT_USE_NEWFS__ + /** + * @brief Based of FilesystemMgrInterface, takes care of managing NewFS + * disks. + */ + class NewFilesystemMgr final : public FilesystemMgrInterface + { + public: + explicit NewFilesystemMgr(); + ~NewFilesystemMgr() override; + + public: + ZKA_COPY_DEFAULT(NewFilesystemMgr); + + public: + NodePtr Create(const Char* path) override; + NodePtr CreateAlias(const Char* path) override; + NodePtr CreateDirectory(const Char* path) override; + NodePtr CreateSwapFile(const Char* path) override; + + public: + bool Remove(const Char* path) override; + NodePtr Open(const Char* path, const Char* r) override; + Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; + VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; + bool Seek(NodePtr node, SizeT off) override; + SizeT Tell(NodePtr node) override; + bool Rewind(NodePtr node) override; + + Void Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) override; + + _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) override; + + public: + /// @brief Get NewFS parser class. + /// @return The filesystem parser class. + NewFSParser* GetParser() noexcept; + + private: + NewFSParser* fImpl{nullptr}; + }; + +#endif // ifdef __FSKIT_USE_NEWFS__ + + /** + * Usable FileStream + * @tparam Encoding file encoding (char, wchar_t...) + * @tparam FSClass Filesystem contract who takes care of it. + */ + template + class FileStream final + { + public: + explicit FileStream(const Encoding* path, const Encoding* restrict_type); + ~FileStream(); + + public: + FileStream& operator=(const FileStream&); + FileStream(const FileStream&); + + public: + ErrorOr WriteAll(const VoidPtr data) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr(kErrorInvalidData); + + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fFile, data, cFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr ReadAll() noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fFile, cFileReadAll, 0); + return ret; + } + + return nullptr; + } + + ErrorOr WriteAll(const Char* fName, const VoidPtr data) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return ErrorOr(kErrorInvalidData); + + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fName, fFile, data, cFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr Read(const Char* fName) noexcept + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0); + return ret; + } + + return nullptr; + } + + VoidPtr Read(SizeT offset, SizeT sz) + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictRead && + this->fFileRestrict != eRestrictReadBinary) + return nullptr; + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + auto ret = man->Read(fFile, cFileReadChunk, sz); + + return ret; + } + + return nullptr; + } + + Void Write(SizeT offset, voidPtr data, SizeT sz) + { + if (this->fFileRestrict != eRestrictReadWrite && + this->fFileRestrict != eRestrictReadWriteBinary && + this->fFileRestrict != eRestrictWrite && + this->fFileRestrict != eRestrictWriteBinary) + return; + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + man->Write(fFile, data, sz, cFileReadChunk); + } + } + + public: + /// @brief Leak node pointer. + /// @return The node pointer. + NodePtr Leak() + { + return fFile; + } + + /// @brief Leak MIME. + /// @return The MIME. + Char* MIME() noexcept + { + return const_cast(fMime); + } + + enum + { + eRestrictRead, + eRestrictReadBinary, + eRestrictWrite, + eRestrictWriteBinary, + eRestrictReadWrite, + eRestrictReadWriteBinary, + }; + + private: + NodePtr fFile{nullptr}; + Int32 fFileRestrict{}; + const Char* fMime{cFileMimeGeneric}; + }; + + using FileStreamUTF8 = FileStream; + using FileStreamUTF16 = FileStream; + + typedef UInt64 CursorType; + + /// @brief constructor + template + FileStream::FileStream(const Encoding* path, + const Encoding* restrict_type) + : fFile(Class::GetMounted()->Open(path, restrict_type)) + { + static const auto cLength = 255; + + /// @brief restrict information about the file descriptor. + struct RESTRICT_MAP final + { + Char fRestrict[cLength]; + Int32 fMappedTo; + }; + + const SizeT cRestrictCount = cRestrictMax; + const RESTRICT_MAP cRestrictList[] = { + { + .fRestrict = cRestrictR, + .fMappedTo = eRestrictRead, + }, + { + .fRestrict = cRestrictRB, + .fMappedTo = eRestrictReadBinary, + }, + { + .fRestrict = cRestrictRWB, + .fMappedTo = eRestrictReadWriteBinary, + }, + { + .fRestrict = cRestrictW, + .fMappedTo = eRestrictWrite, + }, + { + .fRestrict = cRestrictWB, + .fMappedTo = eRestrictReadWrite, + }}; + + for (SizeT index = 0; index < cRestrictCount; ++index) + { + if (rt_string_cmp(restrict_type, cRestrictList[index].fRestrict, + rt_string_len(cRestrictList[index].fRestrict)) == 0) + { + fFileRestrict = cRestrictList[index].fMappedTo; + break; + } + } + + kcout << "newoskrnl.exe: new file: " << path << ".\r"; + } + + /// @brief destructor + template + FileStream::~FileStream() + { + mm_delete_ke_heap(fFile); + } +} // namespace Kernel diff --git a/dev/ZKA/KernelKit/MP.hxx b/dev/ZKA/KernelKit/MP.hxx index 51f3472a..cf5d6754 100644 --- a/dev/ZKA/KernelKit/MP.hxx +++ b/dev/ZKA/KernelKit/MP.hxx @@ -103,7 +103,7 @@ namespace Kernel operator bool() noexcept; public: - /// @brief Shared instance of the MP Manager. + /// @brief Shared instance of the MP Mgr. /// @return the reference to the mp manager class. STATIC HardwareThreadScheduler& The(); diff --git a/dev/ZKA/KernelKit/PCI/Dma.hxx b/dev/ZKA/KernelKit/PCI/Dma.hxx index 43df13f0..8e51bc45 100644 --- a/dev/ZKA/KernelKit/PCI/Dma.hxx +++ b/dev/ZKA/KernelKit/PCI/Dma.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include diff --git a/dev/ZKA/KernelKit/PECodeManager.hxx b/dev/ZKA/KernelKit/PECodeManager.hxx deleted file mode 100644 index f42c7c21..00000000 --- a/dev/ZKA/KernelKit/PECodeManager.hxx +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: PECodeManager.hxx - Purpose: PE32+ Code Manager and Shared Objects. - - Revision History: - - 12/02/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -//////////////////////////////////////////////////// - -// LAST REV: Mon Feb 12 13:52:01 CET 2024 - -//////////////////////////////////////////////////// - -#include -#include -#include diff --git a/dev/ZKA/KernelKit/PECodeMgr.hxx b/dev/ZKA/KernelKit/PECodeMgr.hxx new file mode 100644 index 00000000..7b84fbc1 --- /dev/null +++ b/dev/ZKA/KernelKit/PECodeMgr.hxx @@ -0,0 +1,24 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: PECodeMgr.hxx + Purpose: PE32+ Code Mgr and Shared Objects. + + Revision History: + + 12/02/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +//////////////////////////////////////////////////// + +// LAST REV: Mon Feb 12 13:52:01 CET 2024 + +//////////////////////////////////////////////////// + +#include +#include +#include diff --git a/dev/ZKA/KernelKit/PEFCodeManager.hxx b/dev/ZKA/KernelKit/PEFCodeManager.hxx deleted file mode 100644 index dd6daca5..00000000 --- a/dev/ZKA/KernelKit/PEFCodeManager.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef _INC_CODE_MANAGER_PEF_HXX_ -#define _INC_CODE_MANAGER_PEF_HXX_ - -#include -#include -#include -#include - -#define kPefApplicationMime "application/x-newos-exec" - -namespace Kernel -{ - /// - /// \name PEFLoader - /// \brief PEF loader class. - /// - class PEFLoader : public LoaderInterface - { - private: - explicit PEFLoader() = delete; - - public: - explicit PEFLoader(const VoidPtr blob); - explicit PEFLoader(const Char* path); - ~PEFLoader() override; - - public: - ZKA_COPY_DEFAULT(PEFLoader); - - public: - const Char* Path() override; - const Char* AsString() override; - const Char* MIME() override; - - public: - ErrorOr FindStart() override; - VoidPtr FindSymbol(const Char* name, Int32 kind) override; - - public: - bool IsLoaded() noexcept; - - private: -#ifdef __FSKIT_USE_NEWFS__ - OwnPtr> fFile; -#else - OwnPtr> fFile; -#endif // __FSKIT_USE_NEWFS__ - - Ref fPath; - VoidPtr fCachedBlob; - bool fFatBinary; - bool fBad; - }; - - namespace Utils - { - bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept; - } // namespace Utils -} // namespace Kernel - -#endif // ifndef _INC_CODE_MANAGER_PEF_HXX_ diff --git a/dev/ZKA/KernelKit/PEFCodeMgr.hxx b/dev/ZKA/KernelKit/PEFCodeMgr.hxx new file mode 100644 index 00000000..74cc8eb0 --- /dev/null +++ b/dev/ZKA/KernelKit/PEFCodeMgr.hxx @@ -0,0 +1,67 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef _INC_CODE_MANAGER_PEF_HXX_ +#define _INC_CODE_MANAGER_PEF_HXX_ + +#include +#include +#include +#include + +#define kPefApplicationMime "application/x-newos-exec" + +namespace Kernel +{ + /// + /// \name PEFLoader + /// \brief PEF loader class. + /// + class PEFLoader : public LoaderInterface + { + private: + explicit PEFLoader() = delete; + + public: + explicit PEFLoader(const VoidPtr blob); + explicit PEFLoader(const Char* path); + ~PEFLoader() override; + + public: + ZKA_COPY_DEFAULT(PEFLoader); + + public: + const Char* Path() override; + const Char* AsString() override; + const Char* MIME() override; + + public: + ErrorOr FindStart() override; + VoidPtr FindSymbol(const Char* name, Int32 kind) override; + + public: + bool IsLoaded() noexcept; + + private: +#ifdef __FSKIT_USE_NEWFS__ + OwnPtr> fFile; +#else + OwnPtr> fFile; +#endif // __FSKIT_USE_NEWFS__ + + Ref fPath; + VoidPtr fCachedBlob; + bool fFatBinary; + bool fBad; + }; + + namespace Utils + { + bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept; + } // namespace Utils +} // namespace Kernel + +#endif // ifndef _INC_CODE_MANAGER_PEF_HXX_ diff --git a/dev/ZKA/KernelKit/PEFDLLInterface.hxx b/dev/ZKA/KernelKit/PEFDLLInterface.hxx index ef1a844f..d664bfd8 100644 --- a/dev/ZKA/KernelKit/PEFDLLInterface.hxx +++ b/dev/ZKA/KernelKit/PEFDLLInterface.hxx @@ -11,7 +11,7 @@ #define __KERNELKIT_SHARED_OBJECT_HXX__ #include -#include +#include #include #include @@ -96,7 +96,7 @@ namespace Kernel PEFLoader* fLoader{nullptr}; }; - typedef PEFDLLInterface* DLLInterfacePtr; + typedef DLLInterface* DLLInterfacePtr; EXTERN_C DLLInterfacePtr rtl_init_shared_object(UserProcess* header); EXTERN_C Void rtl_fini_shared_object(UserProcess* header, DLLInterfacePtr lib, Bool* successful); diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index 809dbb7f..78d75af6 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -10,6 +10,7 @@ #include #include #include +#include #include #define kSchedMinMicroTime (AffinityKind::kStandard) @@ -158,13 +159,13 @@ namespace Kernel SizeT StackSize{mib_cast(8)}; // shared library handle, reserved for kDLLKind types of executables only. - PEFDLLInterface* DLLPtr{nullptr}; + DLLInterface* DLLPtr{nullptr}; UserProcess* Parent{nullptr}; // Memory usage. SizeT UsedMemory{0}; SizeT FreeMemory{0}; - SizeT SizeMemory{gib_cast(4)}; + SizeT SizeMemory{mib_cast(64)}; enum { diff --git a/dev/ZKA/NetworkKit/NetworkDevice.hxx b/dev/ZKA/NetworkKit/NetworkDevice.hxx index c307a433..ed575e3e 100644 --- a/dev/ZKA/NetworkKit/NetworkDevice.hxx +++ b/dev/ZKA/NetworkKit/NetworkDevice.hxx @@ -7,7 +7,7 @@ #ifndef __INC_NETWORK_DEVICE_HPP__ #define __INC_NETWORK_DEVICE_HPP__ -#include +#include #include /// @note Can either work with: Ethernet, GPRS, WiFi diff --git a/dev/ZKA/NewKit/PageAllocator.hxx b/dev/ZKA/NewKit/PageAllocator.hxx index a6d84aa0..5b19c0c2 100644 --- a/dev/ZKA/NewKit/PageAllocator.hxx +++ b/dev/ZKA/NewKit/PageAllocator.hxx @@ -7,7 +7,7 @@ #pragma once #include -#include +#include namespace Kernel { diff --git a/dev/ZKA/NewKit/PageManager.hxx b/dev/ZKA/NewKit/PageManager.hxx deleted file mode 100644 index 0de37803..00000000 --- a/dev/ZKA/NewKit/PageManager.hxx +++ /dev/null @@ -1,79 +0,0 @@ -// a way to create and find our pages. -// I'm thinking about a separate way of getting a paged area. - -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel -{ - class PageManager; - - class PTEWrapper final - { - public: - explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0); - - ~PTEWrapper(); - - PTEWrapper& operator=(const PTEWrapper&) = default; - PTEWrapper(const PTEWrapper&) = default; - - public: - const UIntPtr VirtualAddress(); - - void NoExecute(const bool enable = false); - const bool& NoExecute(); - - operator bool() { return fVirtAddr; } - - bool Reclaim(); - bool Shareable(); - bool Present(); - bool Access(); - - private: - Boolean fRw; - Boolean fUser; - Boolean fExecDisable; - UIntPtr fVirtAddr; - Boolean fCache; - Boolean fShareable; - Boolean fWt; - Boolean fPresent; - Boolean fAccessed; - - private: - friend class PageManager; - friend class Pmm; - }; - - struct PageManager final - { - public: - PageManager() = default; - ~PageManager() = default; - - PageManager& operator=(const PageManager&) = default; - PageManager(const PageManager&) = default; - - public: - PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz); - bool Free(Ref& wrapper); - - private: - void FlushTLB(); - - private: - friend PTEWrapper; - friend class Pmm; - }; -} // namespace Kernel diff --git a/dev/ZKA/NewKit/PageMgr.hxx b/dev/ZKA/NewKit/PageMgr.hxx new file mode 100644 index 00000000..1f6b5021 --- /dev/null +++ b/dev/ZKA/NewKit/PageMgr.hxx @@ -0,0 +1,79 @@ +// a way to create and find our pages. +// I'm thinking about a separate way of getting a paged area. + +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel +{ + class PageMgr; + + class PTEWrapper final + { + public: + explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0); + + ~PTEWrapper(); + + PTEWrapper& operator=(const PTEWrapper&) = default; + PTEWrapper(const PTEWrapper&) = default; + + public: + const UIntPtr VirtualAddress(); + + void NoExecute(const bool enable = false); + const Bool& NoExecute(); + + operator bool() { return fVirtAddr; } + + bool Reclaim(); + bool Shareable(); + bool Present(); + bool Access(); + + private: + Boolean fRw; + Boolean fUser; + Boolean fExecDisable; + UIntPtr fVirtAddr; + Boolean fCache; + Boolean fShareable; + Boolean fWt; + Boolean fPresent; + Boolean fAccessed; + + private: + friend class PageMgr; + friend class Pmm; + }; + + struct PageMgr final + { + public: + PageMgr() = default; + ~PageMgr() = default; + + PageMgr& operator=(const PageMgr&) = default; + PageMgr(const PageMgr&) = default; + + public: + PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz); + bool Free(Ref& wrapper); + + private: + void FlushTLB(); + + private: + friend PTEWrapper; + friend class Pmm; + }; +} // namespace Kernel diff --git a/dev/ZKA/NewKit/Pmm.hxx b/dev/ZKA/NewKit/Pmm.hxx index 111b3044..cdf498d9 100644 --- a/dev/ZKA/NewKit/Pmm.hxx +++ b/dev/ZKA/NewKit/Pmm.hxx @@ -7,7 +7,7 @@ #pragma once -#include +#include #include namespace Kernel @@ -33,12 +33,12 @@ namespace Kernel Boolean ToggleShare(Ref refPage, Boolean enable = true); /// @brief Get the page manager of this. - Ref& Leak() + Ref& Leak() { - return fPageManager; + return fPageMgr; } private: - Ref fPageManager; + Ref fPageMgr; }; } // namespace Kernel diff --git a/dev/ZKA/Sources/CodeManager.cxx b/dev/ZKA/Sources/CodeManager.cxx deleted file mode 100644 index 7e180ac0..00000000 --- a/dev/ZKA/Sources/CodeManager.cxx +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include - -namespace Kernel -{ - /// @brief Executes a new process from a function. Kernel code only. - /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. - /// @param main the start of the process. - /// @return if the process was started or not. - bool sched_execute_thread(MainKind main, const Char* processName) noexcept - { - if (!main) - return false; - - UserProcess proc; - proc.SetImageStart(reinterpret_cast(main)); - - proc.Kind = UserProcess::kExeKind; - proc.StackSize = kib_cast(8); - - rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); - - return UserProcessScheduler::The().Add(proc) == kErrorSuccess; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx new file mode 100644 index 00000000..df5b0917 --- /dev/null +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include + +namespace Kernel +{ + /// @brief Executes a new process from a function. Kernel code only. + /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. + /// @param main the start of the process. + /// @return if the process was started or not. + bool sched_execute_thread(MainKind main, const Char* processName) noexcept + { + if (!main) + return false; + + UserProcess proc; + proc.SetImageStart(reinterpret_cast(main)); + + proc.Kind = UserProcess::kExeKind; + proc.StackSize = kib_cast(8); + + rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName)); + + return UserProcessScheduler::The().Add(proc) == kErrorSuccess; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 84c58b3a..88887ec3 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -11,18 +11,18 @@ #include #include #include -#include +#include #include #include #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include #include #include #include @@ -44,23 +44,23 @@ namespace Kernel::Detail /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { - Kernel::NewFilesystemManager* fNewFS{nullptr}; + Kernel::NewFilesystemMgr* fNewFS{nullptr}; public: /// @brief wizard constructor. explicit FilesystemInstaller() { - if (Kernel::FilesystemManagerInterface::GetMounted()) + if (Kernel::FilesystemMgrInterface::GetMounted()) { CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNewFS = reinterpret_cast(Kernel::FilesystemManagerInterface::GetMounted()); + fNewFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); } else { // Mounts a NewFS from main drive. - fNewFS = new Kernel::NewFilesystemManager(); + fNewFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemManagerInterface::Mount(fNewFS); + Kernel::FilesystemMgrInterface::Mount(fNewFS); CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.exe: Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } @@ -142,8 +142,8 @@ namespace Kernel::Detail ZKA_COPY_DEFAULT(FilesystemInstaller); /// @brief Grab the disk's NewFS reference. - /// @return NewFilesystemManager the filesystem interface - Kernel::NewFilesystemManager* Leak() + /// @return NewFilesystemMgr the filesystem interface + Kernel::NewFilesystemMgr* Leak() { return fNewFS; } diff --git a/dev/ZKA/Sources/DeviceManager.cxx b/dev/ZKA/Sources/DeviceManager.cxx deleted file mode 100644 index 229e0fb7..00000000 --- a/dev/ZKA/Sources/DeviceManager.cxx +++ /dev/null @@ -1,7 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include diff --git a/dev/ZKA/Sources/DeviceMgr.cxx b/dev/ZKA/Sources/DeviceMgr.cxx new file mode 100644 index 00000000..70d01984 --- /dev/null +++ b/dev/ZKA/Sources/DeviceMgr.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include diff --git a/dev/ZKA/Sources/DriveManager.cxx b/dev/ZKA/Sources/DriveManager.cxx deleted file mode 100644 index 84c9870f..00000000 --- a/dev/ZKA/Sources/DriveManager.cxx +++ /dev/null @@ -1,146 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include -#include - -/// @file DriveManager.cxx -/// @brief Kernel drive manager. - -namespace Kernel -{ - static UInt16 kATAIO = 0U; - static UInt8 kATAMaster = 0U; - - /// @brief reads from an ATA drive. - /// @param pckt - /// @return - Void ke_drv_input(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - -#ifdef __AHCI__ - drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); -#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); -#endif - } - - /// @brief Writes to an ATA drive. - /// @param pckt - /// @return - Void ke_drv_output(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - -#ifdef __AHCI__ - drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); -#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) - drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); -#endif - } - - /// @brief Executes a disk check on the ATA drive. - /// @param pckt - /// @return - Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) - { - if (!pckt) - { - return; - } - - pckt->fPacketGood = false; - -#if defined(__ATA_PIO__) || defined(__ATA_DMA__) - kATAMaster = true; - kATAIO = ATA_PRIMARY_IO; - - MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster)); -#elif defined(__AHCI__) - UInt16 pi = 0; - MUST_PASS(drv_std_init(pi)); -#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) - - pckt->fPacketGood = true; - } - -/// @brief Gets the drive kind (ATA, SCSI, AHCI...) -/// @param -/// @return -#ifdef __ATA_PIO__ - const Char* io_drive_kind(Void) - { - return "ATA-PIO"; - } -#endif - -#ifdef __ATA_DMA__ - const Char* io_drive_kind(Void) - { - return "ATA-DMA"; - } -#endif - -#ifdef __AHCI__ - const Char* io_drive_kind(Void) - { - return "AHCI"; - } -#endif - - /// @brief Unimplemented drive. - /// @param pckt - /// @return - Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) - { - } - - /// @brief Makes a new drive. - /// @return the new drive. - DriveTrait io_construct_drive() noexcept - { - DriveTrait trait; - - rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); - trait.fKind = kInvalidDrive; - - trait.fInput = io_drv_unimplemented; - trait.fOutput = io_drv_unimplemented; - trait.fVerify = io_drv_unimplemented; - trait.fDriveKind = io_drive_kind; - - return trait; - } - - /// @brief Fetches the main drive. - /// @return the new drive. - DriveTrait io_construct_main_drive() noexcept - { - DriveTrait trait; - - rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); - trait.fKind = kMassStorage; - - trait.fInput = ke_drv_input; - trait.fOutput = ke_drv_output; - trait.fVerify = ke_drv_check_disk; - trait.fDriveKind = io_drive_kind; - - kcout << "newoskrnl.exe: Construct drive with success.\r"; - - return trait; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx new file mode 100644 index 00000000..376eb158 --- /dev/null +++ b/dev/ZKA/Sources/DriveMgr.cxx @@ -0,0 +1,146 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include + +/// @file DriveMgr.cxx +/// @brief Kernel drive manager. + +namespace Kernel +{ + static UInt16 kATAIO = 0U; + static UInt8 kATAMaster = 0U; + + /// @brief reads from an ATA drive. + /// @param pckt + /// @return + Void ke_drv_input(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + +#ifdef __AHCI__ + drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); +#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) + drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); +#endif + } + + /// @brief Writes to an ATA drive. + /// @param pckt + /// @return + Void ke_drv_output(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + +#ifdef __AHCI__ + drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize); +#elif defined(__ATA_PIO__) || defined(__ATA_DMA__) + drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize); +#endif + } + + /// @brief Executes a disk check on the ATA drive. + /// @param pckt + /// @return + Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt) + { + if (!pckt) + { + return; + } + + pckt->fPacketGood = false; + +#if defined(__ATA_PIO__) || defined(__ATA_DMA__) + kATAMaster = true; + kATAIO = ATA_PRIMARY_IO; + + MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster)); +#elif defined(__AHCI__) + UInt16 pi = 0; + MUST_PASS(drv_std_init(pi)); +#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__) + + pckt->fPacketGood = true; + } + +/// @brief Gets the drive kind (ATA, SCSI, AHCI...) +/// @param +/// @return +#ifdef __ATA_PIO__ + const Char* io_drive_kind(Void) + { + return "ATA-PIO"; + } +#endif + +#ifdef __ATA_DMA__ + const Char* io_drive_kind(Void) + { + return "ATA-DMA"; + } +#endif + +#ifdef __AHCI__ + const Char* io_drive_kind(Void) + { + return "AHCI"; + } +#endif + + /// @brief Unimplemented drive. + /// @param pckt + /// @return + Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) + { + } + + /// @brief Makes a new drive. + /// @return the new drive. + DriveTrait io_construct_drive() noexcept + { + DriveTrait trait; + + rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:")); + trait.fKind = kInvalidDrive; + + trait.fInput = io_drv_unimplemented; + trait.fOutput = io_drv_unimplemented; + trait.fVerify = io_drv_unimplemented; + trait.fDriveKind = io_drive_kind; + + return trait; + } + + /// @brief Fetches the main drive. + /// @return the new drive. + DriveTrait io_construct_main_drive() noexcept + { + DriveTrait trait; + + rt_copy_memory((VoidPtr) "\\Mount\\MainDisk:", trait.fName, rt_string_len("\\Mount\\MainDisk:")); + trait.fKind = kMassStorage; + + trait.fInput = ke_drv_input; + trait.fOutput = ke_drv_output; + trait.fVerify = ke_drv_check_disk; + trait.fDriveKind = io_drive_kind; + + kcout << "newoskrnl.exe: Construct drive with success.\r"; + + return trait; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/FileManager.cxx b/dev/ZKA/Sources/FileManager.cxx deleted file mode 100644 index 8c8fb83a..00000000 --- a/dev/ZKA/Sources/FileManager.cxx +++ /dev/null @@ -1,190 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -/// BUGS: 0 -//! @brief File manager for Kernel. - -namespace Kernel -{ - STATIC FilesystemManagerInterface* kMounted = nullptr; - - /// @brief FilesystemManager getter. - /// @return The mounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::GetMounted() - { - return kMounted; - } - - /// @brief Unmount filesystem. - /// @return The unmounted filesystem. - _Output FilesystemManagerInterface* FilesystemManagerInterface::Unmount() - { - if (kMounted) - { - auto mount = kMounted; - kMounted = nullptr; - - return mount; - } - - return nullptr; - } - - /// @brief Mount filesystem. - /// @param mount_ptr The filesystem to mount. - /// @return if it succeeded true, otherwise false. - bool FilesystemManagerInterface::Mount(_Input FilesystemManagerInterface* mount_ptr) - { - if (mount_ptr != nullptr) - { - kMounted = mount_ptr; - return true; - } - - return false; - } - -#ifdef __FSKIT_USE_NEWFS__ - /// @brief Opens a new file. - /// @param path - /// @param r - /// @return - _Output NodePtr NewFilesystemManager::Open(_Input const Char* path, _Input const Char* r) - { - if (!path || *path == 0) - return nullptr; - - if (!r || *r == 0) - return nullptr; - - auto catalog = fImpl->GetCatalog(path); - - return node_cast(catalog); - } - - /// @brief Writes to a catalog's fork. - /// @param node the node ptr. - /// @param data the data. - /// @param flags the size. - /// @return - Void NewFilesystemManager::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return; - if (!size) - return; - - constexpr auto cDataForkName = kNewFSDataFork; - this->Write(cDataForkName, node, data, flags, size); - } - - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - _Output VoidPtr NewFilesystemManager::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return nullptr; - if (!size) - return nullptr; - - constexpr auto cDataForkName = kNewFSDataFork; - return this->Read(cDataForkName, node, flags, size); - } - - Void NewFilesystemManager::Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) - { - if (!size || - size > kNewFSForkSize) - return; - - if (!data) - return; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, - name); - } - - _Output VoidPtr NewFilesystemManager::Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) - { - if (sz > kNewFSForkSize) - return nullptr; - - if (!sz) - return nullptr; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, - name); - - return nullptr; - } - - /// @brief Seek from Catalog. - /// @param node - /// @param off - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NewFilesystemManager::Seek(NodePtr node, SizeT off) - { - if (!node || off == 0) - return false; - - return fImpl->Seek(reinterpret_cast(node), off); - } - - /// @brief Tell where the catalog is. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output SizeT NewFilesystemManager::Tell(NodePtr node) - { - if (!node) - return kNPos; - - return fImpl->Tell(reinterpret_cast(node)); - } - - /// @brief Rewinds the catalog. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NewFilesystemManager::Rewind(NodePtr node) - { - if (!node) - return false; - - return this->Seek(node, 0); - } - - /// @brief Returns the filesystem parser. - /// @return the Filesystem parser class. - _Output NewFSParser* NewFilesystemManager::GetParser() noexcept - { - return fImpl; - } -#endif // __FSKIT_USE_NEWFS__ -} // namespace Kernel diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx new file mode 100644 index 00000000..270c13f2 --- /dev/null +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -0,0 +1,190 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +/// BUGS: 0 +//! @brief File manager for Kernel. + +namespace Kernel +{ + STATIC FilesystemMgrInterface* kMounted = nullptr; + + /// @brief FilesystemMgr getter. + /// @return The mounted filesystem. + _Output FilesystemMgrInterface* FilesystemMgrInterface::GetMounted() + { + return kMounted; + } + + /// @brief Unmount filesystem. + /// @return The unmounted filesystem. + _Output FilesystemMgrInterface* FilesystemMgrInterface::Unmount() + { + if (kMounted) + { + auto mount = kMounted; + kMounted = nullptr; + + return mount; + } + + return nullptr; + } + + /// @brief Mount filesystem. + /// @param mount_ptr The filesystem to mount. + /// @return if it succeeded true, otherwise false. + bool FilesystemMgrInterface::Mount(_Input FilesystemMgrInterface* mount_ptr) + { + if (mount_ptr != nullptr) + { + kMounted = mount_ptr; + return true; + } + + return false; + } + +#ifdef __FSKIT_USE_NEWFS__ + /// @brief Opens a new file. + /// @param path + /// @param r + /// @return + _Output NodePtr NewFilesystemMgr::Open(_Input const Char* path, _Input const Char* r) + { + if (!path || *path == 0) + return nullptr; + + if (!r || *r == 0) + return nullptr; + + auto catalog = fImpl->GetCatalog(path); + + return node_cast(catalog); + } + + /// @brief Writes to a catalog's fork. + /// @param node the node ptr. + /// @param data the data. + /// @param flags the size. + /// @return + Void NewFilesystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return; + if (!size) + return; + + constexpr auto cDataForkName = kNewFSDataFork; + this->Write(cDataForkName, node, data, flags, size); + } + + /// @brief Read from filesystem fork. + /// @param node the catalog node. + /// @param flags the flags with it. + /// @param sz the size to read. + /// @return + _Output VoidPtr NewFilesystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return nullptr; + if (!size) + return nullptr; + + constexpr auto cDataForkName = kNewFSDataFork; + return this->Read(cDataForkName, node, flags, size); + } + + Void NewFilesystemMgr::Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) + { + if (!size || + size > kNewFSForkSize) + return; + + if (!data) + return; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, + name); + } + + _Output VoidPtr NewFilesystemMgr::Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) + { + if (sz > kNewFSForkSize) + return nullptr; + + if (!sz) + return nullptr; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, + name); + + return nullptr; + } + + /// @brief Seek from Catalog. + /// @param node + /// @param off + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NewFilesystemMgr::Seek(NodePtr node, SizeT off) + { + if (!node || off == 0) + return false; + + return fImpl->Seek(reinterpret_cast(node), off); + } + + /// @brief Tell where the catalog is. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output SizeT NewFilesystemMgr::Tell(NodePtr node) + { + if (!node) + return kNPos; + + return fImpl->Tell(reinterpret_cast(node)); + } + + /// @brief Rewinds the catalog. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NewFilesystemMgr::Rewind(NodePtr node) + { + if (!node) + return false; + + return this->Seek(node, 0); + } + + /// @brief Returns the filesystem parser. + /// @return the Filesystem parser class. + _Output NewFSParser* NewFilesystemMgr::GetParser() noexcept + { + return fImpl; + } +#endif // __FSKIT_USE_NEWFS__ +} // namespace Kernel diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index e036badb..615f5664 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -8,7 +8,7 @@ #include #include #include -#include +#include //! @file KernelHeap.cxx //! @brief Kernel heap allocator. @@ -19,7 +19,7 @@ namespace Kernel { SizeT kHeapCount = 0UL; - PageManager kHeapPageManager; + PageMgr kHeapPageMgr; Bool kOperationInProgress = No; /// @brief Contains data structures and algorithms for the heap. @@ -71,13 +71,13 @@ namespace Kernel if (!allocatedPtr || newSz < 1) return nullptr; - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)allocatedPtr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fHeapSize = newSz; + heap_blk->fHeapSize = newSz; - if (heapInfoBlk->fCRC32 > 0) + if (heap_blk->fCRC32 > 0) { MUST_PASS(mm_protect_ke_heap(allocatedPtr)); } @@ -97,9 +97,9 @@ namespace Kernel auto szFix = sz; if (szFix == 0) - ++szFix; + return nullptr; - auto wrapper = kHeapPageManager.Request(rw, user, No, szFix); + auto wrapper = kHeapPageMgr.Request(rw, user, No, szFix); Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr = reinterpret_cast( @@ -107,11 +107,11 @@ namespace Kernel heap_info_ptr->fHeapSize = szFix; heap_info_ptr->fMagic = kKernelHeapMagic; - heap_info_ptr->fCRC32 = 0U; // dont fill it for now. - heap_info_ptr->fHeapPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); - heap_info_ptr->fPage = 0UL; + heap_info_ptr->fCRC32 = No; // dont fill it for now. + heap_info_ptr->fHeapPtr = reinterpret_cast(heap_info_ptr) + sizeof(Detail::HEAP_INFORMATION_BLOCK); + heap_info_ptr->fPage = No; heap_info_ptr->fUser = user; - heap_info_ptr->fPresent = true; + heap_info_ptr->fPresent = No; ++kHeapCount; @@ -138,11 +138,11 @@ namespace Kernel Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - heapInfoBlk->fPage = true; + heap_blk->fPage = true; Detail::mm_alloc_fini_timeout(); @@ -156,48 +156,47 @@ namespace Kernel { if (kHeapCount < 1) return -kErrorInternal; - if (((IntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)) <= 0) - return -kErrorInternal; - if (((IntPtr)heap_ptr - kInvalidAddress) < 0) - return -kErrorInternal; + + if (!heap_ptr) + return -kErrorInvalidData; Detail::mm_alloc_init_timeout(); - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk && heapInfoBlk->fMagic == kKernelHeapMagic) + if (heap_blk && heap_blk->fMagic == kKernelHeapMagic) { - if (!heapInfoBlk->fPresent) + if (!heap_blk->fPresent) { Detail::mm_alloc_fini_timeout(); return -kErrorHeapNotPresent; } - if (heapInfoBlk->fCRC32 != 0) + if (heap_blk->fCRC32 != 0) { - if (heapInfoBlk->fCRC32 != - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, - heapInfoBlk->fHeapSize)) + if (heap_blk->fCRC32 != + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, + heap_blk->fHeapSize)) { - if (!heapInfoBlk->fUser) + if (!heap_blk->fUser) { ke_stop(RUNTIME_CHECK_POINTER); } } } - heapInfoBlk->fHeapSize = 0UL; - heapInfoBlk->fPresent = false; - heapInfoBlk->fHeapPtr = 0; - heapInfoBlk->fCRC32 = 0; - heapInfoBlk->fMagic = 0; + heap_blk->fHeapSize = 0UL; + heap_blk->fPresent = No; + heap_blk->fHeapPtr = 0; + heap_blk->fCRC32 = 0; + heap_blk->fMagic = 0; - PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heapInfoBlk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - Ref pteAddress{&pageWrapper}; + PTEWrapper pageWrapper(false, false, false, reinterpret_cast(heap_blk) - sizeof(Detail::HEAP_INFORMATION_BLOCK)); + Ref pteAddress{pageWrapper}; - kHeapPageManager.Free(pteAddress); + kHeapPageMgr.Free(pteAddress); --kHeapCount; @@ -239,14 +238,14 @@ namespace Kernel { if (heap_ptr) { - Detail::HEAP_INFORMATION_BLOCK_PTR heapInfoBlk = + Detail::HEAP_INFORMATION_BLOCK_PTR heap_blk = reinterpret_cast( (UIntPtr)heap_ptr - sizeof(Detail::HEAP_INFORMATION_BLOCK)); - if (heapInfoBlk->fPresent && kKernelHeapMagic == heapInfoBlk->fMagic) + if (heap_blk->fPresent && kKernelHeapMagic == heap_blk->fMagic) { - heapInfoBlk->fCRC32 = - ke_calculate_crc32((Char*)heapInfoBlk->fHeapPtr, heapInfoBlk->fHeapSize); + heap_blk->fCRC32 = + ke_calculate_crc32((Char*)heap_blk->fHeapPtr, heap_blk->fHeapSize); return true; } diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx index 7429751f..c5cab5dc 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/MP.cxx @@ -17,12 +17,6 @@ namespace Kernel { - /***********************************************************************************/ - /// @brief MP object container property. - /***********************************************************************************/ - - Property cSMPCoreName; - ///! A HardwareThread class takes care of it's owned hardware thread. ///! It has a stack for it's core. @@ -102,13 +96,13 @@ namespace Kernel { return mp_register_process(fStack); } - - //! SMP is disabled here. - - mp_do_context_switch_pre(); - mp_do_context_switch(image, stack_ptr, fStack); - - return true; + else + { + mp_do_context_switch_pre(); + mp_do_context_switch(image, stack_ptr, fStack); + + return false; + } } ///! @brief Tells if processor is waked up. @@ -123,15 +117,7 @@ namespace Kernel ///! @brief Constructor and destructors. ///! @brief Default constructor. - HardwareThreadScheduler::HardwareThreadScheduler() - { - kcout << "newoskrnl.exe: Initializing HardwareThreadScheduler." << endl; - - cSMPCoreName.GetKey() += "Property\\MPClass"; - cSMPCoreName.GetValue() = (PropertyId)this; - - kcout << "newoskrnl.exe: Initialized HardwareThreadScheduler." << endl; - } + HardwareThreadScheduler::HardwareThreadScheduler() = default; ///! @brief Default destructor. HardwareThreadScheduler::~HardwareThreadScheduler() = default; diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NewFS+FileManager.cxx deleted file mode 100644 index 20fb623d..00000000 --- a/dev/ZKA/Sources/NewFS+FileManager.cxx +++ /dev/null @@ -1,109 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __FSKIT_USE_NEWFS__ - -/// @brief NewFS File manager. -/// BUGS: 0 - -namespace Kernel -{ - /// @brief C++ constructor - NewFilesystemManager::NewFilesystemManager() - { - MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NewFSParser(); - MUST_PASS(fImpl); - - kcout << "newoskrnl.exe: We are done here... (NewFilesystemManager).\r"; - } - - NewFilesystemManager::~NewFilesystemManager() - { - kcout << "newoskrnl.exe: Destroying it...\r"; - - if (fImpl) - { - delete fImpl; - } - } - - /// @brief Removes a node from the filesystem. - /// @param fileName The filename - /// @return If it was deleted or not. - bool NewFilesystemManager::Remove(const Char* fileName) - { - if (fileName == nullptr || *fileName == 0) - return false; - - return fImpl->RemoveCatalog(fileName); - } - - /// @brief Creates a node with the specified. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::Create(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path)); - } - - /// @brief Creates a node with is a directory. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateDirectory(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); - } - - /// @brief Creates a node with is a alias. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateAlias(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); - } - - /// @brief Creates a node with is a page file. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NewFilesystemManager::CreateSwapFile(const Char* path) - { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); - } - - /// @brief Gets the root directory. - /// @return - const Char* NewFilesystemHelper::Root() - { - return kNewFSRoot; - } - - /// @brief Gets the up-dir directory. - /// @return - const Char* NewFilesystemHelper::UpDir() - { - return kNewFSUpDir; - } - - /// @brief Gets the separator character. - /// @return - const Char NewFilesystemHelper::Separator() - { - return kNewFSSeparator; - } - - /// @brief Gets the metafile character. - /// @return - const Char NewFilesystemHelper::MetaFile() - { - return kNewFSMetaFilePrefix; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx new file mode 100644 index 00000000..dd0d4a21 --- /dev/null +++ b/dev/ZKA/Sources/NewFS+FileMgr.cxx @@ -0,0 +1,109 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +#ifdef __FSKIT_USE_NEWFS__ + +/// @brief NewFS File manager. +/// BUGS: 0 + +namespace Kernel +{ + /// @brief C++ constructor + NewFilesystemMgr::NewFilesystemMgr() + { + MUST_PASS(Detail::fs_init_newfs()); + fImpl = new NewFSParser(); + MUST_PASS(fImpl); + + kcout << "newoskrnl.exe: We are done here... (NewFilesystemMgr).\r"; + } + + NewFilesystemMgr::~NewFilesystemMgr() + { + kcout << "newoskrnl.exe: Destroying it...\r"; + + if (fImpl) + { + delete fImpl; + } + } + + /// @brief Removes a node from the filesystem. + /// @param fileName The filename + /// @return If it was deleted or not. + bool NewFilesystemMgr::Remove(const Char* fileName) + { + if (fileName == nullptr || *fileName == 0) + return false; + + return fImpl->RemoveCatalog(fileName); + } + + /// @brief Creates a node with the specified. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::Create(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path)); + } + + /// @brief Creates a node with is a directory. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); + } + + /// @brief Creates a node with is a alias. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateAlias(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); + } + + /// @brief Creates a node with is a page file. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) + { + return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); + } + + /// @brief Gets the root directory. + /// @return + const Char* NewFilesystemHelper::Root() + { + return kNewFSRoot; + } + + /// @brief Gets the up-dir directory. + /// @return + const Char* NewFilesystemHelper::UpDir() + { + return kNewFSUpDir; + } + + /// @brief Gets the separator character. + /// @return + const Char NewFilesystemHelper::Separator() + { + return kNewFSSeparator; + } + + /// @brief Gets the metafile character. + /// @return + const Char NewFilesystemHelper::MetaFile() + { + return kNewFSMetaFilePrefix; + } +} // namespace Kernel + +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NewFS+IO.cxx index ddcecde4..e1a6ac95 100644 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ b/dev/ZKA/Sources/NewFS+IO.cxx @@ -4,8 +4,8 @@ ------------------------------------------- */ -#include -#include +#include +#include /************************************************************* * diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx index 6504b2bc..2f63cc9a 100644 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ b/dev/ZKA/Sources/NewFS+Journal.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/PEFCodeManager.cxx b/dev/ZKA/Sources/PEFCodeManager.cxx deleted file mode 100644 index 526312e0..00000000 --- a/dev/ZKA/Sources/PEFCodeManager.cxx +++ /dev/null @@ -1,252 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/// @brief PEF stack size symbol. -#define cPefStackSizeSymbol "SizeOfReserveStack" - -namespace Kernel -{ - namespace Detail - { - /// @brief Get the PEF platform signature according to the compiled backebnd - UInt32 rt_get_pef_platform(void) noexcept - { -#ifdef __ZKA_32X0__ - return kPefArch32x0; -#elif defined(__ZKA_64X0__) - return kPefArch64x0; -#elif defined(__ZKA_AMD64__) - return kPefArchAMD64; -#elif defined(__ZKA_PPC64__) - return kPefArchPowerPC; -#elif defined(__ZKA_ARM64__) - return kPefArchARM64; -#else - return kPefArchInvalid; -#endif // __32x0__ || __64x0__ || __x86_64__ - } - } // namespace Detail - - /// @brief PEF loader constructor w/ blob. - /// @param blob - PEFLoader::PEFLoader(const VoidPtr blob) - : fCachedBlob(blob) - { - MUST_PASS(fCachedBlob); - fBad = false; - } - - /// @brief PEF loader constructor. - /// @param path the filesystem path. - PEFLoader::PEFLoader(const Char* path) - : fCachedBlob(nullptr), fBad(false), fFatBinary(false) - { - fFile.New(const_cast(path), cRestrictRB); - fPath = StringBuilder::Construct(path).Leak(); - - auto cPefHeader = "PEF_CONTAINER"; - - fCachedBlob = fFile->Read(cPefHeader); - - PEFContainer* container = reinterpret_cast(fCachedBlob); - - if (container->Cpu == Detail::rt_get_pef_platform() && - container->Magic[0] == kPefMagic[0] && - container->Magic[1] == kPefMagic[1] && - container->Magic[2] == kPefMagic[2] && - container->Magic[3] == kPefMagic[3] && - container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi) - { - return; - } - else if (container->Magic[4] == kPefMagic[0] && - container->Magic[3] == kPefMagic[1] && - container->Magic[2] == kPefMagic[2] && - container->Magic[1] == kPefMagic[3] && - container->Magic[0] == kPefMagic[0] && container->Abi == kPefAbi) - { - /// This is a fat binary. - this->fFatBinary = true; - return; - } - - fBad = true; - - if (fCachedBlob) - mm_delete_ke_heap(fCachedBlob); - - kcout << "CodeManagerPEF: Warning: Executable format error!\r"; - fCachedBlob = nullptr; - } - - /// @brief PEF destructor. - PEFLoader::~PEFLoader() - { - if (fCachedBlob) - mm_delete_ke_heap(fCachedBlob); - - fFile.Delete(); - } - - VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind) - { - if (!fCachedBlob || fBad || !name) - return nullptr; - - PEFContainer* container = reinterpret_cast(fCachedBlob); - - auto blob = fFile->Read(name); - - PEFCommandHeader* container_header = reinterpret_cast(blob); - - constexpr auto cMangleCharacter = '$'; - const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; - - ErrorOr errOrSym; - - switch (kind) - { - case kPefCode: { - errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol. - break; - } - case kPefData: { - errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol. - break; - } - case kPefZero: { - errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol. - break; - } - default: - return nullptr; - } - - char* unconstSymbol = const_cast(name); - - for (SizeT i = 0UL; i < rt_string_len(unconstSymbol, kPefNameLen); ++i) - { - if (unconstSymbol[i] == ' ') - { - unconstSymbol[i] = cMangleCharacter; - } - } - - errOrSym.Leak().Leak() += name; - - for (SizeT index = 0; index < container->Count; ++index) - { - if (StringBuilder::Equals(container_header->Name, - errOrSym.Leak().Leak().CData())) - { - if (container_header->Kind == kind) - { - if (container_header->Cpu != Detail::rt_get_pef_platform()) - { - if (!this->fFatBinary) - { - mm_delete_ke_heap(blob); - return nullptr; - } - } - - Char* blobRet = new Char[container_header->Size]; - - HAL::mm_update_pte(blobRet, HAL::eFlagsPresent); - HAL::mm_update_pte(blobRet, HAL::eFlagsUser); - - if (container_header->Kind != kPefCode) - HAL::mm_update_pte(blobRet, HAL::eFlagsRw); - - rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size); - - mm_delete_ke_heap(blob); - return blobRet; - } - } - } - - mm_delete_ke_heap(blob); - return nullptr; - } - - /// @brief Finds the executable entrypoint. - /// @return - ErrorOr PEFLoader::FindStart() - { - if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym) - return ErrorOr(sym); - - return ErrorOr(kErrorExecutable); - } - - /// @brief Tells if the executable is loaded or not. - /// @return - bool PEFLoader::IsLoaded() noexcept - { - return !fBad && fCachedBlob; - } - - namespace Utils - { - Bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept - { - auto errOrStart = exec.FindStart(); - - if (errOrStart.Error() != kErrorSuccess) - return false; - - UserProcess proc; - - proc.SetImageStart(errOrStart.Leak().Leak()); - proc.Kind = procKind; - proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData); - - if (!proc.StackSize) - { - const auto cDefaultStackSizeMib = 8; - - proc.StackSize = mib_cast(cDefaultStackSizeMib); - } - - return UserProcessScheduler::The().Add(proc); - } - } // namespace Utils - - const Char* PEFLoader::Path() - { - return fPath.Leak().CData(); - } - - const Char* PEFLoader::AsString() - { -#ifdef __32x0__ - return "32x0 PEF format."; -#elif defined(__64x0__) - return "64x0 PEF format."; -#elif defined(__x86_64__) - return "x86_64 PEF format."; -#elif defined(__powerpc64__) - return "POWER PEF format."; -#else - return "Unknown PEF format."; -#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__ - } - - const Char* PEFLoader::MIME() - { - return kPefApplicationMime; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/PEFCodeMgr.cxx b/dev/ZKA/Sources/PEFCodeMgr.cxx new file mode 100644 index 00000000..feafc35c --- /dev/null +++ b/dev/ZKA/Sources/PEFCodeMgr.cxx @@ -0,0 +1,252 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @brief PEF stack size symbol. +#define cPefStackSizeSymbol "SizeOfReserveStack" + +namespace Kernel +{ + namespace Detail + { + /// @brief Get the PEF platform signature according to the compiled backebnd + UInt32 rt_get_pef_platform(void) noexcept + { +#ifdef __ZKA_32X0__ + return kPefArch32x0; +#elif defined(__ZKA_64X0__) + return kPefArch64x0; +#elif defined(__ZKA_AMD64__) + return kPefArchAMD64; +#elif defined(__ZKA_PPC64__) + return kPefArchPowerPC; +#elif defined(__ZKA_ARM64__) + return kPefArchARM64; +#else + return kPefArchInvalid; +#endif // __32x0__ || __64x0__ || __x86_64__ + } + } // namespace Detail + + /// @brief PEF loader constructor w/ blob. + /// @param blob + PEFLoader::PEFLoader(const VoidPtr blob) + : fCachedBlob(blob) + { + MUST_PASS(fCachedBlob); + fBad = false; + } + + /// @brief PEF loader constructor. + /// @param path the filesystem path. + PEFLoader::PEFLoader(const Char* path) + : fCachedBlob(nullptr), fBad(false), fFatBinary(false) + { + fFile.New(const_cast(path), cRestrictRB); + fPath = StringBuilder::Construct(path).Leak(); + + auto cPefHeader = "PEF_CONTAINER"; + + fCachedBlob = fFile->Read(cPefHeader); + + PEFContainer* container = reinterpret_cast(fCachedBlob); + + if (container->Cpu == Detail::rt_get_pef_platform() && + container->Magic[0] == kPefMagic[0] && + container->Magic[1] == kPefMagic[1] && + container->Magic[2] == kPefMagic[2] && + container->Magic[3] == kPefMagic[3] && + container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi) + { + return; + } + else if (container->Magic[4] == kPefMagic[0] && + container->Magic[3] == kPefMagic[1] && + container->Magic[2] == kPefMagic[2] && + container->Magic[1] == kPefMagic[3] && + container->Magic[0] == kPefMagic[0] && container->Abi == kPefAbi) + { + /// This is a fat binary. + this->fFatBinary = true; + return; + } + + fBad = true; + + if (fCachedBlob) + mm_delete_ke_heap(fCachedBlob); + + kcout << "CodeMgrPEF: Warning: Executable format error!\r"; + fCachedBlob = nullptr; + } + + /// @brief PEF destructor. + PEFLoader::~PEFLoader() + { + if (fCachedBlob) + mm_delete_ke_heap(fCachedBlob); + + fFile.Delete(); + } + + VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind) + { + if (!fCachedBlob || fBad || !name) + return nullptr; + + PEFContainer* container = reinterpret_cast(fCachedBlob); + + auto blob = fFile->Read(name); + + PEFCommandHeader* container_header = reinterpret_cast(blob); + + constexpr auto cMangleCharacter = '$'; + const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; + + ErrorOr errOrSym; + + switch (kind) + { + case kPefCode: { + errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol. + break; + } + case kPefData: { + errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol. + break; + } + case kPefZero: { + errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol. + break; + } + default: + return nullptr; + } + + char* unconstSymbol = const_cast(name); + + for (SizeT i = 0UL; i < rt_string_len(unconstSymbol, kPefNameLen); ++i) + { + if (unconstSymbol[i] == ' ') + { + unconstSymbol[i] = cMangleCharacter; + } + } + + errOrSym.Leak().Leak() += name; + + for (SizeT index = 0; index < container->Count; ++index) + { + if (StringBuilder::Equals(container_header->Name, + errOrSym.Leak().Leak().CData())) + { + if (container_header->Kind == kind) + { + if (container_header->Cpu != Detail::rt_get_pef_platform()) + { + if (!this->fFatBinary) + { + mm_delete_ke_heap(blob); + return nullptr; + } + } + + Char* blobRet = new Char[container_header->Size]; + + HAL::mm_update_pte(blobRet, HAL::eFlagsPresent); + HAL::mm_update_pte(blobRet, HAL::eFlagsUser); + + if (container_header->Kind != kPefCode) + HAL::mm_update_pte(blobRet, HAL::eFlagsRw); + + rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size); + + mm_delete_ke_heap(blob); + return blobRet; + } + } + } + + mm_delete_ke_heap(blob); + return nullptr; + } + + /// @brief Finds the executable entrypoint. + /// @return + ErrorOr PEFLoader::FindStart() + { + if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym) + return ErrorOr(sym); + + return ErrorOr(kErrorExecutable); + } + + /// @brief Tells if the executable is loaded or not. + /// @return + bool PEFLoader::IsLoaded() noexcept + { + return !fBad && fCachedBlob; + } + + namespace Utils + { + Bool execute_from_image(PEFLoader& exec, const Int32& procKind) noexcept + { + auto errOrStart = exec.FindStart(); + + if (errOrStart.Error() != kErrorSuccess) + return false; + + UserProcess proc; + + proc.SetImageStart(errOrStart.Leak().Leak()); + proc.Kind = procKind; + proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData); + + if (!proc.StackSize) + { + const auto cDefaultStackSizeMib = 8; + + proc.StackSize = mib_cast(cDefaultStackSizeMib); + } + + return UserProcessScheduler::The().Add(proc); + } + } // namespace Utils + + const Char* PEFLoader::Path() + { + return fPath.Leak().CData(); + } + + const Char* PEFLoader::AsString() + { +#ifdef __32x0__ + return "32x0 PEF format."; +#elif defined(__64x0__) + return "64x0 PEF format."; +#elif defined(__x86_64__) + return "x86_64 PEF format."; +#elif defined(__powerpc64__) + return "POWER PEF format."; +#else + return "Unknown PEF format."; +#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__ + } + + const Char* PEFLoader::MIME() + { + return kPefApplicationMime; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageManager.cxx deleted file mode 100644 index dd18709f..00000000 --- a/dev/ZKA/Sources/PageManager.cxx +++ /dev/null @@ -1,111 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include - -#ifdef __ZKA_AMD64__ -#include -#elif defined(__ZKA_ARM64__) -#include -#endif // ifdef __ZKA_AMD64__ || defined(__ZKA_ARM64__) - -//! null deref will throw (Page Zero detected, aborting app!) -#define kProtectedRegionEnd (512) - -namespace Kernel -{ - PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) - : fRw(Rw), - fUser(User), - fExecDisable(ExecDisable), - fVirtAddr(VirtAddr), - fCache(false), - fShareable(false), - fWt(false), - fPresent(true), - fAccessed(false) - { - } - - PTEWrapper::~PTEWrapper() = default; - - /// @brief Flush virtual address. - /// @param VirtAddr - Void PageManager::FlushTLB() - { - hal_flush_tlb(); - } - - /// @brief Reclaim freed page. - /// @return - Bool PTEWrapper::Reclaim() - { - if (!this->fPresent) - { - this->fPresent = true; - return true; - } - - return false; - } - - /// @brief Request a PTE. - /// @param Rw r/w? - /// @param User user mode? - /// @param ExecDisable disable execution on page? - /// @return - PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) - { - // Store PTE wrapper right after PTE. - VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); - - return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast(ptr)}; - } - - /// @brief Disable BitMap. - /// @param wrapper the wrapper. - /// @return If the page bitmap was cleared or not. - Bool PageManager::Free(Ref& wrapper) - { - if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper->VirtualAddress())) - return false; - - return true; - } - - /// @brief Virtual PTE address. - /// @return The virtual address of the page. - const UIntPtr PTEWrapper::VirtualAddress() - { - return (fVirtAddr); - } - - bool PTEWrapper::Shareable() - { - return fShareable; - } - - bool PTEWrapper::Present() - { - return fPresent; - } - - bool PTEWrapper::Access() - { - return fAccessed; - } - - void PTEWrapper::NoExecute(const bool enable) - { - this->fExecDisable = enable; - } - - const bool& PTEWrapper::NoExecute() - { - return this->fExecDisable; - } -} // namespace Kernel diff --git a/dev/ZKA/Sources/PageMgr.cxx b/dev/ZKA/Sources/PageMgr.cxx new file mode 100644 index 00000000..78b279f3 --- /dev/null +++ b/dev/ZKA/Sources/PageMgr.cxx @@ -0,0 +1,111 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include + +#ifdef __ZKA_AMD64__ +#include +#elif defined(__ZKA_ARM64__) +#include +#endif // ifdef __ZKA_AMD64__ || defined(__ZKA_ARM64__) + +//! null deref will throw (Page Zero detected, aborting app!) +#define kProtectedRegionEnd (512) + +namespace Kernel +{ + PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr) + : fRw(Rw), + fUser(User), + fExecDisable(ExecDisable), + fVirtAddr(VirtAddr), + fCache(false), + fShareable(false), + fWt(false), + fPresent(true), + fAccessed(false) + { + } + + PTEWrapper::~PTEWrapper() = default; + + /// @brief Flush virtual address. + /// @param VirtAddr + Void PageMgr::FlushTLB() + { + hal_flush_tlb(); + } + + /// @brief Reclaim freed page. + /// @return + Bool PTEWrapper::Reclaim() + { + if (!this->fPresent) + { + this->fPresent = true; + return true; + } + + return false; + } + + /// @brief Request a PTE. + /// @param Rw r/w? + /// @param User user mode? + /// @param ExecDisable disable execution on page? + /// @return + PTEWrapper PageMgr::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz) + { + // Store PTE wrapper right after PTE. + VoidPtr ptr = Kernel::HAL::mm_alloc_bitmap(Rw, User, Sz); + + return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast(ptr)}; + } + + /// @brief Disable BitMap. + /// @param wrapper the wrapper. + /// @return If the page bitmap was cleared or not. + Bool PageMgr::Free(Ref& wrapper) + { + if (!Kernel::HAL::mm_free_bitmap((VoidPtr)wrapper.Leak().VirtualAddress())) + return false; + + return true; + } + + /// @brief Virtual PTE address. + /// @return The virtual address of the page. + const UIntPtr PTEWrapper::VirtualAddress() + { + return (fVirtAddr); + } + + bool PTEWrapper::Shareable() + { + return fShareable; + } + + bool PTEWrapper::Present() + { + return fPresent; + } + + bool PTEWrapper::Access() + { + return fAccessed; + } + + void PTEWrapper::NoExecute(const bool enable) + { + this->fExecDisable = enable; + } + + const bool& PTEWrapper::NoExecute() + { + return this->fExecDisable; + } +} // namespace Kernel diff --git a/dev/ZKA/Sources/Pmm.cxx b/dev/ZKA/Sources/Pmm.cxx index b0855281..58335a2b 100644 --- a/dev/ZKA/Sources/Pmm.cxx +++ b/dev/ZKA/Sources/Pmm.cxx @@ -19,9 +19,9 @@ namespace Kernel { /// @brief Pmm constructor. Pmm::Pmm() - : fPageManager() + : fPageMgr() { - kcout << "[PMM] Allocate PageMemoryManager"; + kcout << "[PMM] Allocate PageMemoryMgr"; } Pmm::~Pmm() = default; @@ -31,17 +31,15 @@ namespace Kernel /// @param readWrite is it r/w? Ref Pmm::RequestPage(Boolean user, Boolean readWrite) { - PTEWrapper pt = fPageManager.Leak().Request(user, readWrite, false, kPTESize); + PTEWrapper pt = fPageMgr.Leak().Request(user, readWrite, false, kPTESize); if (pt.fPresent) { - kcout << "[PMM]: Allocation was successful.\r"; - return Ref(pt); + kcout << "[PMM]: Allocation failed.\r"; + return {}; } - kcout << "[PMM]: Allocation failed.\r"; - - return {}; + return Ref(pt); } Boolean Pmm::FreePage(Ref PageRef) diff --git a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx index 183481e1..97d2e2e4 100644 --- a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx +++ b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) @@ -69,7 +69,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) if (!Data) return *this; - for (SizeT driveCount = 0; driveCount < kDriveManagerCount; ++driveCount) + for (SizeT driveCount = 0; driveCount < kDriveMgrCount; ++driveCount) { auto interface = Data->GetAddressOf(driveCount); if ((interface) && rt_string_cmp((interface)->fDriveKind(), "ATA-", 5) == 0) diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx index 871d011f..5aa688be 100644 --- a/dev/ZKA/Sources/User.cxx +++ b/dev/ZKA/Sources/User.cxx @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 26d8be79..48988e57 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -34,7 +34,7 @@ namespace Kernel /// @brief UserProcess scheduler instance. /***********************************************************************************/ - STATIC UserProcessScheduler* cProcessScheduler; + STATIC UserProcessScheduler* cProcessScheduler = nullptr; /// @brief Gets the last exit code. /// @note Not thread-safe. diff --git a/dev/ZKA/StorageKit/AHCI.hxx b/dev/ZKA/StorageKit/AHCI.hxx index 3e9567a5..f3d771c9 100644 --- a/dev/ZKA/StorageKit/AHCI.hxx +++ b/dev/ZKA/StorageKit/AHCI.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include namespace Kernel diff --git a/dev/ZKA/StorageKit/ATA.hxx b/dev/ZKA/StorageKit/ATA.hxx index be3e4a21..e954b0e7 100644 --- a/dev/ZKA/StorageKit/ATA.hxx +++ b/dev/ZKA/StorageKit/ATA.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/dev/ZKA/StorageKit/NVME.hxx b/dev/ZKA/StorageKit/NVME.hxx index c0231f57..45d00c0c 100644 --- a/dev/ZKA/StorageKit/NVME.hxx +++ b/dev/ZKA/StorageKit/NVME.hxx @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #include namespace Kernel diff --git a/dev/ZKA/amd64-efi.make b/dev/ZKA/amd64-efi.make index 0e8cbad4..4d1f9403 100644 --- a/dev/ZKA/amd64-efi.make +++ b/dev/ZKA/amd64-efi.make @@ -35,7 +35,7 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is __ImageStart -LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x1000000 +LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 LDOBJ = Objects/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. -- cgit v1.2.3