Page 1 of 1

CD-Bootable

Posted: Wed Apr 06, 2011 6:43 pm
by digo_rp
Guys, how can I acess a cd drive using bios function int 0x13?

cuz my note have a sata ahci drive, harddisk and cdrom, does the bios do have like int 0x13 emulate reading and writing sectors ?

Re: CD-Bootable

Posted: Thu Apr 07, 2011 4:24 am
by Combuster
Have you even tried? The answer to the first question is in at least three different manuals.

Re: CD-Bootable

Posted: Thu Apr 07, 2011 5:33 am
by Brendan
Hi,
digo_rp wrote:Guys, how can I acess a cd drive using bios function int 0x13?
That depends on whether you booted from CD-ROM or not.

If You Didn't Boot From CD-ROM

In this case you might not be able to access the CD using the BIOS disk services at all, because some BIOSs don't bother giving the CD a "device number", and some BIOSs are broken (e.g. they report "phantom" devices that don't exist and may have other problems with CD-ROMs because CD doesn't have cylinders and heads) which makes it hard to figure out the correct device number to use.

The basic idea would be to use the "IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS" function for each possible "device number" (from 0 to 255) and see which device numbers correspond to devices that have 2048-byte sectors and are removable (but, this alone can cause false positives - it could still be a tape backup unit or something). You might also be able to check if the device is ATAPI, but that can cause "false negatives" (e.g. a SCSI or USB CD-ROM that isn't ATAPI is still a CD-ROM). To further qualify the device type, you should check the contents of the drive - if it looks like an ISO9660 file system, then it's a lot more likely to be a CD-ROM.

Even if that works, you still need to be able to handle systems that don't have any CD-ROM at all, and systems that have multiple CD-ROMs (e.g. if there's 3 CD-ROMs, then you need to figure out which CD-ROM is the one you want).

If you can get it to work, there will be no emulation - the device will look like a CD-ROM (the BIOS won't attempt to use the CD to emulate a hard disk or floppy disk), and the "IBM/MS INT 13 Extensions" functions can be used to read (2048-byte) sectors from the device.

If You Booted From CD-ROM

In this case the BIOS must support "El Torito" (otherwise you couldn't have booted from CD to begin with) and the BIOS will pass a valid "device number" to your boot loader in DL (which avoids the whole "detect the right device number" mess).

For "El Torito" there's 3 options, depending on what the CD contains. The first option is "no emulation". In this case there's no emulation, and the "IBM/MS INT 13 Extensions" functions can be used to read (2048-byte) sectors from the device.

The next option is "hard disk emulation". In this case the CD contains a "hard disk image"; DL contains the device number for a fake/emulated hard drive that corresponds to this disk image; and the "IBM/MS INT 13 Extensions" functions can be used to read (512-byte) sectors from it. You can't easily access the rest of the CD until/unless you ask the BIOS to disable emulation (which ends up being like the "no emulation" option).

The last option is "floppy disk emulation". In this case the CD contains a "floppy disk image"; DL contains the device number for a fake/emulated floppy drive that corresponds to this disk image; and the normal/older disk functions (e.g. "int 0x13, ah = 0x02") are used to read (512-byte) sectors from it. The "IBM/MS INT 13 Extensions" functions may not work for the emulated floppy disk (just like they may not work for a real floppy disk). You can't easily access the rest of the CD until/unless you ask the BIOS to disable emulation (which ends up being like the "no emulation" option).

In general, the "floppy/hard disk emulation" options are for OSs that don't support booting from CD. For example, for an old OS like DOS you could create a bootable floppy and make DOS boot from CD even though DOS never supported booting from CD. In general, for a new OS you want to avoid emulation and use the "no emulation" mode, because it's simpler (less chance of BIOS bugs), lets you access the whole disk without hassles, and is faster (because the BIOS isn't trying to make 2048-byte sectors look like 512-byte sectors).


In all of the "booted from CD-ROM" cases, read the OSdev wiki page on El-Torito and download and read the El-Torito specification. For "no emulation" and for "didn't boot from CD-ROM" you'll probably also want to read the ISO9660 page and its specification (because your boot loader will want to read files from the ISO9660 CD-ROM).


Cheers,

Brendan