I am trying to write a bootloader to a Virtual Floppy Drive inserted in a VirtualBox VM. Here is the following code that I have:
org 0x7c00 ; We are loaded by BIOS at 0x7C00
bits 16 ; We are still in 16 bit Real Mode
Start: jmp loader
loader:
.Reset:
mov ah, 0x0 ; reset floppy disk function
mov dl, 0x0 ; drive 0 is floppy drive
int 0x13 ; call BIOS
jc .Reset ; If Carry Flag (CF) is set, there was an error. Try resetting again
.Load:
mov ax, 0x07e0 ; we are going to read sector to into address 0x07e0:0
mov es, ax
xor bx, bx
mov ah, 0x2 ; read floppy sector function
mov al, 0x1 ; read 1 sector
mov ch, 0x1 ; we are reading the second sector past us, so its still on track 1
mov cl, 0x2 ; sector to read (The second sector)
mov dh, 0x0 ; head number
mov dl, 0x0 ; drive number. Remember Drive 0 is floppy drive.
int 0x13 ; call BIOS - Read the sector
jc .Load
jmp 0x07e0:0x0000 ; jump to execute the sector!
times 510 - ($-$$) db 0 ; We have to be 512 bytes. Clear the rest of the bytes with 0
dw 0xAA55 ; Boot Signiture
It is supposed to load a small program into memory that prints the letter 'A' on the screen using a BIOS interrupt. This program is located on the second sector of the floppy disk:
org 0x07e0
xor bx, bx
mov ah, 0x0e
mov al, 'A'
int 0x10
cli
hlt
Can anyone tell me why this is not loading? I have tried loading to another address in memory 0x1000, however, this does not work either. Are there certain areas in the virtual memory that are reserved by VirtualBox?
Thanks!!
H
*Edit:
I build my code using nasm for Windows (nasm -f bin -o bootS1.bin bootS1.asm), and then copy and paste the hex from the binary file onto the VFD image using a program called HxD which writes the raw hex data to the disk. The disk is then inserted into the VM and ran to simulate the boot process.
You are reading from track 1 whereas the payload is on track 0. Remember: heads and tracks count from 0, sectors from 1.
Note that instead of hard-coding a disk number, you should use the number provided by the BIOS in dl
.
Also note that org 0x07e0
is incorrect. The offset at which your payload is loaded is 0 in segment 0x07e0
. So it should be org 0x0000
(or just no org
directive at all). Given that you do not refer to any addresses in the payload, this does however not cause the problems you observe.