diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-09-05 19:13:02 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-09-05 19:13:02 +0000 |
| commit | 621e814da6d5005ade8a1fe3f378a363db559cf7 (patch) | |
| tree | 438f1337c0eb2ae83cf3d409c29848d396be08b2 /dev/ZKA/HALKit | |
| parent | cc9ce57cac59bd443e2319e3b8f427172b93f7da (diff) | |
| parent | 3b60a1e87ab02a1b72d8bb9f7392780899d5a0d7 (diff) | |
Merged in major-refactor (pull request #19)
Major refactor
Diffstat (limited to 'dev/ZKA/HALKit')
20 files changed, 229 insertions, 288 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalAPIC.cxx b/dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx index caa2ce0b..caa2ce0b 100644 --- a/dev/ZKA/HALKit/AMD64/HalAPIC.cxx +++ b/dev/ZKA/HALKit/AMD64/HalAPICMgr.cxx diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx new file mode 100644 index 00000000..221cb044 --- /dev/null +++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx @@ -0,0 +1,103 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <ArchKit/ArchKit.hxx> + +#define cVMHMagic ((Kernel::UIntPtr)0x10210) + +#ifdef __ZKA_AMD64__ +#include <HALKit/AMD64/HalPageAlloc.hxx> +#elif defined(__ZKA_ARM64__) +#include <HALKit/ARM64/HalPageAlloc.hxx> +#endif + +#include <NewKit/Defines.hxx> +#include <NewKit/KernelCheck.hxx> + +namespace Kernel +{ + namespace HAL + { + namespace Detail + { + struct AllocatorTraits final + { + /// @brief Iterate over availables pages for a free one. + /// @return The new address which was found. + VoidPtr FindBitMap(VoidPtr base_ptr, SizeT size, Bool rw, Bool user) noexcept + { + while (base_ptr && size) + { + UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr); + + if (ptr_bit_set[0] != cVMHMagic) + { + ptr_bit_set[0] = cVMHMagic; + ptr_bit_set[1] = size; + ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + + kcout << "ALLOC STATUS\r"; + kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "ADDRESS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "ALLOC STATUS\r"; + + if (rw) + mm_update_pte(base_ptr, eFlagsRw); + + if (user) + mm_update_pte(base_ptr, eFlagsUser); + + return (VoidPtr)ptr_bit_set; + } + + base_ptr = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base_ptr) + __BIGGEST_ALIGNMENT__ + ptr_bit_set[1]); + } + + return nullptr; + } + }; + } // namespace Detail + + /// @brief Allocate a new page to be used by the OS. + /// @param rw read/write bit. + /// @param user user bit. + /// @return + auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr + { + VoidPtr ptr_new = nullptr; + Detail::AllocatorTraits traits; + + ptr_new = traits.FindBitMap(kKernelVirtualStart, size, rw, user); + + return ((UIntPtr*)ptr_new); + } + + auto mm_free_bitmap(VoidPtr page_ptr) -> Bool + { + if (!page_ptr) + return false; + + UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr); + + if (!ptr_bit_set[0] || + ptr_bit_set[0] != cVMHMagic) + return false; + + kcout << "FREE STATUS\r"; + kcout << "MAG: " << hex_number(ptr_bit_set[0]) << endl; + kcout << "ADDRESSS: " << hex_number((UIntPtr)ptr_bit_set) << endl; + kcout << "SIZE: " << hex_number(ptr_bit_set[1]) << endl; + kcout << "FREE STATUS\r"; + + ptr_bit_set[0] = 0UL; + ptr_bit_set[1] = 0UL; + ptr_bit_set[2] = __BIGGEST_ALIGNMENT__; + + return true; + } + } // namespace HAL +} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index 611ec596..b49a688f 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -13,6 +13,9 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); + Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } /// @brief Handle page fault. @@ -20,14 +23,23 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } +EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) +{ + Kernel::UserProcessHelper::StartScheduling(); +} + /// @brief Handle math fault. /// @param rsp EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } @@ -44,6 +56,8 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + + Kernel::UserProcessHelper::StartScheduling(); Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } @@ -54,12 +68,12 @@ EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr { if (rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: syscall: enter.\r"; + kcout << "syscall: enter.\r"; if (kSyscalls[rcx].fHooked) (kSyscalls[rcx].fProc)((Kernel::VoidPtr)rdx); - Kernel::kcout << "newoskrnl.exe: syscall: exit.\r"; + kcout << "syscall: exit.\r"; } } @@ -70,11 +84,11 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr { if (rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: kerncall: enter.\r"; + kcout << "kerncall: enter.\r"; if (kKerncalls[rcx].fHooked) (kKerncalls[rcx].fProc)((Kernel::VoidPtr)rdx); - Kernel::kcout << "newoskrnl.exe: kerncall: exit.\r"; + kcout << "kerncall: exit.\r"; } } diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx index 2e76d73a..5f6c0552 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx @@ -16,7 +16,7 @@ // Needed for SMP. // #include <FirmwareKit/EFI.hxx> -#include <KernelKit/MP.hxx> +#include <KernelKit/HardwareThreadScheduler.hxx> #define kApicSignature "APIC" @@ -160,10 +160,10 @@ namespace Kernel::HAL { fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak(); - return true; + return Yes; } - return false; + return No; } /***********************************************************************************/ @@ -191,7 +191,7 @@ namespace Kernel::HAL cSMPInterrupt = 0; kSMPCount = 0; - kcout << "newoskrnl.exe: Probing MADT cores...\r"; + kcout << "Probing MADT cores...\r"; UIntPtr madt_address = kMADTBlock->Address; @@ -205,13 +205,13 @@ namespace Kernel::HAL { case 0x00: { cSMPCores[index] = kMADTBlock->List[index].LAPIC.ProcessorID; - kcout << "newoskrnl.exe: Core ID: " << number(cSMPCores[index]) << endl; + kcout << "Core ID: " << number(cSMPCores[index]) << endl; ++kSMPCount; break; } case 0x05: { madt_address = kMADTBlock->List[index].LAPIC_ADDRESS_OVERRIDE.Address; - kcout << "newoskrnl.exe: Address: " << number(madt_address) << endl; + kcout << "Address: " << number(madt_address) << endl; break; } } @@ -219,7 +219,7 @@ namespace Kernel::HAL ++index; } - kcout << "newoskrnl.exe: # of cores: " << number(kSMPCount) << endl; + kcout << "# of cores: " << number(kSMPCount) << endl; // Kernel is now SMP aware. // That means that the scheduler is now available (on MP Kernels) diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx index 4474295f..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 @@ -47,8 +50,6 @@ namespace Kernel::HAL for (UInt16 idt_indx = 0; idt_indx < 12; ++idt_indx) { - MUST_PASS(ptr_ivt[idt_indx]); - Detail::kInterruptVectorTable[idt_indx].Selector = kGdtKernelCodeSelector; Detail::kInterruptVectorTable[idt_indx].Ist = 0; Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kTrapGate; @@ -62,8 +63,6 @@ namespace Kernel::HAL for (UInt16 idt_indx = 13; idt_indx < kKernelIdtSize; ++idt_indx) { - MUST_PASS(ptr_ivt[idt_indx]); - Detail::kInterruptVectorTable[idt_indx].Selector = kGdtKernelCodeSelector; Detail::kInterruptVectorTable[idt_indx].Ist = 0; Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kInterruptGate; @@ -77,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<RegisterGDT>& 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 34398871..79d9c097 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include <ArchKit/ArchKit.hxx> #include <Modules/CoreCG/FbRenderer.hxx> #include <FirmwareKit/Handover.hxx> -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <KernelKit/Framebuffer.hxx> #include <KernelKit/Heap.hxx> -#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/PEFCodeMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <NewKit/Json.hxx> #include <Modules/CoreCG/Accessibility.hxx> -#include <KernelKit/CodeManager.hxx> +#include <KernelKit/CodeMgr.hxx> #include <Modules/ACPI/ACPIFactoryInterface.hxx> #include <NetworkKit/IPC.hxx> #include <CFKit/Property.hxx> @@ -56,7 +56,6 @@ namespace Kernel::HAL Kernel::Property cKernelVersion; Kernel::User cUserSuper{Kernel::RingKind::kRingSuperUser, kSuperUser}; -EXTERN Kernel::Boolean kAllocationInProgress; EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; Kernel::Void hal_real_init(Kernel::Void) noexcept; @@ -65,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( @@ -93,17 +92,12 @@ EXTERN_C void hal_init_platform( Kernel::Void hal_real_init(Kernel::Void) noexcept { - // reset kAllocationInProgress field to zero. - kAllocationInProgress = false; - - kKernelVMHStart = kHandoverHeader->f_HeapStart; - // get page size. kKernelVirtualSize = kHandoverHeader->f_VirtualSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( - reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_VirtualStart)); + reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart)); // get physical address start. kKernelPhysicalStart = reinterpret_cast<Kernel::VoidPtr>( @@ -131,14 +125,13 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; + kcout << "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/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index dc534589..c26a346f 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -21,23 +21,25 @@ section .text ;; rcx: code ptr. ;; rdx: stack ptr. mp_do_context_switch: - mov rsp, rdx - mov rbp, rsp + 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 rax, rcx + mov r11, gs + mov r12, fs mov r11, 0x202 + mov fs, [r8 + (8 * 4)] + mov gs, [r8 + (8 * 9)] + mov r8, [r8] + o64 sysret ;; @brief Gets the current stack frame. @@ -49,8 +51,6 @@ extern hal_system_call_enter global mp_system_call_handler mp_system_call_handler: - swapgs - push r8 push r9 push r10 @@ -61,26 +61,29 @@ mp_system_call_handler: pop r9 pop r8 - swapgs - sti - o64 sysret mp_do_context_switch_pre: + xor rdx, rdx + mov rax, 0x202 + mov rcx, 0xc0000084 + wrmsr + + mov rdx, mp_system_call_handler + shr rdx, 32 + mov rcx, 0xc0000082 + wrmsr + + ; Enable SCE that enables sysret and syscall + mov rcx, 0xc0000082 + wrmsr mov rcx, 0xc0000080 rdmsr or eax, 1 wrmsr - mov rcx, 0xc0000081 rdmsr - mov rax, 0x00000000 mov edx, 0x00180008 wrmsr - mov rcx, 0xc0000082 - mov rax, mp_system_call_handler - mov rdx, 0x0 - wrmsr - ret diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx deleted file mode 100644 index 28b5f9be..00000000 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ /dev/null @@ -1,149 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <ArchKit/ArchKit.hxx> - -#define cVMHMagic (0xDEEFD00D) -#define cPaddingVMH (16) - -#ifdef __ZKA_AMD64__ -#include <HALKit/AMD64/HalPageAlloc.hxx> -#elif defined(__ZKA_ARM64__) -#include <HALKit/ARM64/HalPageAlloc.hxx> -#endif - -#include <NewKit/Defines.hxx> -#include <NewKit/KernelCheck.hxx> - -Kernel::Boolean kAllocationInProgress = false; - -namespace Kernel -{ - namespace HAL - { - namespace Detail - { - struct VIRTUAL_MEMORY_HEADER - { - UInt32 Magic; - Boolean Present : 1; - Boolean ReadWrite : 1; - Boolean User : 1; - SizeT Size; - }; - - struct VirtualMemoryHeaderTraits final - { - /// @brief Get next header. - /// @param current - /// @return - VIRTUAL_MEMORY_HEADER* Next(VIRTUAL_MEMORY_HEADER* current) - { - if (current->Magic != cVMHMagic) - return current; - - return current + sizeof(VIRTUAL_MEMORY_HEADER) + current->Size; - } - - /// @brief Get previous header. - /// @param current - /// @return - VIRTUAL_MEMORY_HEADER* Prev(VIRTUAL_MEMORY_HEADER* current) - { - if (current->Magic != cVMHMagic) - return current; - - return current - sizeof(VIRTUAL_MEMORY_HEADER) - current->Size; - } - }; - } // namespace Detail - - /// @brief Allocates a new page of memory. - /// @param sz the size of it. - /// @param rw read/write flag. - /// @param user user flag. - /// @return the page table of it. - STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - if (kAllocationInProgress) - return nullptr; - - kAllocationInProgress = true; - - //! fetch from the start. - Detail::VIRTUAL_MEMORY_HEADER* vmh_header = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>(kKernelVMHStart); - Detail::VirtualMemoryHeaderTraits traits; - - while (vmh_header->Present && - vmh_header->Magic == cVMHMagic) - { - vmh_header = traits.Next(vmh_header); - - if (vmh_header == reinterpret_cast<VoidPtr>(kBadPtr)) - { - ke_stop(RUNTIME_CHECK_POINTER); - return nullptr; - } - } - - vmh_header->Magic = cVMHMagic; - vmh_header->Present = true; - vmh_header->ReadWrite = rw; - vmh_header->User = user; - vmh_header->Size = size; - - kAllocationInProgress = false; - - VoidPtr result = reinterpret_cast<VoidPtr>(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER)); - - mm_update_pte(result, (rw ? eFlagsRw : 0)); - mm_update_pte(result, (user ? eFlagsUser : 0)); - - return result; - } - - /// @brief Allocate a new page to be used by the OS. - /// @param rw read/write bit. - /// @param user user bit. - /// @return - auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr - { - kcout << "PageAlloc: Waiting now..."; - - // Wait for a ongoing allocation to complete. - while (kAllocationInProgress) - { - (Void)0; - } - - kcout << ", done waiting, allocating...\r"; - - if (size == 0) - ++size; - - // Now allocate the page. - return hal_try_alloc_new_page(rw, user, size); - } - - auto hal_free_page(VoidPtr page_ptr) -> Bool - { - if (!page_ptr) - return false; - - Detail::VIRTUAL_MEMORY_HEADER* result = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>((UIntPtr)page_ptr - sizeof(Detail::VIRTUAL_MEMORY_HEADER)); - - if (result->Magic != cVMHMagic) - return false; - - if (result->Present != true) - return true; - - result->Present = false; - - return true; - } - } // namespace HAL -} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index aadabd9c..8eb85e78 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -87,8 +87,8 @@ namespace Kernel::HAL ZKA_PTE ALIGN(kPTEAlign) Pte[kPTEMax]; }; - auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr; - auto hal_free_page(VoidPtr page_ptr) -> Bool; + auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr; + auto mm_free_bitmap(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index 407b7e51..3c34ab68 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -27,32 +27,37 @@ namespace Kernel::HAL // Access PML4 entry volatile UInt64* pml4_entry = (volatile UInt64*)(((UInt64)pml4_base) + pml4_idx * sizeof(UIntPtr)); - UInt64 pdpt_base = *pml4_entry & ~0xFFF; // Remove flags (assuming 4KB pages) + UInt64 pdpt_base = *pml4_entry & ~0xFFF; // Remove flags (assuming 4KB pages) // Access PDPT entry volatile UInt64* pdpt_entry = (volatile UInt64*)(((UInt64)pdpt_base) + pdpt_idx * sizeof(UIntPtr)); - UInt64 pd_base = *pdpt_entry & ~0xFFF; // Remove flags + UInt64 pd_base = *pdpt_entry & ~0xFFF; // Remove flags + // Now PD volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pd_base) + pd_idx * sizeof(UIntPtr)); UInt64 pt_base = *pd_entry & ~0xFFF; // Remove flags + // And then PTE volatile UInt64* page_addr = (volatile UInt64*)(((UInt64)pt_base) + (pte_idx * sizeof(UIntPtr))); - if (page_addr) - { - if (flags & eFlagsPresent) - *page_addr |= 0x01; // present bit + if (flags & eFlagsPresent) + *page_addr |= 0x01; // present bit + else if (flags & ~eFlagsPresent) + *page_addr &= 0x01; // present bit - if (flags & eFlagsRw) - *page_addr |= 0x02; + if (flags & eFlagsRw) + *page_addr |= 0x02; + else if (flags & ~eFlagsRw) + *page_addr &= 0x02; // present bit - if (flags & eFlagsUser) - *page_addr |= 0x02; + if (flags & eFlagsUser) + *page_addr |= 0x04; + else if (flags & ~eFlagsUser) + *page_addr &= 0x04; // present bit - return Yes; - } + hal_write_cr3((UIntPtr)pml4_base); - return No; + return 0; } Void Out8(UInt16 port, UInt8 value) diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index a80e13cb..0636c291 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -56,11 +56,10 @@ namespace Kernel::HAL /// @brief Virtual memory flags. enum { - eFlagsPresent, - eFlagsUser, - eFlagsRw, - eFlagsExecDisable, - eFlagsCount, + eFlagsPresent = 0x01, + eFlagsRw = 0x02, + eFlagsUser = 0x04, + eFlagsCount = 0x3, }; /// @brief Updates a PTE from pd_base. @@ -102,15 +101,15 @@ namespace Kernel::HAL /// @brief Stack frame (as retrieved from assembly.) 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; @@ -293,7 +292,6 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr); #define kKernelIdtSize 0x100 #define kKernelInterruptId 0x32 -inline Kernel::VoidPtr kKernelVMHStart = nullptr; inline Kernel::VoidPtr kKernelVirtualStart = nullptr; inline Kernel::UIntPtr kKernelVirtualSize = 0UL; diff --git a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx index 889b8c39..7eaa5bbb 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/AHCI.cxx @@ -63,7 +63,7 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) { if (ports_implemented) { - kcout << "newoskrnl.exe: Port is implemented by host.\r"; + kcout << "Port is implemented by host.\r"; UInt8 ipm = (mem_ahci->Ports[ahci_index].Ssts >> 8) & 0x0F; UInt8 det = mem_ahci->Ports[ahci_index].Ssts & 0x0F; @@ -72,8 +72,8 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) det == cAhciPresent && ipm == cAhciIPMActive) { - kcout << "newoskrnl.exe: Found AHCI controller.\r"; - kcout << "newoskrnl.exe: Device is of SATA type.\r"; + kcout << "Found AHCI controller.\r"; + kcout << "Device is of SATA type.\r"; detected = true; diff --git a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx index 996b93ee..bc1a1f22 100644 --- a/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/dev/ZKA/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -68,7 +68,7 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) drv_std_select(IO); - Kernel::kcout << "newoskrnl.exe: Initializing drive...\r"; + kcout << "Initializing drive...\r"; ATAInit_Retry: // Bus init, NEIN bit. @@ -80,7 +80,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { - Kernel::kcout << "newoskrnl.exe: Failing drive...\r"; + kcout << "Failing drive...\r"; return false; } @@ -107,7 +107,7 @@ ATAInit_Retry: OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - Kernel::kcout << "newoskrnl.exe: Create ATA module.\r"; + kcout << "Created IDE module.\r"; return true; } diff --git a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx index 52e4f1ee..140c3370 100644 --- a/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/ARM64/HalKernelMain.cxx @@ -7,14 +7,14 @@ #include <ArchKit/ArchKit.hxx> #include <Modules/CoreCG/FbRenderer.hxx> #include <FirmwareKit/Handover.hxx> -#include <KernelKit/FileManager.hxx> +#include <KernelKit/FileMgr.hxx> #include <KernelKit/Framebuffer.hxx> #include <KernelKit/Heap.hxx> -#include <KernelKit/PEFCodeManager.hxx> +#include <KernelKit/PEFCodeMgr.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <NewKit/Json.hxx> #include <Modules/CoreCG/Accessibility.hxx> -#include <KernelKit/CodeManager.hxx> +#include <KernelKit/CodeMgr.hxx> #include <Modules/ACPI/ACPIFactoryInterface.hxx> #include <NetworkKit/IPC.hxx> #include <CFKit/Property.hxx> @@ -76,14 +76,12 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept // reset kAllocationInProgress field to zero. kAllocationInProgress = false; - kKernelVMHStart = kHandoverHeader->f_HeapStart; - // get page size. kKernelVirtualSize = kHandoverHeader->f_VirtualSize; // get virtual address start (for the heap) kKernelVirtualStart = reinterpret_cast<Kernel::VoidPtr>( - reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_VirtualStart)); + reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart)); // get physical address start. kKernelPhysicalStart = reinterpret_cast<Kernel::VoidPtr>( @@ -94,14 +92,14 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept else Kernel::HAL::mp_get_cores(nullptr); - Kernel::kcout << "newoskrnl.exe: Creating filesystem and such.\r"; + kcout << "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/HALKit/ARM64/HalPageAlloc.hxx b/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx index ef3b6db1..ab77f1d0 100644 --- a/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/ARM64/HalPageAlloc.hxx @@ -96,7 +96,7 @@ namespace Kernel::HAL LongDescLevel3 ALIGN(kPTEAlign) Pte[kPTEMax]; }; - VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size); + VoidPtr mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size); } // namespace Kernel::HAL namespace Kernel diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx index 1880d36c..ad2bdc7b 100644 --- a/dev/ZKA/HALKit/ARM64/Processor.hxx +++ b/dev/ZKA/HALKit/ARM64/Processor.hxx @@ -42,7 +42,6 @@ namespace Kernel::HAL typedef StackFrame* StackFramePtr; } // namespace Kernel::HAL -inline Kernel::VoidPtr kKernelVMHStart = nullptr; inline Kernel::VoidPtr kKernelVirtualStart = nullptr; inline Kernel::UIntPtr kKernelVirtualSize = 0UL; diff --git a/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx b/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx index 97950a78..f1f6c718 100644 --- a/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx +++ b/dev/ZKA/HALKit/ARM64/Storage/HalFlash.cxx @@ -53,13 +53,13 @@ namespace Kernel /// @brief Enable flash memory at slot. STATIC Void drv_enable_flash(Int32 arg) { - kcout << "newoskrnl.exe: Enabled FLSH hardware.\r"; + kcout << "Enabled FLSH hardware.\r"; } /// @brief Disable flash memory at slot. STATIC Void drv_disable_flash(Int32 arg) { - kcout << "newoskrnl.exe: Disabled FLSH hardware.\r"; + kcout << "Disabled FLSH hardware.\r"; } } // namespace Kernel diff --git a/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 5f71380d..254e1ab6 100644 --- a/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/dev/ZKA/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -14,11 +14,11 @@ EXTERN_C void rt_syscall_handle(Kernel::HAL::StackFrame* stack) { if (stack->Rcx <= (kSyscalls.Count() - 1)) { - Kernel::kcout << "newoskrnl.exe: syscall: enter.\r"; + kcout << "syscall: enter.\r"; if (kSyscalls[stack->Rcx].Leak().Leak().fHooked) (kSyscalls[stack->Rcx].Leak().Leak().fProc)(stack); - Kernel::kcout << "newoskrnl.exe: syscall: exit.\r"; + kcout << "syscall: exit.\r"; } } diff --git a/dev/ZKA/HALKit/POWER/HalHardware.cxx b/dev/ZKA/HALKit/POWER/HalHardware.cxx deleted file mode 100644 index 9fb841c8..00000000 --- a/dev/ZKA/HALKit/POWER/HalHardware.cxx +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <HALKit/POWER/Processor.hxx> -#include <KernelKit/DebugOutput.hxx> - -namespace Kernel -{ - namespace HAL - { - UIntPtr hal_alloc_page(bool rw, bool user) - { - return 0; - } - } // namespace HAL -} // namespace Kernel |
