Reading data from from floppy disk problems
Posted: Mon Apr 11, 2022 5:39 am
- BIOS returns the floppy drive = 231 not 0 as I read floppy should be = 0 so when replacing dl with 0 in read: it fails to read the disk but when it replacing dl in reset: it resets successfully so which drive is reset while the floppy drive = 0
- When I put pusha in print_string before the rest of the code and popa in print_done before ret after running the program it only prints bootmsg
- When replacing 0x0F00 with 0x1000 and 0xF000 with 0x10000 it doesn't print Hello World but it prints S I don't know why
- When replacing 0x0F00 with 0x1000 and 0xF000 with es:bx (while it must be equivalent to 0x10000) it doesn't Hello World nor S
- I'm using qemu
- Command qemu-system-x86_64 -drive format=raw,file=%FILE%.img makes bios return drive 231 so what it boots as
- Someone told me to replace it with this command qemu-system-x86_64 -drive file=%FILE%.img,if=floppy,index=0,media=disk,format=raw it made bios returns drive number 0 which is the expected floppy number but bios prints this error Boot failed : could not read the boot disk while if the working version of the code as it is it prints Hello World despite this error
Code: Select all
program_intialization:
org 0x7C00 ;load program at 0x7C00
push dx ;save drive number to stack appeared to be 231 not 0
jmp program_start ;go to program_start
print_string:
cld ;clear direction flag to increase si after copying the value of the address pointed by it
lodsb ;copy [si] into al then increase si
or al,al ;check if al is null
jz print_done ;if null then go to print_done
mov ah,0x0E ;else copy 0x0E to ah which is the video output code
int 0x10 ;then interrupt the program with 0x10 the video routine code which will print the character in al
jmp print_string ;and print the next character until null is found
print_done:
mov al,0x0A ;copy the code of line feed into al
mov ah,0x0E ;copy 0x0E to ah which is the video output code
int 0x10 ;interrupt the program with 0x10 the video routine code which will print the character in al (the line feed)
mov al,0x0D ;copy the code of carriage return into al
mov ah,0x0E ;copy 0x0E to ah which is the video output code
int 0x10 ;interrupt the program with 0x10 the video routine code which will print the character in al (the carriage return)
ret ;return to the place the function is called from
program_start:
xor ax,ax ;intialize ax to 0
mov ds,ax ;intialize ds to 0
mov es,ax ;intialize es to 0
mov si,bootmsg ;copy bootmsg address to si
call print_string ;print bootmsg
reset:
mov si,rstmsg ;copy reset adress to si
call print_string ;print reset
mov ah,0 ;drive reset code
pop dx ;get drive number into dl
push dx ;save drive number again
int 0x13 ;reset drive
jc reset ;if failed try again
mov ax,0x0F00 ;copy 0x0F00 to ax
mov es,ax ;copy 0x0F00 to es
xor bx,bx ;make bx = 0x0000
mov si,scs ;if success
call print_string ;print scs
read:
mov si,rdmsg ;copy reset adress to si
call print_string ;print reset
pop dx ;get the drive number into dl
mov ah,0x02 ;copy disk read code to ah
mov al,1 ;read 1 sector
mov ch,0 ;on track 0
mov cl,2 ;read sector number 2
mov dh,0 ;head number 0
int 0x13 ;read from disk to memory address es:bx (0xF000)
jc read ;if failed try again
mov si,scs ;if success
call print_string ;print scs
end:
mov si,0xF000 ;which is es:bx
call print_string0 ;print Hello World read from memory 0xF000
cli ;clear all interupts
hlt ;halt the system
bootmsg db "Bootloader v0.1",0
rstmsg db "Trying to reset Floppy Disk",0
rdmsg db "Trying to read Floppy Disk",0
scs db "Operation Successful",0
times 510 - ($-$$) db 0 ;fill the rest of bootsector with 00
dw 0xAA55 ;boot magic number
msg db "Hello World",0 ;add hello world to the next sector (512bytes) which will be read