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/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 +++--- 7 files changed, 78 insertions(+), 60 deletions(-) (limited to 'dev/ZKA/HALKit') 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"; -- cgit v1.2.3