NASM assembly (with most of the unrelated code ommited):
Code: Select all
[bits 16]
[org 0x7c00]
; --- SNIP loading and debug code (segments are 0) ---
mov di,0x500
idt_build_loop:
mov ax,int_null
stosw
mov ax,0x0008
stosw
mov ax,0x8e00
stosw
mov ax,0
stosw
test di,0xd00
jb idt_build_loop
cli
lgdt [gdtr]
lidt [idtr]
mov eax, cr0
or ax, 1
mov cr0, eax
mov eax, 0x10 ; 0x10 points at the new data selector
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x8:main
gdtr:
dw 0x27 ; 5 entrys
dd gdt_data
gdt_data:
; null
dd 0x00000000
dd 0x00400000 ; size bit set
; global code
dd 0x0000ffff
dd 0x00cf9a00
; global data
dd 0x0000ffff
dd 0x00cf9200
; 16-bit code
dd 0x0000ffff
db 0x00009e00
; 16-bit data
dw 0x0000ffff
db 0x00009200
idtr:
dw 0x7ff ; 100 interupts * 8 bytes - 1 fencepost
dd 0x0500 ; lowest guaranteed free ram
int_null:
iret
times 510 - ($ - $$) db 0 ; fill rest of boot sector
dw 0xaa55 ; boot signature end of bootloader
[bits 32]
main:
mov dword [0xb8000], 0x07690748
mov eax,0x04
mov edx,0x04
mov esi,boothello
call textat
;int 0x41 ; uncommenting this causes the CPU to reset
jmp $
; --- SNIP more debug code ---
times 1024 - ($ - $$) db 0 ; fill rest of second sector