So far I have 2 files namely boot.s which is to load stuffs from floppy and setup.s for testing the bootloader. My Makefile goes like this:
Code: Select all
AS=as
LD=ld
LDFLAGS_16=-s -Ttext 0 --oformat binary
LDFLAGS_SYS=-s -x -m elf_i386 -e fin -Ttext 0 -M
CC=gcc
boot: boot.s
$(AS) -o boot.o ./boot.s
$(LD) $(LDFLAGS_16) -e start -o $@ ./boot.o
setup: setup.s
$(AS) -o setup.o ./setup.s
$(LD) $(LDFLAGS_16) -e fin -o setup ./setup.o
image: boot setup
#dd if=./boot of=./image
cat ./boot ./setup >./image
clean:
rm ./boot ./setup ./*.o
Code: Select all
#some initialization and output stuff and ljmp 0x0c70 etc.
#initialise registers for int 0x13
movw $SYSSEC, %ax
movw %ax, %es
xor %di, %di
movb $0x02, %cl
xor %ch, %ch
xor %dx, %dx
xor %bx, %bx
loading:
movb $2, %ah
movb $1, %al
int $0x13
jc retry
xor %di, %di
#loading sectors on other headers or cylinders
movw %es, %ax
add $0x20, %ax
movw %ax, %es
inc %cl
cmp $18, %cl
jbe loading
movb $1, %cl
inc %dh
cmp $2, %dh
jb loading
xor %dh, %dh
inc %ch
cmp $10, %ch
jb loading
#All done, output success info
movw $BOOTSEC, %ax
movw %ax, %es
movw $7, %cx
movw $0x1105, %dx
movw $0x000c, %bx
movw $ok_msg, %bp
movw $0x1301, %ax
int $0x10
ljmp $SYSSEC, $0
#if something goes wrong with loading
#retry 5 times
retry:
inc %di
cmp $5, %di
jae error_loading
xor %al, %al
xor %dl, %dl
int $0x13
jmp loading
hlt:
jmp hlt
#if things just doesn't go well after
#repeated retry
#output error info and jmp to hlt
In addition, I'm using the qemu and running the command like:
Code: Select all
qemu-system-i386 -cpu 486 -fda ./image -boot a -s
Thank you beforehand!