Last active
August 29, 2015 14:01
-
-
Save Mischa-Alff/acd3b6a4a539e13e89b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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