hi all. first post. anyway.. maybe this will help you. it's a simple bootloader that i wrote for my real-mode OS kernel that loads my 28 KB kernel into 1000:0000 starting from the second sector of the bootdisk. then it sets up some registers and transfers control to the kernel.
Code: Select all
org 7c00h
jmp entry
spt db 18 ;sectors per track
heads db 2 ;heads
entry:
xor ax, ax
xor bx, bx
xor cx, cx
xor si, si
xor di, di
xor bp, bp
push ax
push ax
push ax
pop es
pop ds
pop ss
mov sp, 0FFFEh
sti
lea si, loadbanner
call printstr
mov cx, 2
mov dx, 0
mov bx, 0
mov ax, 01000h
push ax
pop es
jmp read
readsect:
inc cl
cmp cl, spt
ja nexthead
add bx, 512
read:
push bx
push cx
mov ax, 0201h
int 013h
pop cx
pop bx
jc readerr
inc total
call printdot
push cx
mov cx, total
cmp cx, sectorcount
pop cx
jz success
mov retrycount, 0
jmp readsect
readerr:
push ax
mov ax, retrycount
inc ax
mov retrycount, ax
cmp ax, 7 ;allow up to 6 retries
pop ax
jnz read
lea si, errbanner
call printstr
cli
hlt
nexthead:
mov cl, 0
inc dh
cmp dh, heads
jnz readsect
mov dh, 0
inc ch
jmp readsect
success:
mov ax, 01000h
push ax
push ax
push ax
pop ds
pop ss
pop es
mov ax, 0FFFEh
push ax
pop sp
mov ax, 01000h
push ax
mov ax, 00h
push ax
cli
retf
printstr:
mov ah, 0Eh
mov al, [si]
cmp al, 0
jz goback
mov bx, 0
int 010h
inc si
jmp printstr
goback:
ret
printdot:
push ax
push bx
mov ah, 0Eh
mov al, '.'
int 010h
pop bx
pop ax
ret
total dw 0
retrycount dw 0
sectorcount db 56
loadbanner db 'Loading NamelessOS...', 0
errbanner db 'Error reading data! System halted.', 13, 10, 0
i'm pretty new to x86 assembly still, so i'm sure it could be made better somehow, but it does it's job perfectly and you can change a couple variables if you need to work with different disk geometries. the above code will work unmodified on a 1.44 MB floppy.