Boot Media And Memory Confusion

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
User avatar
saltlamp
Member
Member
Posts: 50
Joined: Tue Dec 11, 2018 3:13 pm

Boot Media And Memory Confusion

Post by saltlamp »

Hi, my apologies for this (potentially) noob question, but I am slightly confused about boot media/devices/drives and memory. I have looked over the Wiki, and this is exactly why I made this thread, because I couldn't find anything that answered my question.

My confusion is from all of the sources that I have read; all of which, say that 512 bytes are loaded into memory when the computer finds a boot-able disk/drive and boots from it. But since a DVD or optical media has 2 KB sectors, does the computer load 512 * 4 bytes into memory, or does it still only load 512 bytes into memory?

Thanks, and kind regards.
MrLolthe1st
Member
Member
Posts: 90
Joined: Sat Sep 24, 2016 12:06 am

Re: Boot Media And Memory Confusion

Post by MrLolthe1st »

Hi, BIOS loads all 2kb to memory, you can make a 2kb-bootloader, but signature at offset 510 must be a valid signature.
When BIOS gives control to your bootloader, in dl stored disk number, you can use it for int 13h.
Cheers,
Aleksandr
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Boot Media And Memory Confusion

Post by BenLunt »

Hi,

The (Legacy) BIOS will usually load a single sector. That doesn't mean that a sector is only 512 bytes. A sector is a sector. If that sector happens to be on a media device that has 2048-byte sectors, then it will load 2048 bytes. Same for 4096-byte sectors.

However, and this is a big however. It also depends on what the BIOS is doing. If the BIOS sees a Bootable CDROM and is in emulation mode, the emulation mode will determine if it has 512 bytes or 2048 bytes. For example, if the emulation is a 1.44Meg floppy, the BIOS might load 2048 bytes, but you can only assume that the first 512 are valid. You must treat the media device as a 1.44meg floppy and read any remaining 512-byte sectors that your boot code might need.

For example, if your boot code needs four (4) 512-byte sectors and you just booted from a CDROM that is using 1.44meg floppy emulation, even though the BIOS might have already loaded the 2048 bytes your code requires, you must call the BIOS to load three (3) more 512-byte sectors from the media, the second, third, and fourth (emulated) sectors. It is up to the BIOS whether it thinks it needs to read from the physical device or know that it has the 2048 bytes in memory and just reads from there. Your code must not assume so.

If the BIOS is in Hard Drive emulation (when booting from a CDROM), it might load a few more than one (512-byte) sector. The El Torito Specification states that the BIOS should read up to 256 sectors, depending on the value found in the boot catalog. (256 is from memory, i.e.: a single byte used for the count).

This same specification (go look it up) also allows you to specify which emulation you are using, the endian-ness of the information, etc.

Therefore, depending on whether your boot code is specific for the CDROM, and if so, what filesystem (ISO9660 or UDF), or if your code is generic and can easily be emulated as a hard drive image, will determine how many bytes are loaded for the first sector.

Ben
- http://www.fysnet.net/osdesign_book_series.htm
User avatar
saltlamp
Member
Member
Posts: 50
Joined: Tue Dec 11, 2018 3:13 pm

Re: Boot Media And Memory Confusion

Post by saltlamp »

Alright, I am starting to understand now. Thanks a lot, both of you. That confusion was causing me to not be able to move on with my multi-stage boot loader.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Boot Media And Memory Confusion

Post by bzt »

Hi,

BenLunt's answer is absolutely correct, although I'd like to point out the importance of boot catalog. On floppies and harddisks the BIOS always loads the very FIRST sector. On CDROM in no emulation mode, it's consulting the boot catalog to figure out which sector to load, which is probably not the first sector (but could be). The boot catalog may contain pointers to several boot sectors for different architectures and firmware, because CDROM images were designed to be bootable on multiple machines. Also note that many BIOSes are buggy, and they are only capable of reading the first entry in the catalog (I had problems with mixing EFI-x86 and BIOS-x86 entries on real machines, in my case the solution was to put BIOS-x86 in the first entry, and EFI-x86 in the second).

Cheers,
bzt
Post Reply