User:Madanra/Tasks before leaving Real Mode

From OSDev Wiki
Jump to: navigation, search

Before switching to Protected Mode or Long Mode, there's a number of tasks you'll want your bootloader to perform that are hard or impossible afterwards.



  • Get a map of the physical address space
The only safe and reliable way of getting a memory map is BIOS function INT 0x15, EAX=0xE820 or UEFI function GetMemoryMap. See Detecting Memory (x86) and Memory Map (x86).
  • Video tasks
If you don't have a video driver for every graphics card in existence, you're going to need to use BIOS or UEFI functions. You may want to:
  • Get a list of video modes
  • Get the monitor's EDID
  • Set the video mode
See Getting VBE Mode Info.
  • Get a list of disk drives present and their "virtual cylinders, heads, and sectors" information
The CHS information is useful for correctly setting the CHS values in partition tables without guesswork, and you'll to know the mapping from "BIOS device number" to physical device so that after booting you know which devices the CHS geometry you found applies to.
  • If you booted from disk, find out what disk you booted from
This is somewhat covered by the previous item, but is one its most important advantages: if you've loaded your kernel etc. using BIOS functions and a "BIOS device number" you'll need to know what physical device this corresponds to so you can identify what physical partition you booted from once your OS is running.
  • If you booted from network, get network information
Find the network card's MAC address and IP address, plus the DNS server's IP address, TFTP server's IP address etc. so that you can avoid doing (relatively slow) DHCP negotiations a second time if/when possible.
  • BIOS only
  • Determinte PCI access mechanism
It's best to ask the BIOS to avoid manual probing. See PCI.
  • Enable A20 line
It's best to ask BIOS to do it and fall back to less reliable methods if the BIOS won't. See A20 Line
  • Tell the BIOS what mode you're going to use
For x86-64 processors, the AMD manuals specify a BIOS function INT 0x15, EAX=0xEC00, BL=mode which tells the BIOS whether we are planning to use protected mode only, long mode only, or a mixture.
  • UEFI only
  • Get addresses of ACPI, SMBIOS etc. tables
UEFI tells you the location of various significat tables so you don't have to search for them.
  • Load your kernel/initrd/whatever
Self-explanatory :)

See also


Forum threads

External links

Personal tools