1

When using old legacy BIOS (consider X86 architecture), the boot loader jumps to a location at the real mode kernel (offset 512 which is defined in header.S assembly file) and starts the real mode code. The real mode code then prepares a stack and heap and jumps to main.c again in real mode. What about UEFI boot mechanism? Is the real mode kernel code still used? Does the boot loader jump to that same part of header.S and give control to that same code in real mode? More exactly, what is the difference of kernel initialization at the moment the boot loader jumps to OS code between legacy BIOS boot and UEFI boot?

  • If you want a Linux-specific answer, you probably should tweak this question to say "Linux" somewhere. Ironically, there's an alternative question, that wouldn't refer to header.S and main.c, that would address this process in a manner that is not Linux-specific. After all, the mechanism that you are asking about actually isn't. – JdeBP Aug 18 '17 at 15:50
  • @JdeBP My question is clear and is asked hopefully in the right place. If you have the knowledge to share and answer this question I appreciate if you do so, otherwise I don't see a reason for you to remind me of how a correctly structured question looks like. – user2808671 Aug 18 '17 at 15:55
2

Real mode code is not used when the EFI stub mechanism is used. The firmware (executed from flash ROM on the motherboard when the machine is booted) switches the processor to protected mode before loading the kernel image. The kernel image header is constructed to look like a PE executable as mandated by the UEFI specification. For more information see this Intel article.

Edit: added some info demanded in the comment below. arch/x86/boot/header.S contains the definitions that make the file look like a PE binary when compiled with CONFIG_EFI_STUB. The firmware calls the entry point placed in the header; the entry point is efi_pe_entry in arch/x86/boot/compressed/head_64.S. This routine calls make_boot_params and efi_main in arch/x86/boot/compressed/eboot.c. The former constructs a boot_params structure, and also loads an initramfs if specified on the command line. The kernel command line is also handled differently: UEFI takes care of it too, but because UEFI uses UCS-2 encoded strings (a subset of Unicode), they are converted to ASCII. Both header.S and head_64.S contain a lot of code that is common between the EFI stub and traditional way of booting.

Ps. UEFI may some day make it possible to get rid of Real Mode in x86 processors for good. It is only used for booting modern operating systems.

  • Thanks but I have not gotten my answer of how the kernel initializes then? Parts of some important initialization code are in real mode kernel, so those jobs must be done somewhere else when real mode code is not used. What code (which kernel files) tackle the same responsibility of real mode code? To what location does the boot loader jump? I want to read the code at that place. (the c or assembly file) Unfortunately it's not documented in Linux boot protocol clearly. – user2808671 Aug 18 '17 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.