Hi,
I am new to OS Development and have just developed a boot loader that just print my name on screen using int 10 interrupt. I made a bootable CD from power iso booted by this boot loader.
everything was right there until I tried to boot a kernel present on cd.
I know that I need to use int 13,2 interrupt to read sectors but I can't find find the device number for CD-ROM. On searching I found about EL torrito format and wanted to load kernel with no emolution mode. But I'm unable to find device number for that too.
Please help me...!!
Thanks.
Need Help With Bootloader for cdfs...!!
- mangatmodi
- Posts: 6
- Joined: Tue Jul 21, 2009 1:03 pm
- Location: India
Need Help With Bootloader for cdfs...!!
I'm proud to be INDIAN
Re: Need Help With Bootloader for cdfs...!!
Before executing a boot sector, the BIOS stores the number of the boot drive in DL.
Must retrieve this value at the beginning of your boot sector.
For info: I made a CD-ROM bootloader available here. You can use it as an example.
Must retrieve this value at the beginning of your boot sector.
For info: I made a CD-ROM bootloader available here. You can use it as an example.
Last edited by f2 on Tue Jul 21, 2009 3:37 pm, edited 1 time in total.
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
- mangatmodi
- Posts: 6
- Joined: Tue Jul 21, 2009 1:03 pm
- Location: India
Re: Need Help With Bootloader for cdfs...!!
@Tommy
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?
Thanks for your reply...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?
I'm proud to be INDIAN
Re: Need Help With Bootloader for cdfs...!!
Hi,
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
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).mangatmodi wrote: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?Tommy wrote:Before executing the boot sector, the BIOS stores the number of the boot drive in DL.
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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Need Help With Bootloader for cdfs...!!
I tried using multiboot->boot_device to figure out whether I booted from hard drive or CD-ROM, and the first byte is basically the BIOS number passed along by GRUB. Unfortunately, nobody seems to agree about what the value should be for CD-ROM: I got 0xEF, 0xF0 from some emulators, and I think I even saw 0x82 from a PC. Currently I just assume it is a CD-ROM boot if the boot device is not a hard drive.
- mangatmodi
- Posts: 6
- Joined: Tue Jul 21, 2009 1:03 pm
- Location: India
Re: Need Help With Bootloader for cdfs...!!
@Brendan
Sir, Thanks a lot for your valuable help.
I was looking for it from quite long time. I guess, I will be now able to write bootloader for
CD-ROM, but I have realized that I need some more practice with assembly as I have always coded in C.
SO, I'm now taking some lessons on assembly properly and then I'll resume my work.
Once again, Thank you all for help. I will be coming back whenever I have some problem or when I think , I'm able to help
others.
Thank You,
Sir, Thanks a lot for your valuable help.
I was looking for it from quite long time. I guess, I will be now able to write bootloader for
CD-ROM, but I have realized that I need some more practice with assembly as I have always coded in C.
SO, I'm now taking some lessons on assembly properly and then I'll resume my work.
Once again, Thank you all for help. I will be coming back whenever I have some problem or when I think , I'm able to help
others.
Thank You,
I'm proud to be INDIAN