summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit
diff options
context:
space:
mode:
authoramlal <amlal@el-mahrouss-logic.com>2024-03-16 14:22:21 +0100
committeramlal <amlal@el-mahrouss-logic.com>2024-03-16 14:22:21 +0100
commit55059428bfd6a18451bc1ed3ee64e7bb04c395cd (patch)
tree02dd524a2249111e30d2208fd700fa72e31182db /Private/HALKit
parent8f9b5e08f53f6e49a1f4c6b20e17c54298da9c44 (diff)
HCR-14: See below.
- Pretty big modifications, add kernel mouse. Signed-off-by: amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/HALKit')
-rw-r--r--Private/HALKit/AMD64/HalControlRegister.s4
-rw-r--r--Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp14
-rw-r--r--Private/HALKit/AMD64/HalDescriptorLoader.cpp91
-rw-r--r--Private/HALKit/AMD64/HalInterruptRouting.asm148
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx37
-rw-r--r--Private/HALKit/AMD64/HalKernelMouse.cxx122
-rw-r--r--Private/HALKit/AMD64/HalNewBoot.asm3
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.hpp12
-rw-r--r--Private/HALKit/AMD64/HalRoutines.s4
-rw-r--r--Private/HALKit/AMD64/Processor.hpp8
10 files changed, 361 insertions, 82 deletions
diff --git a/Private/HALKit/AMD64/HalControlRegister.s b/Private/HALKit/AMD64/HalControlRegister.s
index 2b898211..0504d2fb 100644
--- a/Private/HALKit/AMD64/HalControlRegister.s
+++ b/Private/HALKit/AMD64/HalControlRegister.s
@@ -14,9 +14,7 @@
.section .text
flush_tlb:
- mov %rsi, %cr3
- mov %cr3, %rsi
- xor %rax, %rax
+ invlpg (%rcx)
ret
read_cr3:
diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp
index a86499e1..e95e8902 100644
--- a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp
+++ b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp
@@ -11,10 +11,10 @@
EXTERN_C void idt_handle_gpf(HCore::UIntPtr rsp) {
MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent());
- HCore::kcout << HCore::StringBuilder::FromInt("rsp{%}", rsp);
+ HCore::kcout << "HCoreKrnl.exe: Stack Pointer: " << HCore::StringBuilder::FromInt("rsp{%}", rsp);
HCore::kcout
- << "HCoreKrnl: General Protection Fault, caused by "
+ << "HCoreKrnl.exe: General Protection Fault, caused by "
<< HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();
HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
@@ -24,13 +24,13 @@ EXTERN_C void idt_handle_scheduler(HCore::UIntPtr rsp) {
HCore::kcout << HCore::StringBuilder::FromInt("rsp{%}", rsp);
HCore::kcout
- << "HCoreKrnl: Will be scheduled back later "
+ << "HCoreKrnl.exe: Will be scheduled back later "
<< HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName()
<< HCore::end_line();
/// schedule another process.
if (!HCore::ProcessHelper::StartScheduling()) {
- HCore::kcout << "HCoreKrnl: Continue schedule this process...\r\n";
+ HCore::kcout << "HCoreKrnl.exe: Continue schedule this process...\r\n";
}
}
@@ -40,7 +40,7 @@ EXTERN_C void idt_handle_pf(HCore::UIntPtr rsp) {
MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent());
HCore::kcout
- << "HCoreKrnl: Segmentation Fault, caused by "
+ << "HCoreKrnl.exe: Segmentation Fault, caused by "
<< HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();
HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
@@ -52,7 +52,7 @@ EXTERN_C void idt_handle_math(HCore::UIntPtr rsp) {
MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent());
HCore::kcout
- << "HCoreKrnl: Math error, caused by "
+ << "HCoreKrnl.exe: Math error, caused by "
<< HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();
HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
@@ -64,7 +64,7 @@ EXTERN_C void idt_handle_generic(HCore::UIntPtr rsp) {
MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent());
HCore::kcout
- << "HCoreKrnl: Execution error, caused by "
+ << "HCoreKrnl.exe: Execution error, caused by "
<< HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();
HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
diff --git a/Private/HALKit/AMD64/HalDescriptorLoader.cpp b/Private/HALKit/AMD64/HalDescriptorLoader.cpp
index 1dbe8e9e..595d52e4 100644
--- a/Private/HALKit/AMD64/HalDescriptorLoader.cpp
+++ b/Private/HALKit/AMD64/HalDescriptorLoader.cpp
@@ -7,63 +7,35 @@
#include <ArchKit/ArchKit.hpp>
namespace HCore::HAL {
+namespace Detail {
STATIC RegisterGDT kRegGdt;
-
-void GDTLoader::Load(RegisterGDT &gdt) {
- MUST_PASS(gdt.Base != 0);
-
- kRegGdt.Base = gdt.Base;
- kRegGdt.Limit = gdt.Limit;
-
- rt_load_gdt(kRegGdt);
-}
-
STATIC HAL::Register64 kRegIdt;
STATIC ::HCore::Detail::AMD64::InterruptDescriptorAMD64
kInterruptVectorTable[kKernelIdtSize];
-void IDTLoader::Load(Register64 &idt) {
- volatile ::HCore::UIntPtr **baseIdt = (volatile ::HCore::UIntPtr **)idt.Base;
-
- MUST_PASS(baseIdt);
-
- for (UInt16 i = 0; i < kKernelIdtSize; i++) {
- MUST_PASS(baseIdt[i]);
-
- kInterruptVectorTable[i].Selector = kGdtCodeSelector;
- kInterruptVectorTable[i].Ist = 0x0;
- kInterruptVectorTable[i].TypeAttributes = kInterruptGate;
- kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & 0xFFFF);
- kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & 0xFFFF);
- kInterruptVectorTable[i].OffsetHigh =
- (((UIntPtr)baseIdt[i] >> 32) & 0xFFFFFFFF);
- kInterruptVectorTable[i].Zero = 0x0;
- }
-
- kRegIdt.Base = reinterpret_cast<UIntPtr>(kInterruptVectorTable);
- kRegIdt.Limit = sizeof(::HCore::Detail::AMD64::InterruptDescriptorAMD64) *
- (kKernelIdtSize - 1);
-
- rt_load_idt(kRegIdt);
-
+STATIC Void RemapPIC(Void) noexcept {
UInt8 a1, a2;
a1 = HAL::In8(0x21); // save masks
a2 = HAL::In8(0xA1);
// Remap PIC.
- HAL::Out8(0x20, 0x11);
+ HAL::Out8(0x20, 0x10 | 0x01);
HAL::rt_wait_400ns();
- HAL::Out8(0xA0, 0x11);
+ HAL::Out8(0xA0, 0x10 | 0x01);
HAL::rt_wait_400ns();
- HAL::Out8(0x21, 0x20);
+
+ HAL::Out8(0x21, 0x28);
HAL::rt_wait_400ns();
- HAL::Out8(0xA1, 0x28);
+ HAL::Out8(0xA1, 0x30);
+
HAL::rt_wait_400ns();
+
HAL::Out8(0x21, 0x04);
HAL::rt_wait_400ns();
HAL::Out8(0xA1, 0x02);
+
HAL::rt_wait_400ns();
HAL::Out8(0x21, 0x01);
HAL::rt_wait_400ns();
@@ -72,6 +44,49 @@ void IDTLoader::Load(Register64 &idt) {
HAL::Out8(0x21, a1);
HAL::rt_wait_400ns();
HAL::Out8(0xA1, a2);
+
+ HAL::Out8(0x21, 0xfd);
+ HAL::Out8(0xa1, 0xff);
+}
+} // namespace Detail
+
+/// @brief Loads the provided Global Descriptor Table.
+/// @param gdt
+/// @return
+Void GDTLoader::Load(RegisterGDT &gdt) {
+ MUST_PASS(gdt.Base != 0);
+
+ Detail::kRegGdt.Base = gdt.Base;
+ Detail::kRegGdt.Limit = gdt.Limit;
+
+ hal_load_gdt(Detail::kRegGdt);
+}
+
+Void IDTLoader::Load(Register64 &idt) {
+ volatile ::HCore::UIntPtr **baseIdt = (volatile ::HCore::UIntPtr **)idt.Base;
+
+ MUST_PASS(baseIdt);
+
+ for (UInt16 i = 0; i < kKernelIdtSize; i++) {
+ MUST_PASS(baseIdt[i]);
+
+ Detail::kInterruptVectorTable[i].Selector = kGdtCodeSelector;
+ Detail::kInterruptVectorTable[i].Ist = 0x0;
+ Detail::kInterruptVectorTable[i].TypeAttributes = kInterruptGate;
+ Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & 0xFFFF);
+ Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & 0xFFFF);
+ Detail::kInterruptVectorTable[i].OffsetHigh =
+ (((UIntPtr)baseIdt[i] >> 32) & 0xFFFFFFFF);
+ Detail::kInterruptVectorTable[i].Zero = 0x0;
+ }
+
+ Detail::kRegIdt.Base = reinterpret_cast<UIntPtr>(Detail::kInterruptVectorTable);
+ Detail::kRegIdt.Limit = sizeof(::HCore::Detail::AMD64::InterruptDescriptorAMD64) *
+ (kKernelIdtSize - 1);
+
+ hal_load_idt(Detail::kRegIdt);
+
+ Detail::RemapPIC();
}
void GDTLoader::Load(Ref<RegisterGDT> &gdt) { GDTLoader::Load(gdt.Leak()); }
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm
index 99bba00a..6bbc12fd 100644
--- a/Private/HALKit/AMD64/HalInterruptRouting.asm
+++ b/Private/HALKit/AMD64/HalInterruptRouting.asm
@@ -11,7 +11,7 @@
[bits 64]
-%define kInterruptId 0x21
+%define kInterruptId 0x21
%macro IntExp 1
global __HCR_INT_%1
@@ -36,13 +36,18 @@ global _ke_power_on_self_test
global ke_handle_irq
global kInterruptVectorTable
+extern _hal_mouse_handler
+extern idt_handle_gpf
+extern idt_handle_pf
extern ke_io_print
section .text
IntNormal 0
IntNormal 1
+
IntNormal 2
+
IntNormal 3
IntNormal 4
IntNormal 5
@@ -52,9 +57,35 @@ IntExp 8
IntNormal 9
IntExp 10
IntExp 11
-IntExp 12
+
+__HCR_INT_12:
+ cli
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_gpf
+
+ pop rax
+
+ sti
+ iretq
+
IntExp 13
-IntExp 14
+
+__HCR_INT_14:
+ cli
+
+ push rax
+
+ mov rcx, rsp
+ call idt_handle_pf
+
+ pop rax
+
+ sti
+ iretq
+
IntNormal 15
IntNormal 16
IntExp 17
@@ -97,8 +128,101 @@ __HCR_INT_33:
sti
iretq
-%assign i 34
-%rep 222
+__HCR_INT_34:
+ cld
+
+ iretq
+
+
+__HCR_INT_35:
+ cld
+
+ iretq
+
+__HCR_INT_36:
+ cld
+
+ iretq
+
+__HCR_INT_37:
+ cld
+
+ iretq
+
+__HCR_INT_38:
+ cld
+
+ iretq
+
+__HCR_INT_39:
+ cld
+
+ iretq
+
+__HCR_INT_40:
+ cld
+
+ iretq
+
+__HCR_INT_41:
+ cld
+
+ iretq
+
+__HCR_INT_42:
+ cld
+
+ iretq
+
+__HCR_INT_43:
+ cld
+
+ iretq
+
+__HCR_INT_44:
+ cli
+
+ push rax
+
+ call _hal_mouse_handler
+
+ pop rax
+
+ push rax
+
+ ;; Find and execute system call TODO
+
+ mov rcx, kMouseLabelExit
+ call ke_io_print
+
+ pop rax
+
+ sti
+ iretq
+
+__HCR_INT_45:
+ cld
+
+ iretq
+
+IntNormal 46
+IntNormal 47
+IntNormal 48
+IntNormal 49
+IntNormal 50
+IntNormal 51
+IntNormal 52
+IntNormal 53
+IntNormal 54
+IntNormal 55
+IntNormal 56
+IntNormal 57
+IntNormal 58
+IntNormal 59
+IntNormal 60
+
+%assign i 61
+%rep 195
IntNormal i
%assign i i+1
%endrep
@@ -114,9 +238,9 @@ _ke_power_on_self_test:
ret
-[global rt_load_gdt]
+[global hal_load_gdt]
-rt_load_gdt:
+hal_load_gdt:
lgdt [rcx]
push 0x08
lea rax, [rel rt_reload_segments]
@@ -131,9 +255,9 @@ rt_reload_segments:
mov ss, ax
ret
-global rt_load_idt
+global hal_load_idt
-rt_load_idt:
+hal_load_idt:
lidt [rcx]
sti
ret
@@ -148,6 +272,8 @@ kInterruptVectorTable:
%endrep
kSystemCallLabelEnter:
- db "HCoreKrnl.exe: SystemCall: Enter", 0xa, 0xd, 0
+ db "HCoreKrnl.exe: SystemCall: Enter.", 0xa, 0xd, 0
kSystemCallLabelExit:
- db "HCoreKrnl.exe: SystemCall: Exit", 0xa, 0xd, 0 \ No newline at end of file
+ db "HCoreKrnl.exe: SystemCall: Exit.", 0xa, 0xd, 0
+kMouseLabelExit:
+ db "HCoreKrnl.exe: KernelMouse: Acknowledge Interrupt.", 0xa, 0xd, 0 \ No newline at end of file
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 1f4256a9..248ae8cb 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -5,22 +5,35 @@
------------------------------------------- */
#include <ArchKit/ArchKit.hpp>
-#include <Drivers/PS2/Mouse.hxx>
#include <FirmwareKit/Handover.hxx>
#include <KernelKit/FileManager.hpp>
#include <KernelKit/Framebuffer.hpp>
#include <KernelKit/PEFCodeManager.hxx>
+#include <KernelKit/ProcessScheduler.hpp>
+#include <KernelKit/Rsrc/Splash.rsrc>
#include <KernelKit/Rsrc/Util.hxx>
#include <NewKit/Json.hpp>
#include <NewKit/KernelHeap.hpp>
#include <NewKit/UserHeap.hpp>
-#include <KernelKit/ProcessScheduler.hpp>
-#include <KernelKit/Rsrc/Splash.rsrc>
///! @brief Disk contains HCore files.
#define kInstalledMedia 0xDD
EXTERN_C HCore::VoidPtr kInterruptVectorTable[];
+EXTERN_C HCore::Void _ke_init_mouse();
+EXTERN_C HCore::Void _hal_mouse_draw();
+
+namespace Detail {
+STATIC HCore::Void ke_page_protect_nullptr(HCore::Void) {
+ HCore::HAL::PageDirectory64* pageDirNull = nullptr;
+
+ for (HCore::SizeT indexPte = 0; indexPte < kPTEMax; ++indexPte) {
+ pageDirNull->Pte[indexPte].Rw = false;
+ }
+
+ flush_tlb(reinterpret_cast<HCore::UIntPtr>(pageDirNull));
+}
+} // namespace Detail
EXTERN_C void RuntimeMain(
HCore::HEL::HandoverInformationHeader* HandoverHeader) {
@@ -61,29 +74,31 @@ EXTERN_C void RuntimeMain(
HCore::HAL::IDTLoader idt;
idt.Load(idtBase);
+ Detail::ke_page_protect_nullptr();
+
KeInitRsrc();
- KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH,
- ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2),
- ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2));
+ KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH,
+ ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2),
+ ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2));
KeClearRsrc();
/// START POST
HCore::HAL::Detail::_ke_power_on_self_test();
-
+
/// END POST
-
+
/// Mounts a NewFS block.
- HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
+ HCore::FilesystemManagerInterface::Mount(new HCore::NewFilesystemManager());
/// We already have an install of HCore.
if (HandoverHeader->f_Bootloader == kInstalledMedia) {
- HCore::kcout << "HCoreKrnl: Running kernel...\r\n";
+ HCore::kcout << "HCoreKrnl.exe: Running kernel...\r\n";
/// TODO: Parse system configuration.
} else {
- HCore::kcout << "HCoreKrnl: Running setup...\r\n";
+ HCore::kcout << "HCoreKrnl.exe: Running setup...\r\n";
}
HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
diff --git a/Private/HALKit/AMD64/HalKernelMouse.cxx b/Private/HALKit/AMD64/HalKernelMouse.cxx
new file mode 100644
index 00000000..58c45dfe
--- /dev/null
+++ b/Private/HALKit/AMD64/HalKernelMouse.cxx
@@ -0,0 +1,122 @@
+#include <KernelKit/Rsrc/Util.hxx>
+#include <KernelKit/Rsrc/Cursor.rsrc>
+#include <Drivers/PS2/PS2KernelMouse.hxx>
+#include <NewKit/Defines.hpp>
+#include <KernelKit/Framebuffer.hpp>
+
+STATIC HCore::Int32 kPrevX = 0;
+STATIC HCore::Int32 kPrevY = 0;
+STATIC HCore::Int32 kX = 0;
+STATIC HCore::Int32 kY = 0;
+STATIC HCore::Int32 kMouseCycle = 0;
+STATIC HCore::PS2KernelMouse kMousePS2;
+STATIC HCore::Int32 kMousePacket[4];
+STATIC HCore::Boolean kMousePacketReady = false;
+
+#define kPS2LeftButton 0b00000001
+#define kPS2MiddleButton 0b00000010
+#define kPS2RightButton 0b00000100
+
+#define kPS2XSign 0b00010000
+#define kPS2YSign 0b00100000
+#define kPS2XOverflow 0b01000000
+#define kPS2YOverflow 0b10000000
+
+EXTERN_C void _hal_mouse_handler()
+{
+#ifdef __DEBUG__
+ HCore::UInt8 data = HCore::HAL::In8(0x60);
+
+ switch (kMouseCycle)
+ {
+ case 0:
+ {
+ if (kMousePacketReady) break;
+ if ((data & 0b00001000) == 0) break;
+
+ kMousePacket[0] = data;
+ ++kMouseCycle;
+
+ break;
+ }
+ case 1:
+ {
+ if (kMousePacketReady) break;
+
+ kMousePacket[1] = data;
+ ++kMouseCycle;
+
+ break;
+ }
+ case 2:
+ {
+ if (kMousePacketReady) break;
+
+ kMousePacket[2] = data;
+ ++kMouseCycle;
+ kMousePacketReady = true;
+ kMouseCycle = 0;
+
+ break;
+ }
+ default:
+ break;
+ }
+#endif
+}
+
+EXTERN_C void _hal_mouse_draw()
+{
+#ifdef __DEBUG__
+ if (!kMousePacketReady) return;
+
+ bool xNeg, yNeg, xOvf, yOvf;
+
+ xNeg = (kMousePacket[0] & kPS2XSign);
+ yNeg = (kMousePacket[0] & kPS2YSign);
+
+ xOvf = (kMousePacket[0] & kPS2XOverflow);
+ yOvf = (kMousePacket[0] & kPS2YOverflow);
+
+ kX += xNeg ? (256 - kMousePacket[1]) : (256 - (-kMousePacket[1]));
+ kY += yNeg ? (256 - kMousePacket[2]) : (256 - (-kMousePacket[2]));;
+
+ if (xOvf) {
+ kX += xNeg ? 255 : -255;
+ }
+
+ if (yOvf) {
+ kY += yNeg ? 255 : -255;
+ }
+
+ if (kY > kHandoverHeader->f_GOP.f_Height)
+ {
+ return;
+ }
+
+ if (kX > kHandoverHeader->f_GOP.f_Width)
+ {
+ return;
+ }
+
+ KeClearZone(POINTER_HEIGHT, POINTER_WIDTH, kPrevX, kPrevY);
+
+ KeInitRsrc();
+ KeDrawRsrc(Pointer, POINTER_HEIGHT, POINTER_WIDTH, kX, kY);
+ KeClearRsrc();
+
+ kPrevX = kMousePacket[1];
+ kPrevY = kMousePacket[2];
+
+ kMousePacketReady = false;
+#endif
+}
+
+/// @brief Inital kernel mouse initializer
+/// @param
+EXTERN_C void _ke_init_mouse(void)
+{
+#ifdef __DEBUG__
+ kMousePS2.Init();
+#endif
+} \ No newline at end of file
diff --git a/Private/HALKit/AMD64/HalNewBoot.asm b/Private/HALKit/AMD64/HalNewBoot.asm
index 881c1728..3a16cd24 100644
--- a/Private/HALKit/AMD64/HalNewBoot.asm
+++ b/Private/HALKit/AMD64/HalNewBoot.asm
@@ -31,9 +31,12 @@ extern RuntimeMain
;; Just a simple setup, we'd also need to tell some before
Main:
+ push rax
push rcx
call RuntimeMain
pop rcx
+ pop rax
+;; Go to sleep.
MainLoop:
cli
hlt
diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp
index f6b57a6d..bea28808 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.hpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.hpp
@@ -26,13 +26,13 @@
#define kPTESize (0x1000)
#endif // !kPTESize
-extern "C" void flush_tlb(HCore::UIntPtr VirtualAddr);
-extern "C" void write_cr3(HCore::UIntPtr pde);
-extern "C" void write_cr0(HCore::UIntPtr bit);
+EXTERN_C void flush_tlb(HCore::UIntPtr pde);
+EXTERN_C void write_cr3(HCore::UIntPtr pde);
+EXTERN_C void write_cr0(HCore::UIntPtr bit);
-extern "C" HCore::UIntPtr read_cr0(); // @brief CPU control register.
-extern "C" HCore::UIntPtr read_cr2(); // @brief Fault address.
-extern "C" HCore::UIntPtr read_cr3(); // @brief Page table.
+EXTERN_C HCore::UIntPtr read_cr0(); // @brief CPU control register.
+EXTERN_C HCore::UIntPtr read_cr2(); // @brief Fault address.
+EXTERN_C HCore::UIntPtr read_cr3(); // @brief Page table.
namespace HCore::HAL {
struct PageTable64 {
diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s
index a25b25c7..e4944111 100644
--- a/Private/HALKit/AMD64/HalRoutines.s
+++ b/Private/HALKit/AMD64/HalRoutines.s
@@ -1,5 +1,5 @@
-.globl rt_load_idt
-.globl rt_load_gdt
+.globl hal_load_idt
+.globl hal_load_gdt
.globl rt_wait_400ns
.globl rt_get_current_context
diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp
index 02951540..2c4a1c67 100644
--- a/Private/HALKit/AMD64/Processor.hpp
+++ b/Private/HALKit/AMD64/Processor.hpp
@@ -177,9 +177,9 @@ EXTERN_C void idt_handle_gpf(HCore::UIntPtr rsp);
EXTERN_C void idt_handle_math(HCore::UIntPtr rsp);
EXTERN_C void idt_handle_pf(HCore::UIntPtr rsp);
-EXTERN_C void rt_load_idt(HCore::HAL::Register64 ptr);
-EXTERN_C void rt_load_gdt(HCore::HAL::RegisterGDT ptr);
+EXTERN_C void hal_load_idt(HCore::HAL::Register64 ptr);
+EXTERN_C void hal_load_gdt(HCore::HAL::RegisterGDT ptr);
/// @brief Maximum size of the IDT.
-#define kKernelIdtSize 256
-
+#define kKernelIdtSize 0x100
+#define kKernelInterruptId 0x21