From fc55f0d69d24fb4908cbd811681f2c3fac53614d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 31 Jan 2024 09:42:54 +0100 Subject: kernel: add GKit, improve AMD64 HAL. Signed-off-by: Amlal El Mahrouss --- Private/HALKit/AMD64/HalPlatformAMD64.cpp | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Private/HALKit/AMD64/HalPlatformAMD64.cpp (limited to 'Private/HALKit/AMD64/HalPlatformAMD64.cpp') diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp new file mode 100644 index 00000000..f72be01f --- /dev/null +++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp @@ -0,0 +1,47 @@ +/* + * ======================================================== + * + * HCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +namespace HCore::HAL { +namespace Detail { +struct RegisterAMD64 final { + UIntPtr base; + UShort limit; +}; +} // namespace Detail + +void GDTLoader::Load(Register64 &gdt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); + + reg->base = gdt.Base; + reg->limit = gdt.Limit; + + rt_cli(); + rt_load_gdt(reg); + rt_sti(); +} + +void IDTLoader::Load(Register64 &idt) { + Detail::RegisterAMD64 *reg = new Detail::RegisterAMD64(); + MUST_PASS(reg); + + reg->base = idt.Base; + reg->limit = idt.Limit; + + rt_cli(); + rt_load_idt(reg); + rt_sti(); +} + +void GDTLoader::Load(Ref &gdt) { GDTLoader::Load(gdt.Leak()); } + +void IDTLoader::Load(Ref &idt) { IDTLoader::Load(idt.Leak()); } +} // namespace HCore::HAL -- cgit v1.2.3