Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform low-level IO with a USB flash drive under the BIOS (compared to a floppy)?

I have recently been studying some bootstrap code which was intended for use with a floppy drive. My goal is to modify the program so that it uses my USB flash drive. Now I see how the INT 13H function has been used with the floppy device, but I guess my question is, how will communicating with the USB drive differ?

For example, here is a snippet of the floppy code (GNU assembler):



    movb    $0x00,%dl       /* select 1st floppy */

    /* later */

    movw    sec,%cx     /* get sector number */
    movw    head,%dx    /* get head number */

    movw    $0x0201,%ax /* read 1 sector */
    int $0x13

Now I have read that moving 0x80 into %dl will select the first HDD in the BIOS. In my particular bios I can change the drive order, which would include a USB drive. I am quite sure this is becoming BIOS dependant, but I was thinking that the order listed in the BIOS could correspond to the value I move into %dl. I need to track down some documentation...

I am really unfamiliar with working with block devices as it is, can someone point me to a good place to start learning more?

Thanks!

like image 451
Mr. Shickadance Avatar asked Feb 14 '09 04:02

Mr. Shickadance


People also ask

What is a flash drive called in BIOS?

In some BIOS versions, it's called "Removable Devices" or "External Devices." Remove other USB devices.

Can I format a USB drive in BIOS?

Can I format a hard drive from the BIOS? Many people ask how to format a hard disk from BIOS. The short answer is that you can't. If you need to format a disk and you can't do it from within Windows, you can create a bootable CD, DVD or USB flash drive and run a free third-party formatting tool.


1 Answers

The simple answer is that if the BIOS can boot from the USB flash drive the same BIOS functions for floppy disk / hard drive access can be used.

The happy answer is that a simple technique allows the same boot sector code to access a floppy disk image on a USB flash drive whether it was booted with floppy disk emulation or hard drive emulation. If dl=80h (hard drive emulation)

GET DRIVE PARAMETERS
int 13h, ah=8
Return:
ch=maximum sector number (same as number of sectors per track)
dh=maximum head number (just add 1 to get number of heads)

This returned information describes the geometry of the emulated device (if dl=0 then it's standard floppy disk geometry - 18 sectors per track and 2 heads). This can be used to calculate the required Cylinder Head Sector information required for:

READ SECTOR(S)
int 13h, ah=2

and

WRITE SECTOR(S)
int 13h, ah=3

See Ralf Brown's Interrupt List - int 13h

See my post here: USB Booting Secrets

like image 77
Mike Gonta Avatar answered Sep 21 '22 16:09

Mike Gonta