bootloader loading second stage issues
Posted: Sun Oct 23, 2011 4:45 pm
Note: I have a feeling that this will have been covered already in another thread, but I've searched and not found anything, so if there is such a thread, I apologise.
I want to make a two stage bootloader, which uses a floppy disk, but no file system, just raw copying of the binaries onto the disk. I believe this should be possible, I can't think of any reason why it wouldn't be, but whenever I try to load my second stage binary from the next sector, it fails. By fails I mean it is supposed to print a message, but it doesn't.
The code for stage1 is as follows:
and stage2:
The following procedure is how i assemble and write to disk:
and then use bochs to run the code by reading the floppy.
Note: /dev/sdc is because I'm using a usb floppy drive.
If anybody has encountered a similar problem or could shed some light on why this is not working it would be much appreciated.
Thanks for your time.
-0xC
I want to make a two stage bootloader, which uses a floppy disk, but no file system, just raw copying of the binaries onto the disk. I believe this should be possible, I can't think of any reason why it wouldn't be, but whenever I try to load my second stage binary from the next sector, it fails. By fails I mean it is supposed to print a message, but it doesn't.
The code for stage1 is as follows:
Code: Select all
bits 16 ;we start in 16 bit mode
org 0x7C00 ;and at 0x7C00
entry: ;start here!
jmp load
;; print: print the string that resides in si
print:
.printstart:
lodsb ;move a byte from si to al
or al, al ;check for a zero
jz .printend
mov ah, 0x0E
int 10h
jmp .printstart
.printend:
ret
load:
mov si, stage1msg
call print
mov ax, 0x1000 ;this is where the sector is going to be read into
mov bx, ax
xor ax, ax
mov es, ax
.reset:
mov ah, 0x0 ;function 0, reset
mov dl, 0x0 ;drive 0
int 0x13
jc .reset ;if the carry is set, something went wrong, try again
.read:
mov ah, 0x02 ;function 2, read
mov al, 1 ;read 1 sector
mov ch, 1 ;the sector past stage1, so still track 1
mov cl, 2 ;the sector to read
mov dh, 0 ;the head number
mov dl, 0 ;the drive number
int 0x13
jc .read
jmp 0x1000:0x00
cli
hlt
stage1msg db "This is stage1", 13, 10, 0
times 510 - ($ - $$) db 0 ;it needs to be 512 bytes
dw 0xAA55 ;boot signature
Code: Select all
org 0x1000 ; This sector is loaded at 0x1000:0 by the bootloader
start:
mov si, msg
print:
lodsb
or al, al
jz out
mov ah, 0x0E
int 0x13
jmp print
out:
msg db "This is the second stage!", 13, 10, 0
cli ; just halt the system
hlt
Code: Select all
nasm stage1.asm -f bin -o stage1
nasm stage2.asm -f bin -o stage2
cat stage1 stage2 > floppy.img
dd if=floppy.img of=/dev/sdc
Note: /dev/sdc is because I'm using a usb floppy drive.
If anybody has encountered a similar problem or could shed some light on why this is not working it would be much appreciated.
Thanks for your time.
-0xC