AMD64 Architecture Programmer’s Manual Volume 2 Rev. 3.22 states in section 14.6.1 "Activating Long Mode" that:
(Emphasis mine)Enable paging by setting CR0.PG to 1. This causes the processor to set the EFER.LMA bit to 1.
The instruction following the MOV CR0 that enables paging must be a branch[...]
However Entering Long Mode Directly and a few other samples I've looked at (a noteable exception being the sample directly following in the AMD manual) load the 64-bit GDT after enabling paging, but before branching.
Normally I would just ignore this (as I'm only playing around with os/x64 development for my own amusement) but since I can't get the sample (*) to work if follow the "proper way" (by moving the
Code: Select all
lgdt [GDT.pointer]
My question is: am I misreading the documentation or missing something? I'm testing with qemu and virtualbox (i realize they share the same emulation core).
(*) What prompted me to ask this question was my own code only working if I loaded the 64-bit GDT before switching to long mode, not so much randomly moving around instructions in the sample.