Linux system startup, refers to the system from the power to the system console display "Login:" Login prompt to the operating stage, and the most closely related to this part of the code is: four assembler: Bootsect. S Setup. S head. S entry. S
MAIN.C files under the init directory
Primarily view the Start_kernel functions in INIT/MAIN.C:
In the system startup process, the main focus on several aspects: Interrupt system and scheduling system initialization of the file system of the equipment Management system initialization Network protocol initialization
Reset_init functions in INIT/MAIN.C:
In this function, there is the Kernel_thread function, which creates the kernel thread, and the prototype is as follows:
int kernel_thread (int (*FN), void *arg, unsigned long flags)
This function is defined in ARCH/XXX/KERNEL/PROCESS.C, which uses the Do_fork () function to create a new kernel-state thread, where Linux kernel threads are processes that do not have virtual storage space, run in the kernel, and use the physical address space directly.
The new kernel thread created by Kernel_thread is init, then returns, executes Unlock_kernel (corresponds to Lock_kernel in Start_kernel), and then executes Cpu_idle (), This is actually the end of the initialization of the main thread: it observes whether it is in tif_need_resched--in need_resched implementation, if not, let oneself sleep, no person completes schedule () function. TIF is the meaning of thread information flag.
Next move to the init function:
The init thread calls many functions, but the network-related sock_init () initialized in Do_basic_setup, and then continues to execute the Do_initcalls function, which is defined in the C file with two important variables __initcall_start and __initcall_end, they are defined as follows:
extern initcall_t __initcall_start, __initcall_end;
static void __init do_initcalls (void)
{
initcall_t *call;
int count = Preempt_count ();
/* from start traversal to end*/for
(call = &__initcall_start; Call < &__initcall_end; call++) {
char *mesg;
......
(*call) ();
msg = NULL;
}
}
The initcall_t class and __initcall_start,__initcall_end are defined in init.h files in the Include/linux directory.