Code: Select all
Trampoline_Start:
cli
xor ax, ax
mov ds, ax
mov ebx, [HeapStart]
; Set CR3 to PML4
mov eax, [ebx+BasicInfo.PageTable]
mov cr3, eax
; Enable PAE and PSE
mov eax, cr4
or eax, 0x30
mov cr4, eax
; Enable Long mode
mov ecx, 0xC0000080
rdmsr
or eax, 0x00000100
wrmsr
; Enable Paging and Protection at same time
mov eax, cr0
or eax, 0x80000001
mov cr0, eax
lgdt [GDT_PTR_Long]
jmp 0x8:LongModeTest
Trampoline_End:
Code: Select all
Trampoline_Start:
cli
lgdt [GDT_PTR]
mov eax, cr0
or al, 1
mov cr0, eax
jmp 0x8:.AP_PMode
[BITS 32]
.AP_PMode:
mov eax, 0x10
mov ds, ax
mov ebx, [HeapStart]
; Set CR3 to PML4
mov eax, [ebx+BasicInfo.PageTable]
mov cr3, eax
; Enable PAE and PSE
mov eax, cr4
or eax, 0x30
mov cr4, eax
; Enable Long mode
mov ecx, 0xC0000080
rdmsr
or eax, 0x00000100
wrmsr
; Enable Paging
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
lgdt [GDT_PTR_Long]
jmp 0x8:LongModeTest
Trampoline_End:
I'm wondering if anyone else has experienced similar issues? I'm not sure if there is a problem with my code or if switching directly to long mode from real mode no longer works on new hardware. I assume it has to be the former but I don't see anything wrong with my code, and am I wrong assuming that it should either
1. Successfully jump to LongModeTest in long mode or
2. Triple Fault
I haven't gotten a chance to debug it more (I should probably try it with 0 length IDT). Here is LongModeTest:
Code: Select all
[BITS 64]
LongModeTest:
cli
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov rax, [PayloadEntry]
mov edi, [HeapStart]
; Tell BSP we've started
mov DWORD [CpuGood], 1
; Wait for BSP to give us the OK to execute payload
.GetLock:
lock bts DWORD [Spinlock], 0
jc .PauseSpin
jmp rax
.PauseSpin:
pause
test DWORD [Spinlock], 1
jnz .PauseSpin
jmp .GetLock
Is there something wrong with my trampoline (other than not trying to mask NMIs) that would be causing this? Has anyone else had similar problems on hardware? Im trying to figure out if its possible that some pieces of hardware will not go from Real mode to Long mode directly, but this doesn't seem possible.