summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/AMD64
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-30 12:34:54 +0200
committerAmlal <amlal@nekernel.org>2025-04-30 12:34:54 +0200
commitfcea594f2df75dcd0f3d4bfeac988b748be89c13 (patch)
tree0204f5575637644879c89a1a3c00b5848043e89b /dev/kernel/HALKit/AMD64
parent911bf2d68a4904d8ff838d31e00ef65d4e03063c (diff)
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 <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/AMD64')
-rw-r--r--dev/kernel/HALKit/AMD64/HalKernelMain.cc7
-rw-r--r--dev/kernel/HALKit/AMD64/Paging.h2
-rw-r--r--dev/kernel/HALKit/AMD64/Processor.h2
3 files changed, 9 insertions, 2 deletions
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