Skip to content

Instantly share code, notes, and snippets.

@Azerothian
Created May 25, 2010 13:03
Show Gist options
  • Save Azerothian/413104 to your computer and use it in GitHub Desktop.
Save Azerothian/413104 to your computer and use it in GitHub Desktop.
org 0x0 ; offset to 0, we will set segments later
bits 16
jmp main ; Jump to main
main:
;Dont know whats in the segment registers so lets just reload them anyway :)
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ax, 0x9000
mov ss, ax
mov sp, 0xFFFF
jmp switch_to_prot
switch_to_prot:
cli
;call enableA20
lgdt[gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp codeSel:protectedMode
enableA20:
in al, 0x92
or al, 2
out 0x92, al
ret
bits 32
protectedMode:
cli
hlt
[bits 16]
gdt dw 0
dd 0
gdtr:
dw gdtEnd-gdt-1
dd gdt
nullSel equ $-gdt
codeSel equ $-gdt
codeGdt
dw 0x0ffff
dw 0x0000
db 0x00
db 0x09a
db 0x0cf
db 0x00
dataSel equ $-gdt
dataGdt
dw 0x0ffff
dw 0x0000
db 0x00
db 0x092
db 0x0cf
db 0x00
videoSel equ $-gdt
dw 3999
dw 0x8000
db 0x0b
db 0x92
db 0x00
db 0x00
gdtEnd
bootingSystem db "Booting process started..", 0dh, 0ah, 0
switching db "Switching to protected mode..", 0dh, 0ah, 0
times 510 - ($ - $$) db 0
dw 0xaa55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment