In a typical simple bootloader writing for x86, we have the following code to load the GDT and perform a far jump (note that CS is 0x0 before executing the following code):
lgdt gdtdesc
movl %cr0, %eax
orl $1, %eax
movl %eax, %cr0
# Jump to next instruction, but in 32-bit code segment.
# Switches processor into 32-bit mode.
ljmp $0x8, $protcseg
.code32 # Assemble for 32-bit mode
protcseg:
However, just after lgdt
CS is null, pointing to a null descriptor in GDT. So :
1.How on earth can the CPU fetch the correct instruction just after GDT is loaded by lgdt
?
2.DPL of the code segment to far-jump to is usually 0, does the CPU perform privilege check when doing the far jump?