Page 1 of 1
Unable to read floppy sector with bochs,
Posted: Mon Aug 02, 2010 7:56 am
by tushs
Hi I am trying to read a sector from floppy drive bochs set up but somehow its is not working bellow is the code , kindly help m to figure out problem,
Code: Select all
BITS 16
ORG 0x7C00
entry:
; clear screen
mov ax, 0x9100
mov ss, ax
mov sp, 0x9000
mov ah,0
mov al,0x03 ; 0x13 set mode vga 256 color 0x03 80*25 16 color
int 0x10
xor ax,ax ; set ax zero
mov ds,ax ; initilize data segment register
mov es,ax
mov ah,0x02
mov al,0x01
mov ch,0x00
mov cl,0x02
mov dh,0x00
mov dl,0x00
mov bx,0x7e00
read_sector:
int 0x13
jc read_sector
mov si, msg
call print_str
mov si,0x7e00
call print_str
jmp hang
read_error:
mov si,msg_err
call print_str
hang:
jmp hang
print_str:
lodsb ; this will load a byte from DS : SI to al
or al,al ; this will set zero flag if output of or is zero
jz print_str_out ; jump if zero
mov ah,0x0E ; print char
mov bx,0x007 ; color
int 0x10 ; call bios
jmp print_str
print_str_out:
retn
; Memory Data
;--------------------------------------------------------
msg db 'Read Sector',0
msg_err db 'Read Error',0
; Size should not be greater then 510 bytes
;--------------------------------------------------------
size equ $ - entry
%if size+2 > 512
%error "Code is greater then 512"
%endif
times 510-($-$$) db 0 ; Note that this does not handle -ve error condition
dw 0AA55h
my bochs file has a line
Code: Select all
floppya: 1_44=boot.bin, status=inserted
boot:floppy
I am able to display message and play with int 10h but I am not able to read sector and displaying it on screen.
Re: Unable to read floppy sector with bochs,
Posted: Mon Aug 02, 2010 9:38 am
by Code0x58
You shouldn't change DL (drive number) as that is already set for you by the BIOS before it jumps to your loader, you can probably get away with having AL as 0x11 as well to read the remaining 17 sectors of the track.
Re: Unable to read floppy sector with bochs,
Posted: Mon Aug 02, 2010 2:25 pm
by bewing
Does it print your error message, or your regular message? How do you know it is not working?
Re: Unable to read floppy sector with bochs,
Posted: Mon Aug 02, 2010 5:39 pm
by Code0x58
my guess is that it doesn't print anything as it gets stuck at
Code: Select all
read_sector:
int 0x13
jc read_sector
It's never going to print an error message as there isn't any way to get to it, if it were to print the normal message then it would be all right if not a little dodgy because of DL being changed - unless you appended something to the end of that boot sector such as some text the print_str 0x7e00 won't display anything because it would still be zeroed memory as far as I am aware.
Re: Unable to read floppy sector with bochs,
Posted: Tue Aug 03, 2010 12:30 am
by tushs
Thank all of you for reply,
I had updated code with following changes
1. comment out mov dl,0x00
2. Added print if read error
3. added prints after successful read sector.
4. added print after display buffer.
I got output as,
"Read Sector Read Sector "
This indicates that sector read is successful, code is not in "hang" loop but still I am not able to get correct buffer at 0x7e00, es 0x00
. Following is updated code.
Code: Select all
[BITS 16]
[ORG 0x7C00]
entry:
; clear screen
mov ax, 0x9100
mov ss, ax
mov sp, 0x9000
mov ah,0
mov al,0x03 ; 0x13 set mode vga 256 color 0x03 80*25 16 color
int 0x10
xor ax,ax ; set ax zero
mov ds,ax ; initilize data segment register
mov es,ax ; set es to zero
mov ch,0x00
mov cl,0x02
mov dh,0x00
; mov dl,0x00 ; Let dl be same which is set by BIOS
read_sector:
mov ah,0x02 ; on error ah al bx, will be used so reset it
mov al,0x11
mov bx,0x7e00
int 0x13
jc read_error
mov si, msg
call print_str ; Print Message after successful read
mov si,0x7e00
call print_str ; Now display buffer
mov si, msg
call print_str ; Print same message after display buffer
jmp hang
read_error:
mov si,msg_err
call print_str
mov ah,0x00 ; Reset Disk
int 0x13
jmp read_sector
hang:
jmp hang
print_str:
lodsb ; this will load a byte from DS : SI to al
or al,al ; this will set zero flag if output of or is zero
jz print_str_out ; jump if zero
mov ah,0x0E ; print char
mov bx,0x007 ; color
int 0x10 ; call bios
jmp print_str
print_str_out:
retn
; Memory Data
;--------------------------------------------------------
msg db 'Read Sector ',0
msg_err db 'Read Error ',0
; Size should not be greater then 510 bytes
;--------------------------------------------------------
size equ $ - entry
%if size+2 > 512
%error "Code is greater then 512"
%endif
times 510-($-$$) db 0 ; Note that this does not handle -ve error condition
dw 0AA55h
; Output of This code is
;=> Read Sector Read Sector
Re: Unable to read floppy sector with bochs,
Posted: Tue Aug 03, 2010 4:11 am
by tushs
This is latest update
same code is working on VMware and it is not working with boshs.... I prefer to use linux, can any one tell me why bochs is not working ....
Re: Unable to read floppy sector with bochs,
Posted: Tue Aug 03, 2010 6:16 am
by Code0x58
tushs wrote:I got output as,
"Read Sector Read Sector "
This indicates that sector read is successful, code is not in "hang" loop but still I am not able to get correct buffer at 0x7e00, es 0x00
.
Unless you aren't showing us some of what you are doing such as appending a text file to your boot sector that's all you will get, what would it have to read in otherwise? I tested the code with text on the end and it worked: all I did was stick something along the lines of
db "if this is printed we have read sector 2!", this string would end up at the start of the next sector because of the times statement above makes sure that everything up to the 0xaa55 is in sector 1 and anything after is in sector 2. As a side note you don't completely need the error with the if, the times statement throws an error if it is given a negative count.
Re: Unable to read floppy sector with bochs,
Posted: Tue Aug 03, 2010 8:46 am
by tushs
I got problem my bochs rc was incorrect. Anyway thank u all for help.