diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2025-01-25 21:48:56 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2025-01-25 21:48:56 +0100 |
| commit | 6f98067bc9fb75794c864c5b35a7ee1bf0704c73 (patch) | |
| tree | 6a83d009d9a52e36f2afb9944432c0244c3d0184 /dev/Kernel/HALKit/AMD64/Processor.h | |
| parent | ede6c1e0fd670d5af1c62ab52847fc518cfd4e9c (diff) | |
ADD: Better SATA driver, but not fully fixed yet.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit/AMD64/Processor.h')
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/Processor.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/dev/Kernel/HALKit/AMD64/Processor.h b/dev/Kernel/HALKit/AMD64/Processor.h index 0e6dcfff..acdf7e42 100644 --- a/dev/Kernel/HALKit/AMD64/Processor.h +++ b/dev/Kernel/HALKit/AMD64/Processor.h @@ -206,6 +206,27 @@ namespace Kernel::HAL return edx & (1 << 5); } + inline UInt64 hal_get_phys_address(void* virtual_address) + { + UInt64 addr = (UInt64)virtual_address; + UInt64 cr3 = (UInt64)hal_read_cr3(); + + // Extract indices for PML4, PDPT, PD, and PT + UInt64 pml4_idx = (addr >> 39) & 0x1FF; + UInt64 pdpt_idx = (addr >> 30) & 0x1FF; + UInt64 pd_idx = (addr >> 21) & 0x1FF; + UInt64 pt_idx = (addr >> 12) & 0x1FF; + + // Get PML4 Table + UInt64* pml4 = (UInt64*)(cr3 & ~0xFFF); + UInt64* pdpt = (UInt64*)(pml4[pml4_idx] & ~0xFFF); + UInt64* pd = (UInt64*)(pdpt[pdpt_idx] & ~0xFFF); + UInt64* pt = (UInt64*)(pd[pd_idx] & ~0xFFF); + + // Get Physical Address + return (pt[pt_idx] & ~0xFFF) + (addr & 0xFFF); + } + /***********************************************************************************/ /// @brief Get Model specific register inside core. /// @param msr MSR |
