diff options
Diffstat (limited to 'dev/kernel/HALKit')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalKernelMain.cc | 7 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 52 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Paging.h | 1 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Processor.h | 12 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/HALKit/ARM64/Processor.h | 5 |
7 files changed, 43 insertions, 40 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index cc3c8e93..7ce1b0d8 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -29,9 +29,10 @@ STATIC Kernel::Void hal_init_scheduler_team() STATIC Kernel::UInt64 hal_rdtsc_fn() { - Kernel::UInt32 lo, hi; - __asm__ volatile("rdtsc" - : "=a"(lo), "=d"(hi)); + Kernel::UInt32 lo = 0, hi = 0; + + asm volatile("rdtsc" + : "=a"(lo), "=d"(hi)); return ((Kernel::UInt64)hi << 32) | lo; } diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc index 8bd98923..4b50a3f4 100644 --- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc @@ -14,6 +14,7 @@ namespace Kernel::HAL { namespace Detail { + /// @brief Page Table Entry for AMD64. struct PTE { UInt64 Present : 1; @@ -28,7 +29,7 @@ namespace Kernel::HAL UInt64 Ignored1 : 3; // Available to software UInt64 PhysicalAddress : 40; // Physical page frame address (bits 12–51) UInt64 Ignored2 : 7; // More software bits / reserved - UInt64 Protection_key : 4; // Optional (if PKU enabled) + UInt64 ProtectionKey : 4; // Optional (if PKU enabled) UInt64 Reserved : 1; // Usually reserved UInt64 Nx : 1; // No Execute }; @@ -45,6 +46,9 @@ namespace Kernel::HAL (void)(kout << (pte->Nx ? "NX" : "Not NX") << kendl); (void)(kout << (pte->User ? "User" : "Not User") << kendl); (void)(kout << (pte->Pcd ? "Not Cached" : "Cached") << kendl); + (void)(kout << (pte->Accessed ? "Accessed" : "Not Accessed") << kendl); + (void)(kout << hex_number(pte->PhysicalAddress) << kendl); + (void)(kout << (pte->ProtectionKey ? "Protected" : "Not Protected/PKU Disabled") << kendl); } /***********************************************************************************/ @@ -54,31 +58,29 @@ namespace Kernel::HAL /***********************************************************************************/ UIntPtr hal_get_phys_address(VoidPtr virt) { - const UInt64 vaddr = (UInt64)virt; + const UInt64 kVMAddr = (UInt64)virt; const UInt64 kMask9Bits = 0x1FFULL; const UInt64 kPageOffsetMask = 0xFFFULL; UInt64 cr3 = (UInt64)hal_read_cr3() & ~kPageOffsetMask; - hal_invl_tlb(virt); - // Level 4 auto pml4 = reinterpret_cast<UInt64*>(cr3); - UInt64 pml4e = pml4[(vaddr >> 39) & kMask9Bits]; + UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9Bits]; if (!(pml4e & 1)) return 0; // Level 3 auto pdpt = reinterpret_cast<UInt64*>(pml4e & ~kPageOffsetMask); - UInt64 pdpte = pdpt[(vaddr >> 30) & kMask9Bits]; + UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9Bits]; if (!(pdpte & 1)) return 0; // Level 2 auto pd = reinterpret_cast<UInt64*>(pdpte & ~kPageOffsetMask); - UInt64 pde = pd[(vaddr >> 21) & kMask9Bits]; + UInt64 pde = pd[(kVMAddr >> 21) & kMask9Bits]; if (!(pde & 1)) return 0; @@ -86,12 +88,12 @@ namespace Kernel::HAL // 1 GiB page support if (pde & (1 << 7)) { - return (pde & ~((1ULL << 30) - 1)) | (vaddr & ((1ULL << 30) - 1)); + return (pde & ~((1ULL << 30) - 1)) | (kVMAddr & ((1ULL << 30) - 1)); } // Level 1 - auto pt = reinterpret_cast<UInt64*>(pde & ~kPageOffsetMask); - Detail::PTE* pte = (Detail::PTE*)pt[(vaddr >> 12) & kMask9Bits]; + auto pt = reinterpret_cast<UInt64*>(pde & ~kPageOffsetMask); + Detail::PTE* pte = (Detail::PTE*)pt[(kVMAddr >> 12) & kMask9Bits]; if (!pte->Present) return 0; @@ -110,46 +112,44 @@ namespace Kernel::HAL /***********************************************************************************/ EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { - const UInt64 vaddr = (UInt64)virtual_address; + const UInt64 kVMAddr = (UInt64)virtual_address; constexpr UInt64 kMask9 = 0x1FF; constexpr UInt64 kPageMask = 0xFFF; UInt64 cr3 = (UIntPtr)hal_read_cr3() & ~kPageMask; auto pml4 = reinterpret_cast<UInt64*>(cr3); - UInt64 pml4e = pml4[(vaddr >> 39) & kMask9]; + UInt64 pml4e = pml4[(kVMAddr >> 39) & kMask9]; if (!(pml4e & 1)) return kErrorInvalidData; - auto pdpt = reinterpret_cast<UInt64*>(pml4e & ~kPageMask); - UInt64 pdpte = pdpt[(vaddr >> 30) & kMask9]; + UInt64* pdpt = reinterpret_cast<UInt64*>(pml4e & ~kPageMask); + UInt64 pdpte = pdpt[(kVMAddr >> 30) & kMask9]; if (!(pdpte & 1)) return kErrorInvalidData; - auto pd = reinterpret_cast<UInt64*>(pdpte & ~kPageMask); - UInt64 pde = pd[(vaddr >> 21) & kMask9]; + UInt64* pd = reinterpret_cast<UInt64*>(pdpte & ~kPageMask); + UInt64 pde = pd[(kVMAddr >> 21) & kMask9]; if (!(pde & 1)) return kErrorInvalidData; UInt64* pt = reinterpret_cast<UInt64*>(pde & ~kPageMask); - Detail::PTE* pte = (Detail::PTE*)pt[(vaddr >> 12) & kMask9]; + Detail::PTE* pte = (Detail::PTE*)pt[(kVMAddr >> 12) & kMask9]; - pte->Present = !!(flags & kMMFlagsPresent); - pte->Wr = !!(flags & kMMFlagsWr); - pte->User = !!(flags & kMMFlagsUser); - pte->Nx = !!(flags & kMMFlagsNX); - pte->Pcd = !(flags & kMMFlagsUncached); + pte->Present = !!(flags & kMMFlagsPresent); + pte->Wr = !!(flags & kMMFlagsWr); + pte->User = !!(flags & kMMFlagsUser); + pte->Nx = !!(flags & kMMFlagsNX); + pte->Pcd = !(flags & kMMFlagsUncached); + pte->PhysicalAddress = (UIntPtr)(physical_address); - if (physical_address) - pte->PhysicalAddress = (UIntPtr)physical_address; + mmi_page_status(pte); hal_invl_tlb(virtual_address); - mmi_page_status(pte); - return kErrorSuccess; } } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc index ba5710e3..edad0e97 100644 --- a/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalSchedulerCorePrimitivesAMD64.cc @@ -46,7 +46,7 @@ namespace Kernel Void mp_hang_thread(HAL::StackFrame* stack) { NE_UNUSED(stack); - + while (Yes) { /* Nothing to do, code is spinning */ diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index da90a71a..ea20dece 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -64,7 +64,6 @@ namespace Kernel::HAL } } // namespace Detail - auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr; auto mm_free_bitmap(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index 084bc962..e375a935 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -68,13 +68,13 @@ namespace Kernel::HAL /// @brief Memory Manager mapping flags. enum { - kMMFlagsInvalid = 1 << 0, - kMMFlagsPresent = 1 << 1, - kMMFlagsWr = 1 << 2, - kMMFlagsUser = 1 << 3, - kMMFlagsNX = 1 << 4, + kMMFlagsInvalid = 1 << 0, + kMMFlagsPresent = 1 << 1, + kMMFlagsWr = 1 << 2, + kMMFlagsUser = 1 << 3, + kMMFlagsNX = 1 << 4, kMMFlagsUncached = 1 << 5, - kMMFlagsCount = 4, + kMMFlagsCount = 4, }; struct PACKED Register64 final diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 728b20ed..42451d70 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -152,9 +152,9 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz /// check for command header. MUST_PASS(command_header); - command_header->Struc.Cfl = sizeof(FisRegH2D) / sizeof(UInt32); + command_header->Struc.Cfl = sizeof(FisRegH2D) / sizeof(UInt32); command_header->Struc.Write = Write; - command_header->Prdtl = 1; + command_header->Prdtl = 1; auto ctba_phys = ((UInt64)command_header->Ctbau << 32) | command_header->Ctba; auto command_table = reinterpret_cast<volatile HbaCmdTbl*>(ctba_phys); diff --git a/dev/kernel/HALKit/ARM64/Processor.h b/dev/kernel/HALKit/ARM64/Processor.h index f0f09578..b108fc82 100644 --- a/dev/kernel/HALKit/ARM64/Processor.h +++ b/dev/kernel/HALKit/ARM64/Processor.h @@ -28,7 +28,8 @@ namespace Kernel::HAL kMMFlagsWr = 1 << 1, kMMFlagsUser = 1 << 2, kMMFlagsNX = 1 << 3, - kMMFlagsCount = 3, + kMMFlagsUncached = 1 << 4, + kMMFlagsCount = 4, }; /// @brief Set a PTE from pd_base. @@ -38,6 +39,8 @@ namespace Kernel::HAL /// @return Status code of page manip. EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags); + EXTERN_C UIntPtr hal_get_phys_address(VoidPtr virtual_address); + typedef UIntPtr Reg; typedef Register64 Register; |
