Bootloader just causes the machine to restart, doesn't really boot or load...
Desired effect:
Load and jump to binary on second sector of the bootdisk, as well as entering 32-bit protected mode.
How to Reproduce:
Compile following code with fasm, run in qemu.
Code: Select all
use16
jmp main
nop
times 59 db 0ffh
nSectors db 1 ; number of sectors to load
main:
mov ax,0002h ; set video mode
int 10h
mov byte [0xB8000],"1"
mov byte [0xB8001],07h
@@: mov ax,0 ; reset floppy device
mov dl,0
int 13h
jc @b ; try again
loadKernel: ; Load the kernel to physical addresss 0:1000h
mov bx,0
mov es,bx
mov bx,1000h
mov ah,2 ; read sector function code
mov al,1 ; read 1 sector at a time
mov ch,0 ; read from track 0
mov dl,0 ; read from drive 0 (floopy)
mov dh,0 ; read from head 0
mov cl,2 ; sector counter - start from the second sector (first sector is bootloader)
@@: int 13h ; do it!
jc loadKernel ; try again.
cmp cl,[2 + nSectors] ; did we load enough?
je @f ; yep, continue
add bx,200h ; nope, do more
inc cl
jmp @b
@@: mov byte [0xB8002],"2"
mov byte [0xB8003],07h
cli ; no interrupts beyond this point
sub ax,ax
mov ds,ax ; set ds to zero for gdt
lgdt [gdt_desc]
mov eax,cr0
or al,1
mov cr0,eax
use32
mov byte [ds:0B8004h], '3'
mov byte [ds:0B8005h], 07h
jmp 00h:1000h ; Jump to the kernel
; Gdt
gdt:
gdt_null:
dd 0
dd 0
gdt_code:
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data:
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end:
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
times 510-$ db 00h
dw 0aa55h