From fcea594f2df75dcd0f3d4bfeac988b748be89c13 Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 30 Apr 2025 12:34:54 +0200 Subject: kernel: keep track of cr3 in AMD HAL/HEL. why? To keep track of it, avoid security issues in the future. Signed-off-by: Amlal --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 7 ++++++- dev/kernel/HALKit/AMD64/Paging.h | 2 +- dev/kernel/HALKit/AMD64/Processor.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'dev/kernel/HALKit') diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index fba02bc1..29244add 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -27,7 +27,8 @@ STATIC Kernel::Void hal_pre_init_scheduler() noexcept { } } -/// @brief Kernel init procedure. +/// @brief Kernel init function. +/// @param handover_hdr Handover boot header. EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { if (handover_hdr->f_Magic != kHandoverMagic && handover_hdr->f_Version != kHandoverVersion) { return kEfiFail; @@ -42,6 +43,10 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, handover_hdr->f_HardwareTables.f_ImageHandle); + kKernelCR3 = kHandoverHeader->f_PageStart; + + hal_write_cr3(kKernelCR3); + /************************************** */ /* INITIALIZE BIT MAP. */ /************************************** */ diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index 074c1113..3c7107bc 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -37,7 +37,7 @@ 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. -EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page table. +EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page directory inside cr3 register. namespace Kernel::HAL { namespace Detail { diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index b57e9abf..d7d594d9 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -286,3 +286,5 @@ EXTERN_C ATTRIBUTE(naked) Kernel::Void hal_load_gdt(Kernel::HAL::Register64 ptr) inline Kernel::VoidPtr kKernelBitMpStart = nullptr; inline Kernel::UIntPtr kKernelBitMpSize = 0UL; + +inline Kernel::VoidPtr kKernelCR3 = nullptr; \ No newline at end of file -- cgit v1.2.3