I was doing mit6.828 labs, and I'm quite curious about why BIOS would enable protected mode and then disable it (as bootloader should start in real mode)?
2 Answers
Many BIOS chips are even as big as 8-16MB before the UEFI era
The size of the BIOS, and the capacity of the ROM, EEPROM, or other media it may be stored on, has increased over time as new features have been added to the code; BIOS versions now exist with sizes up to 32 megabytes.
That's because nowadays BIOSes are very huge with lots of complex features like USB support, network boot, CD and DVD boot, automatic restore after BIOS failures (for dual-BIOS systems)... Some high-end BIOSes for overclockers have another way to restore BIOS even when both BIOS chips fail which probably requires another chip and FAT file system support
In the 90s I saw many BIOS setup routines (probably American Megatrends) support multiple languages including Japanese and Chinese so they also have to store the font table somewhere. That takes a lot of address space. Some modern BIOSes even contain quite extensive graphics (although not as impressive as UEFI's) and it's not possible to run those in real mode with just a few hundred KBs of RAM
Therefore most of the later BIOSes need to switch to protected mode in order to have more address space. See How can the BIOS larger than 64KB today?
You can also check out some open source boot firmware like SeaBIOS or Libreboot to see
- 30,396
- 15
- 136
- 260
Most of the current BIOSes are UEFI based. And UEFI BIOS is quite large on current platforms - these are complicated pieces of HW, requiring lots of initialization (even most basic CPU and memory bringup is nontrivial). Hence the code grew beyond what real mode can (easily) handle.
When the platform is then configured to utilize CSM and start in legacy BIOS mode - it has no choice but to switch to real mode before passing control to either legacy option rom (but please note CPU is left in what's called "big" real mode, per PCI spec for option roms) or legacy bootloader.
If you stay in UEFI boot mode - there is no need for such a switch as boot if performed by yet another UEFI binary.
- 1,288