[SOLVED] Bootsector: How to tell if USB uses FDD/HDD emu?

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
b00tsect
Posts: 2
Joined: Sun Feb 26, 2012 11:10 am

[SOLVED] Bootsector: How to tell if USB uses FDD/HDD emu?

Post by b00tsect »

Hi all,

I've wrote a bootsector that checks for int 13h extensions (thanks for the site, excellent resources in the wiki), using the extensions if they're present, otherwise falling back to LBA to CHS translation and using int 13, 2h. This works fine, on bochs, most of my computers, etc. (both FDD/HDD).

Except one machine: my primary one! When I try to boot off USB, it makes it appear as though it uses HDD emulation and says it supports the int 13h extensions (with no error code returned afterwards), but doesn't actually read any data. The drive index is 0x80, and the snippet below results in control flow going to read_sectors_lba. If I insert an unconditional jmp to use the CHS routine, the machine in question boots fine. Other machines boot using the LBA code fine, so there shouldn't be any bugs.

Code: Select all

  # Check to see what routines are supported
  movw %cx, %dx
  movb $0x41, %ah
  movw $0x55AA, %bx
  stc

  int $0x13

  jc read_sectors_chs
  cmp $0xAA55, %bx
  jne read_sectors_chs
  testb $0x01, %cl
  jz read_sectors_chs

read_sectors_lba:
   ...
I'm stumped. Any ideas?
Thanks in advance.
Last edited by b00tsect on Sun Feb 26, 2012 12:21 pm, edited 1 time in total.
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: Bootsector: How to tell whether USB uses FDD/HDD emulati

Post by M2004 »

1) A buggy bios failing to boot properly from usb device by using lba method?

2) Do you check edd support bit (bit4, cx register) returned by
INT 13h AH=41h: Check Extensions Present

http://en.wikipedia.org/wiki/INT_13H#IN ... ns_Present

Regards
Mac2004
b00tsect
Posts: 2
Joined: Sun Feb 26, 2012 11:10 am

Re: Bootsector: How to tell whether USB uses FDD/HDD emulati

Post by b00tsect »

No need to check bit 4; look at grub source:

Code: Select all

   /* use CHS if fails */
   jc LOCAL(chs_mode)
   cmpw  $0xaa55, %bx
   jne   LOCAL(chs_mode)

   andw  $1, %cx
   jz LOCAL(chs_mode)
You were right on the buggy BIOS, though; %dl was getting wiped after the call to int 13h, 41h. Thanks! :D
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: [SOLVED] Bootsector: How to tell if USB uses FDD/HDD emu

Post by M2004 »

Good, you got this problem solved =D>

Regards
Mac2004
Post Reply