Construct a simple Linux system menuos
Introduction of Linux Kernel source code
Three magic weapons (stored program computer, function call stack, interrupt) and two swords (interrupt context Toggle: Save field and resume scene, process context toggle)
1, in the Linux kernel source code inside arch occupies quite a large amount. The code in the Arch/x86 directory is our focus.
2, kernel boot-related code is basically in the init directory (MAIN.C).
Start_kernel is the starting point for initializing the Linux kernel.
Start_kernel equivalent to the main function in a C program
3, the core code of the Linux kernel in the kernel directory
Second, to construct a simple Linux system
Init is the first user-state process, which is process number 1th.
Kernel boot:
Third, follow up the Linux kernel boot process
1. How to use GDB to track the debug kernel
Boot kernel: Qemu-kernel linux-3.18.6/arch/x86/boot/bzimage -initrd rootfs.img-s-s/* freezes the CPU before you start * /
/* Create a GDB server-gdb on port 1234 tcp::1234 If you do not want to use port 1234, you can use-gdb tcp:xxxx instead of-s option */
Open another Shell window
- gdb
- file Linux-3.18.6/vmlinux # in GdB interface targe Before Remote load symbol table/* Load the kernel image with symbol table in */
- < span class= "Bash plain" (gdb) Target remote:1234 # Establish a connection between GDB and Gdbserver, press c to keep Linux on qemu running
- break start_kernel # breakpoints can be set either before target remote or after/* Set breakpoint Trace kernel */
The current state is frozen:
Start GDB:
Load the Linux symbol table and boot to the Start_lernel location:
Start_kernel down code, set a breakpoint:
At the tail of the Start_kernel:
2, simple analysis of Start_kernel
Main.c in the
Asmlinkage __visible void __init start_kernel (void)
501{
502Char *command_line;
503Char *after_dashes;
504
505/*
506 * need to run as early as possible, to initialize the
507 * LOCKDEP Hash:
508 */
509lockdep_init ();
510set_task_stack_end_magic (&init_task); /* Define the &INIT_TASK global variable, which is the pcb,0 process that was created manually-the final idle process */
511SMP_SETUP_PROCESSOR_ID ();
512debug_objects_early_init ();
513
514/*
515 * Set up the The The initial Canary ASAP:
516 */
517boot_init_stack_canary ();
518
519cgroup_init_early ();
520
521local_irq_disable ();
522early_boot_irqs_disabled = true;
523
524/*
525 * Interrupts is still disabled. Do necessary setups and then
526 * Enable them
527 */
All modules are initialized with INIT, and the module is initialized by Start_kernel.
Trap Init: Initialization of some interrupt vectors
To set the interrupt gate:
Start_kernel the last sentence of rest init:
Init_process is a Linux system 1th process , is the first user-state process, the default is the root directory of the program.
Kthreadd Create a kernel thread.
Dispatched to the Idel process (process No. 0 ) when no process is required for the system to execute
Iv. Summary
This week to learn to construct a simple Linux system, in the Linux kernel source code inside the arch occupies a very large amount, the code in the Arch/x86 directory is our focus, the kernel boot-related code is basically in the Init directory, The core code of the Linux kernel is in the kernel directory, and we mainly understand the execution process of the Start_kernel function . We construct a simple Linux system in the lab building to be careful with the construction process. Also learned that Rest_init called the No. 0 process, from the Start_lernel has been there, on the Windows system called the system idel,0 process created the 1th process, but also created a kernel thread of other services, so the system started up, This is the boot process of the kernel.
The third week of Linux kernel analysis notes constructs a simple Linux system menuos