Far jump goes crazy
Posted: Tue Jun 02, 2015 5:45 am
Hi! I was writing the code that should bring the CPU from real mode to protected mode,
starting from the GDT and then reloading the segments before the final jump to the next bootloader stage.
However the code doesn't behave as it should, because the far jump needed for reloading CS somehow
goes completely crazy and (as you can see below) CS isn't loaded with the correct value.
The GDT itself is correctly set (first thing I've check) as well as the GDTR structure pointer and its contents.
This is what VirtualBox says after the far jump:
Completely off-road, the virtual machine as well as me.
starting from the GDT and then reloading the segments before the final jump to the next bootloader stage.
However the code doesn't behave as it should, because the far jump needed for reloading CS somehow
goes completely crazy and (as you can see below) CS isn't loaded with the correct value.
The GDT itself is correctly set (first thing I've check) as well as the GDTR structure pointer and its contents.
Code: Select all
;;
;; File assembled with NASM
;; Function called from C. Defined as:
;; extern void JumpToPrelude(struct GlobalDescriptorRegister* GDTR)
;;
JumpToPrelude:
Use16
mov eax, cr3
inc al
mov cr3, eax
mov eax, [esp + 4]
lgdt [eax]
.ReloadSegments:
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x0008:.Continue
.Continue:
;;
;; This halt is never reached.
;;
hlt
mov esp, 0x00010000
mov ebp, esp
mov eax, 0x00020000
jmp eax
Code: Select all
VBoxDbg> r
eax=0000f734 ebx=0000b8d2 ecx=00005e8b edx=00005000 esi=0000660f edi=000075ff
eip=0000ff53 esp=00007bd8 ebp=0000468b iopl=0 nv up di pl zr na po nc
cs=f000 ds=0010 es=0010 fs=0010 gs=0010 ss=0010 eflags=00000046