Page 1 of 1

Problem reading from USB

Posted: Thu Oct 11, 2012 6:59 am
by freakadella
Im working on my own operating system and have a problem with loading files from a USB flash drive. I am using int13h and ah 42h to read data from the USB, but I can't get it to work.I am trying to read the sector, right after the boot sector. You can see in the code, that I have put the ascii code for the W exactly one byte after the bootsector. I have implemented a jump in case int13h raises the carry flag and have found out that it always does so.Consequently I suspect the problem to be in the formating of my DAP. If someone could help with this problem, I would be very grateful.

Code: Select all

	mov ax, 0x000e
	mov si, ax
	mov ax, 0x07C0
	mov ds, ax
	mov dl, 0x01

jmp 1

	db 0x10
	db 0x00

	dw 0x0100

	dw 0x7D00
	dw 0x0000

	dw 0x0000
	dw 0x0000
	dw 0x0000
	dw 0x0001

1:

	clc
	mov ah,0x42
	int 0x13
	jc fail
	mov ah, 0xe
	mov al, [0x7D00]
	int 0x10

	fail:
	mov ah,0xe
	mov al,"f"
	int 0x10
loop:
	jmp loop

	times 510-($-$$) db 0
	db 0x55
	db 0xAA

	db "W"

Re: Problem reading from USB

Posted: Thu Oct 11, 2012 9:14 am
by egos
You are newbie! Flash drive usually has number 80h but will be better if you keep the number passed by BIOS. In USB-FDD mode you should use function 2 instead 42h. In this case flash drive usually has number 0.

Your DAP is incorrect:
- "number of sectors to transfer" should be 1, not 100h (max valid value is 7Fh);
- I think you meant offset 7E00h because 7C00h+512=7E00h;
- "starting sector number" should be 1, not 1000000000000h.

And setup the stack firstly.

Do you know what is the label? I think, no.

Code: Select all

mov si,dap
...
dap:
db 16,0,1,0
dd 0:7E00h ; fasm supports such address values
dq 1