X86: Question about GDT loading

From: Alexandre

Date: Sun Aug 16 2026 - 16:58:38 EST


I was tracing the execution of the file
"arch/x86/boot/compressed/head_32.S" with gdb when I noticed that the
address used for the GDT in the GDTR structure pointed to the GDTR
itself.

This is weird because it would make the GDTR an entry in the GDT.

I see that the code (line 64) loads address of the "gdt" label (line
172), which contains the GDTR data and the GDT entries, into eax and
then stores that address, as the GDT offset field (line 65).
Also, the GDT size field is calculated including the size of the GDTR
data. (I unsure if that's intended)

Taking a look with gdb and with the kernel compiled for i386, we can
see that the address being used in the "lgdt" instruction (line 66)
is the same one being used as the offset for the GDT.

gdb:
Assembly:
0x10001d lgdtl (%eax)
(gdb) i r eax
eax 0xca2000 13246464
(gdb) x/64bx 0xca2000
0xca2000: 0x1f 0x00 0x00 0x20 0xca 0x00 0x00 0x00
0xca2008: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xca2010: 0xff 0xff 0x00 0x00 0x00 0x9a 0xcf 0x00
0xca2018: 0xff 0xff 0x00 0x00 0x00 0x92 0xcf 0x00
0xca2020: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xca2028: 0x00 0x00 0x00 0x00 0x05 0x00 0x00 0x00
0xca2030: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0xca2038: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
(gdb)

After the size field ( 0x1f 0x00 ) the address of the GDT points to
the GDTR ( 0x00 0x20 0xca 0x00 ).

Please let me know if that is intended or not.

Kind regards,
Alexandre Ramos