So, I am beginning the development of a x86_64 hobby kernel and I found this code to load the GDT (Global Descriptor Table), but I don't understand what it does.
load_gdt:
lgdt [rdi]
mov ax, 0x10
mov ss, ax
mov ds, ax
mov es, ax
mov rax, qword .trampoline
push qword 0x8
push rax
o64 retf
.trampoline:
ret
I know it loads my gdt descriptor from the rdi register (register of the first parameter of a function call in sysv abi) but I don't know why I need to set all segment registers to 0x10 and what black magic is doing the rest ?