Created
November 17, 2015 03:29
-
-
Save XanClic/473bad1b711fa61f010e 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
use16 | |
org 0x7c00 | |
cli | |
jmp far 0x0000:_start | |
gdtd: | |
dw gdt_end - gdt - 1 | |
dd gdt | |
gdt: | |
dq 0 ; 0x00: NULL | |
dq 0x00cf9a000000ffff ; 0x08: 32 bit CS | |
dq 0x00cf92000000ffff ; 0x10: 32 bit DS | |
dq 0x00af9a000000ffff ; 0x18: 64 bit CS | |
gdt_end: | |
_start: | |
push cs | |
pop ds | |
lgdt [ds:gdtd] | |
mov eax,cr0 | |
or eax,0x00000001 | |
mov cr0,eax | |
jmp 0x08:pm | |
use32 | |
pm: | |
mov ax,0x10 | |
mov ds,ax | |
mov es,ax | |
mov ss,ax | |
mov esp,0xa0000 | |
mov eax,cr4 | |
or eax,0x20 | |
mov cr4,eax | |
mov edi,0x300000 | |
mov eax,0x30100f | |
stosd | |
mov ecx,0x03ff | |
xor eax,eax | |
rep stosd | |
mov eax,0x30200f | |
stosd | |
mov ecx,0x03ff | |
xor eax,eax | |
rep stosd | |
mov ecx,0x0200 | |
mov esi,0x008b | |
map_loop: | |
mov eax,esi | |
stosd | |
xor eax,eax | |
stosd | |
add esi,0x200000 | |
sub ecx,1 | |
jnz map_loop | |
mov eax,0x300000 | |
mov cr3,eax | |
mov ecx,0xc0000080 | |
rdmsr | |
or eax,0x00000100 | |
wrmsr | |
mov eax,cr0 | |
or eax,0x80000000 | |
mov cr0,eax | |
jmp 0x18:lm | |
use64 | |
lm: | |
mov rdx,0x0000111111111111 | |
mulx rsi,rdi,rdx | |
mulx rax,rax,rdx | |
hlt | |
times 510-($-$$) db 0 | |
dw 0xaa55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment