OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Reading data from from floppy disk problems
PostPosted: Mon Apr 11, 2022 5:39 am 
Offline

Joined: Sun Jul 19, 2020 9:45 am
Posts: 9
  • 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:
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


Top
 Profile  
 
 Post subject: Re: Reading data from from floppy disk problems
PostPosted: Mon Apr 11, 2022 12:19 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Androv wrote:
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

You can reset the floppy drive even when there's no disk in the floppy drive. Are you sure DL is 231? It should be 128 for a hard disk.

Androv wrote:
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

Perhaps the stack provided by the BIOS is too small. Perhaps you need to set BX before calling INT 0x10.

Androv wrote:
When replacing 0x0F00 with 0x1000 and 0xF000 with 0x10000 it doesn't print Hello World but it prints S I don't know why

Your assembler should tell you exactly why: the SI register is 16 bits, and 0x10000 doesn't fit in 16 bits.

Androv wrote:
When replacing 0x0F00 with 0x1000 and 0xF000 with es:bx (while it must be equivalent to 0x10000) it doesn't Hello World nor S

But LODSB uses DS:SI, not ES:BX. You'll have to show your code if you want help with this.

Androv wrote:
Command qemu-system-x86_64 -drive format=raw,file=%FILE%.img makes bios return drive 231 so what it boots as

It will boot as a hard disk, but it should be drive 128. Are you sure DL is 231?

Androv wrote:
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

QEMU tries to boot the hard disk, then displays the error message because it can't boot the hard disk, then boots your floppy disk. You can make the error message go away by adding "-boot order=a" to your command line.

Androv wrote:
Code:
    read:
        ...
        pop dx              ;get the drive number into dl
        ...
        jc read             ;if failed try again.

This loop repeatedly pops from the stack.


Top
 Profile  
 
 Post subject: Re: Reading data from from floppy disk problems
PostPosted: Wed Apr 13, 2022 8:06 pm 
Offline

Joined: Sun Jul 19, 2020 9:45 am
Posts: 9
Thanks .

Octocontrabass wrote:
Your assembler should tell you exactly why: the SI register is 16 bits, and 0x10000 doesn't fit in 16 bits.


so what i can do to print from es:bx


Top
 Profile  
 
 Post subject: Re: Reading data from from floppy disk problems
PostPosted: Wed Apr 13, 2022 8:56 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Your print_string function uses an address in DS:SI, not SI. So, one way you could print a string at ES:BX is to copy ES:BX into DS:SI.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group