After the boot loader hands execution over to the kernel, what happens? I know assembler, so what are the first few instructions that a kernel must make? Or is there a C function that does this? What is the startup sequence before the kernel can execute an arbitrary binary?
Share
I’ll assume that you’re talking about x86 here…
It depends where you consider the boundary between “boot loader” and “kernel” to be: the start of the kernel proper is 32-bit protected mode code, but the kernel itself provides some boot code to get there from real mode.
The real mode code is in
arch/x86/boot/:start_of_setupdoes some basic setup of the environment for C, and callsmain(), which does some fairly dull stuff, ending with the actual jump to protected mode (seepmjump.S).Where you end up now depends on whether or not the kernel is compressed. If it is, the entry point is actually a self-decompression routine. This is fairly dull stuff as well, and essentially transparent: the decompression code and compressed kernel are moved higher up in memory out of the way, then the kernel is uncompressed to the original location, and then jumped into as if it had been uncompressed all along. This code is in
arch/x86/boot/compressed/(the entry point isstartup_32inhead_32.S).The kernel really gets going properly at
startup_32inarch/x86/kernel/head_32.S. The code there ends up by callingi386_start_kernel()inarch/x86/kernel/head32.c, which finally calls the generic kernel startup code instart_kernel().