Skip to content

Instantly share code, notes, and snippets.

@XanClic
Created November 17, 2015 02:32
Show Gist options
  • Save XanClic/b8d87473e5f324312a94 to your computer and use it in GitHub Desktop.
Save XanClic/b8d87473e5f324312a94 to your computer and use it in GitHub Desktop.
use16
org 0x7c00
cli
jmp far 0x0000:_start
gdtd:
dw gdt_end - gdt - 1
dd gdt
gdt:
dq 0
dq 0x00cf9a000000ffff
dq 0x00cf92000000ffff
dq 0x00af9a000000ffff
gdt_end:
_start:
push cs
pop ds
lgdt [ds:gdtd]
mov eax,cr0
inc eax
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:
; mulx rsp,rsp,rdx
db 0xC4, 0xE2, 0xDB, 0xF6, 0xE2
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