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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

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

Post 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 ? ;(
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

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

Post 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
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

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

Post 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 ?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

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

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

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

Post 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?
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Octocontrabass
Member
Member
Posts: 5604
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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!
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

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

Post 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.
lihawl
Posts: 6
Joined: Fri Nov 29, 2013 7:08 pm

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

Post 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.
Post Reply