Hi,
mangatmodi wrote:Tommy wrote:Before executing the boot sector, the BIOS stores the number of the boot drive in DL.
But please explain that why BIOS is storing the device number of cd-rom and not hard disk or floppy drive? is it because i'm using cd rom to boot from?
If you boot from any kind of disk, then the BIOS always puts the device number for that disk in DL before jumping to your boot loader. For example, if you boot from floppy then DL will (probably) contain 0x00 (the first floppy drive), and if you boot from a hard disk then DL will (probably) contain 0x80 (the first hard drive).
Originally there were no CD-ROMs (they weren't invented when the first 80x86/PC was designed) so they were added after, and for the original CD-ROMs there wasn't any way to boot from them until the "El Torito specification" was created. For backward compatibility (because no software supported booting from CD-ROM at the time) El Torito includes the ability for the BIOS to use a floppy disk image on the CD to emulate a real floppy drive, and/or to use a hard disk image on the CD to emulate a real hard drive. In both of these cases, the BIOS will shift device numbers around so that an emulated floppy drive is still device 0x00 (a real floppy drive that was device 0x00 would become device 0x01 in this case), and/or so that an emulated hard drive is still device 0x80 (a real hard drive that was device 0x80 would become device 0x81 in this case). Because of this emulation, old software that expected to boot from a floppy or hard drive could be put onto a CD and booted from CD (typically without any changes, as most old software used the BIOS for disk access and didn't try to write to the boot device while booting).
This floppy/hard disk emulation can cause problems in some cases. For example, it's normal to have a version of your OS on a bootable CD that's used to install a more permanent copy of the OS on the hard drive, but in this case the BIOS has renumbered the devices, so after the OS is installed you reboot and the device numbers have all changed. To get around that El Torito adds some extra BIOS functions to disable the emulation. There's also functions you can use to identify the types of devices (for e.g. so you can figure out if device 0x80 is a hard disk or not).
El Torito also supports "no emulation". This was completely new, and didn't need to conform to old conventions - for e.g. it uses 2048-byte sectors (just like the CD), and the BIOS loads any number of sectors at any starting address (e.g. the boot record on the CD can ask the BIOS to load 400 KiB at 0x00006000, instead of just one sector that is always loaded at 0x007C00). Despite this the BIOS still tells the boot loader which device it booted from. Typically the CD is device 0xC0, but there's no standard and it could be anything (possibly including 0x80 if there are no hard drives present). IMHO this is the cleanest way of booting from CD, but it means you need to write a different boot loader (rather than using the same floppy or hard disk boot loader for real devices and emulated devices/CD).
Of course a modern BIOS also supports booting from USB flash memory, and then there's hard disks and CD drives connected to USB (instead of being connected to an ATA controller or a SCSI controller), and for a while different pieces of software/firmware used different CHS->LBA conventions for hard disks, and some disk controllers (e.g. all SCSI controllers) replace the BIOS "int 0x13" functions with their own; so there's plenty of ways that everything can get messed up (normal bugs *and* incompatibilities)...
Cheers,
Brendan