Page 1 of 1

INT 0x13 AH=42 every time returning CF=1 AH=1 (USB reading)

Posted: Wed Dec 11, 2013 8:47 am
by ZigZogZang
Hey.

First of all i did test for:
INT 13h AH=41h: Check Extensions Present
And all was fine, because CF=0 after interrupt finished.

My code for INT 0x13 AH=42:

Code: Select all

mov ah, 0x42
mov dl, 0x80
mov si, DAPACK
int 0x13


DAPACK:
			db	0x10
			db	0
blkcnt:		dw	1		
db_add:		dw	0x7e00		
			dw	0		
d_lba:		dd	1		
			dd	0		
I want to read 1st sector (only one sector) of usb memory to 0:7E00

I am sure 0x80 is correct number of device (tested with interrupt 0x13 function 0x15).

I was trying to deal with it before i posted it here in many ways but all failed...

Each time int13 is done i get same bad result:
CF=1 and AH=1
CF=1 means error occured but according to http://en.wikipedia.org/wiki/INT_13H it means:
"0x01 Invalid Command"

Invalid command ? XD How ? What way invalid ? :)

Hope you will help me because i am out of energy at the moment, than you for help.

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 9:54 am
by iansjack
There's a lot of code that you are not showing us here, to do with setting the stack and the segment selectors. Are you 100% sure that it is correct?

I am suspicious of your assumption that 0x80 is the device you want to read from. Are you absolutely sure that your BIOS treats the device as a hard disk not as a floppy?

Edit: Return code AH=1 can also mean "invalid parameter"; now doesn't that sound more likely? If I were you I would single-step through the code in a debugger and check what you are actually loading into the registers before you call the interrupt. And take careful note of the segment registers to ensure that any addresses are correct.

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 1:10 pm
by ZigZogZang
iansjack wrote:There's a lot of code that you are not showing us here, to do with setting the stack and the segment selectors. Are you 100% sure that it is correct?

I am suspicious of your assumption that 0x80 is the device you want to read from. Are you absolutely sure that your BIOS treats the device as a hard disk not as a floppy?

Edit: Return code AH=1 can also mean "invalid parameter"; now doesn't that sound more likely? If I were you I would single-step through the code in a debugger and check what you are actually loading into the registers before you call the interrupt. And take careful note of the segment registers to ensure that any addresses are correct.

I am not using /setting stack in any way in this code. I am doing this code in bootloader so it's in real mode, so as segment i set 0x0 and offset 0x7e00

I have checked 0x80 as drive index. Check it with virtualbox too where ony device is usb, so... dunno what else may be the reason of error.

Any other ideas ? ;(

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 1:33 pm
by iansjack
You are not setting a stack, but you are calling an interrupt? That could be a mistake. I take it that you are saying you have set both CS and DS to zero?

Follow my advice of single-stepping through the code as far as the interrupt. Then you can see what parameters are being passed - the evidence is that they are invalid. But I would set up a minimal stack first. Even just disassembling the code may be enough to show you what is wrong.

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 1:57 pm
by ZigZogZang
iansjack wrote:You are not setting a stack, but you are calling an interrupt? That could be a mistake. I take it that you are saying you have set both CS and DS to zero?

Follow my advice of single-stepping through the code as far as the interrupt. Then you can see what parameters are being passed - the evidence is that they are invalid. But I would set up a minimal stack first. Even just disassembling the code may be enough to show you what is wrong.
I set stack and still error

mov ax, 0x0
mov ss, ax
mov sp, 0xffff

cs=ds=0

id is correct because i have tested with function ah=0x02 (int 13h) and it's working correctly but i'd preffer to use ah=0x42 function where i use LBA address directly

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 2:57 pm
by ZigZogZang
Ok, it's working now, why ? I don't know why.

I have deleted some part of code and then rewritten it and it's working, well... :wink:

Anyway 1 question about drive index.
Atm i am testing it with virtualbox and only 1 disk inside so my dl=0x80, right but what is the best way to detect my usb drive in random PC ? And what if there are 2 hard disk and 1 usb connected ? According to wikipedia 1st HD = 0x80, 2nd HD = 0x81, and no info about more Hard Disks, hmm ?

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Wed Dec 11, 2013 10:58 pm
by thepowersgang
1. That stack point is not sane (it's not aligned, and that area is above your boot sector, so you now have less memory to load new code into). HInt = Set SP=0x7C00, that'll make it grow downwards from your code and hence leave the area above free for other use
2. When the bootloader gets control, the drive number of the boot drive will be in `DL`, make sure to save that value and use it for all disk accesses.

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Thu Dec 12, 2013 2:05 am
by BMW
I get exactly the same problem, except only on one computer. It works fine with QEMU and my desktop, but if I boot it from my laptop I get AH = 0x01. Does anyone have any idea why this would be? Do some BIOSes not support using INT 0x13 AH=0x42 with USB flash drives?

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Thu Dec 12, 2013 2:58 am
by Octocontrabass
In my tests, I saw three behaviors across five or six different computers:
  • Int 0x13 extensions are always available.
  • Extensions are available only if there is a partition table in the first sector.
  • Extensions are available unless the first sector contains a BPB.
The amount of variety means it's difficult to guarantee that int 0x13 extensions will be available on all BIOSes. In fact, it's difficult to guarantee the correct code will be loaded. One BIOS, if it detects a valid partition table, skips the MBR entirely and loads the VBR of the active partition!

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Thu Dec 12, 2013 3:28 am
by Antti
Octocontrabass wrote:One BIOS, if it detects a valid partition table, skips the MBR entirely and loads the VBR of the active partition!
If this is true, I have to modify my boot system.

Re: INT 0x13 AH=42 every time returning CF=1 AH=1 (USB readi

Posted: Sat Jan 11, 2014 3:39 pm
by lihawl
Hi,ZigZogZang
Although, I didn't find someone wrote following thing in some specification, But I think it's really widely correct.
The device (inlcude ATA/STAT/usb hard disk except floppy disk) that your os booted from is first hard disk, that means it's driver number is 0x80.