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?
It's asmlinkage void __init start_kernel(void)
C function in init/main.c
.
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_setup
does some basic setup of the environment for C, and calls main()
, which does some fairly dull stuff, ending with the actual jump to protected mode (see pmjump.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 is startup_32
in head_32.S
).
The kernel really gets going properly at startup_32
in arch/x86/kernel/head_32.S
. The code there ends up by calling i386_start_kernel()
in arch/x86/kernel/head32.c
, which finally calls the generic kernel startup code in start_kernel()
.