Skip to content

Instantly share code, notes, and snippets.

@Mischa-Alff
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mischa-Alff/acd3b6a4a539e13e89b8 to your computer and use it in GitHub Desktop.
Save Mischa-Alff/acd3b6a4a539e13e89b8 to your computer and use it in GitHub Desktop.
; disable paging
mov eax, cr0
and eax, (1<<31)-1
mov cr0, eax
; Clear memory that will
; contain page tables stuff
mov edi, 0xC1000
mov cr3, edi
xor eax, eax
mov ecx, 4096
rep stosd
mov edi, cr3
; set up paging tables
mov dword [edi], 0xC2003
add edi, 0x1000
mov dword [edi], 0xC3003
add edi, 0x1000
mov dword [edi], 0xC4003
add edi, 0x1000
; identity map the first 4 MiB
mov ebx, 0x3
mov ecx, 0x200
.se:
mov dword [edi], ebx
add ebx, 0x1000
add edi, 8
loop .se
; enable PAE paging
mov eax, cr4
or eax, 1 << 5
mov cr4, eax
call print_dot
; set LM-bit
mov ecx, 0xC0000080
rdmsr
or eax, 1 << 8
wrmsr
call print_dot
; enable paging
mov eax, cr0
or eax, 1 << 31
mov cr0, eax
call print_dot
jmp $
; load 64-bit gdt
lgdt [gdt.pointer]
; jump to 64-bit entry point
jmp gdt.code:entry64
call print_dot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment