I'm working on a simple kernel that follows the multiboot specification. This is for a class project, so I can't post my code directly, but for my question, it's sufficient to say that we're using a modified version of the multiboot sample code.
I'm trying to set the global descriptor table register (GDTR) to point to the appropriate address. In order to do so, I've been following the GDT Tutorial from the OSDev wiki. In the tutorial, their sample code for flat protected mode simply loads two values off the stack and puts those into the GDTR. This confuses me because I thought the GDTR should be set before the stack is initialized. I don't know where the ESP would be pointing if the kernel hasn't initialized it yet. I suppose it's possible that GRUB sets it to something before jumping to any of the code in boot.S, but I haven't been able to find any documentation to suggest that.
tl;dr - Why does the OSDev GDT Tutorial retrieve data from an address relative to ESP when loading the address and size of the global descriptor table?