I would like to ask if it is GRUB that switch the CPU to protected mode during boot up or is it the Linux kernel that does it. And also I would like to ask - is the kernel itself (vmlinuz) an ELF or is it plain binary format? Thanks.
AFAIK, Grub starts in real mode like any other software loaded at boot. It switches to protected mode for its run time (detecting HD, displaying menus etc.) and switches back into real mode before loading and running OS such as Linux that do not support multiboot protocol.
The kernel image is split into two pieces: The real-mode kernel code, which is small and can be loaded within the 640kB threshold of available memory; The rest of the kernel, which runs in protected mode and is loaded after the first megabyte of memory.
GRUB stands for GRand Unified Bootloader. Its function is to take over from BIOS at boot time, load itself, load the Linux kernel into memory, and then turn over execution to the kernel. Once the kernel takes over, GRUB has done its job and it is no longer needed.
The GRUB (Grand Unified Bootloader) is a tool for booting and loading operating system kernels and the default bootloader for systems based on the Linux kernel. Although it runs first when a machine is turned on, regular users rarely see GRUB in action. It functions automatically and requires no user input.
GRUB does drop you in protected mode.
The GRUB Multiboot Specification (version 0.6.96) Section 3.2 tells you this
‘CR0’
Bit 31 (PG) must be cleared. Bit 0 (PE) must be set. Other bits are all undefined.
And CR0 Register mapping tells you that the system should be in protected mode.
Linux is not a multiboot kernel and does not rely on some bootloader for switching in the PM, it follows the Linux Boot Protocol. But linux does the protected mode switch itself, and does not rely in the bootloader
check : http://lxr.linux.no/#linux+v2.6.39/arch/x86/boot/main.c
Here it calls go_to_protected_mode();
when then calls protected_mode_jump ()
which then does the CR0
stuff (sets the bit 0)
(The other bit says that paging is disabled)
EDIT
What i can figure out is that GRUB can detect linux boot protocol (GRUB2, and legacy should also) and loads linux on memory, but does not switch to protected mode. Have a look at this link: http://www.gnu.org/software/grub/manual/grub.html#GNU_002fLinux and section 16 of the page in this link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With