From 9ff6bf983a40ae30472962343036a5b6d9d00e25 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 3 Sep 2026 21:02:08 +0200 Subject: x86_64/cpu: fix GDT size calculation The GDT pointer already receives the size in bytes when the GDT constructs it to activate the new GDT. Previously, the size in bytes got multiplied by the size of a single segment_descriptor before performing the mandatory subtraction of one. This means that the CPU lived in the believe that the GDT had a size of 448 bytes, instead of the true 56. Additionally, the calculation was flawed in another way, revealing the reason for why the size in bytes was passed to global_descriptor_table_pointer in the first place: it assumes that all entries in the GDT are of the same size. However, system descriptors are larger than basic segment descriptors. --- arch/x86_64/arch/cpu/global_descriptor_table.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/x86_64') diff --git a/arch/x86_64/arch/cpu/global_descriptor_table.hpp b/arch/x86_64/arch/cpu/global_descriptor_table.hpp index e485d65c..986dd566 100644 --- a/arch/x86_64/arch/cpu/global_descriptor_table.hpp +++ b/arch/x86_64/arch/cpu/global_descriptor_table.hpp @@ -23,7 +23,7 @@ namespace arch::cpu { template global_descriptor_table_pointer(global_descriptor_table const & gdt) - : size{GdtSize * sizeof(segment_descriptor) - 1} + : size{GdtSize - 1} , address{kapi::memory::physical_address{std::bit_cast(&gdt)}.raw()} {} -- cgit v1.2.3