diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
| commit | df8a42aa1266d953a9ee473afe9f6349bd1837c7 (patch) | |
| tree | cad53c222ca90ee98ac82ee2d630a4ff0b0c3ee3 /dev/ZKA/HALKit | |
| parent | 884ea5c2d43b6c8d4c2bb4fc33c11dc2313eeca2 (diff) | |
[dev/FeatureAdd] Add mm_new_class, as C++ new doesn't initialize class directly.
[dev/FeatureFix] CR2 set to invalid address due to stack corruption, fixing that.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA/HALKit')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalProcessor.cxx | 32 |
3 files changed, 23 insertions, 17 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index df5317e5..e6d5d292 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -122,7 +122,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept kcout << "Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemMgr(); + auto fs = Kernel::mm_new_class<Kernel::NewFilesystemMgr>(); MUST_PASS(fs); diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index b0d444d9..3cd7ab0f 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -31,9 +31,9 @@ #endif // !kAlign EXTERN_C void hal_flush_tlb(); -EXTERN_C void hal_invl_tlb(Kernel::UIntPtr addr); -EXTERN_C void hal_write_cr3(Kernel::UIntPtr pml4); -EXTERN_C void hal_write_cr0(Kernel::UIntPtr bit); +EXTERN_C void hal_invl_tlb(Kernel::VoidPtr addr); +EXTERN_C void hal_write_cr3(Kernel::VoidPtr cr3); +EXTERN_C void hal_write_cr0(Kernel::VoidPtr bit); EXTERN_C Kernel::VoidPtr hal_read_cr0(); // @brief CPU control register. EXTERN_C Kernel::VoidPtr hal_read_cr2(); // @brief Fault address. diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index fa634406..b31f58e2 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -25,33 +25,39 @@ namespace Kernel::HAL { VoidPtr pml4_base = hal_read_cr3(); - UIntPtr pd_idx = ((UIntPtr)virt_addr >> 22); - UIntPtr pte_idx = ((UIntPtr)virt_addr >> 12) & 0x3FFF; - // Now PD - volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pml4_base) + pd_idx * sizeof(UIntPtr)); + UIntPtr pd_idx = ((UIntPtr)virt_addr >> 22); + UIntPtr pte_idx = ((UIntPtr)virt_addr >> 12) & 0x03FF; - kcout << (*pd_entry & 0x01 ? "Dir Present." : "Dir Not present.") << endl; + // Now get pd_entry + volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pml4_base) + (pd_idx * kPTEAlign)); // Don't bother allocate directory. if (!(*pd_entry & 0x01)) { - ke_stop(RUNTIME_CHECK_PAGE); + ke_stop(RUNTIME_CHECK_PAGE); } - UInt64 pt_base = *pd_entry & ~0xFFF; // Remove flags + UInt64 pt_base = pd_entry[pd_idx] & ~0xFFF; // Remove flags // And then PTE - volatile UIntPtr* page_addr = (volatile UIntPtr*)(((UInt64)pt_base) + (pte_idx * sizeof(UIntPtr))); + volatile UIntPtr* pt_entry = (volatile UIntPtr*)(pt_base + (pte_idx * kPTEAlign)); - kcout << (*page_addr & 0x01 ? "Page Present." : "Page Not Present.") << endl; - kcout << (*page_addr & 0x04 ? "User." : "Not User.") << endl; + kcout << (pt_entry[pte_idx] & 0x01 ? "Page Present." : "Page Not Present.") << endl; + kcout << (pt_entry[pte_idx] & 0x02 ? "Page RW." : "Page Not RW.") << endl; + kcout << (pt_entry[pte_idx] & 0x04 ? "Page User." : "Page Not User.") << endl; - if (phys_addr == nullptr) + switch ((UIntPtr)phys_addr) { - phys_addr = (VoidPtr)((*page_addr & ~0xFFF) + ((UIntPtr)virt_addr & 0xFFF)); + case kBadAddress: { + phys_addr = (VoidPtr)((pt_entry[pte_idx] & ~0xFFF) + ((UIntPtr)virt_addr & 0xFFF)); + break; + } + default: { + break; + } } - (*page_addr) = ((UIntPtr)phys_addr) | (flags & 0xFFF) | 0x01; + pt_entry[pte_idx] = ((UIntPtr)phys_addr) | (flags & 0xFFF) | 0x01; return 0; } |
