I. Introduction to Linux kernel source code
Stable version kernel: Linux-3.18.6
Directory structure of the Linux kernel source code:
Arch Catalog: In the Linux kernel source code occupies a large proportion, because the Linux kernel supports a lot of architectures, and the Arch directory is to support different CPU source code. arch/x86 directory is the key
Documentation Directory: Document Directory
FS Directory: File system
Init directory: Kernel boot-related code is basically in the Init directory, where the Start_kernel function in the main.c code is equivalent to the main function of the normal C program
IPC Directory: interprocess communication
Kernel Directory: Core code of the Linux kernel in the kernel directory
LIB directory: common library files
MM Directory: Memory-managed
Readme directory:
Two. Construct a simple Linux system
L Open the shell using the virtual machine of the lab building
Enter menu program after kernel boot, support three commands help, version and quit
L TRACE the kernel through GDB
L build menuos with your own Linux system environment
Init is the first user-state process
L reconfigure Linux to carry debug information
- On the basis of the original configuration, make Menuconfig Select the following option to reconfigure Linux to carry debug information
- Make recompile (longer)
L use GDB to track debug kernel
Freeze the-s:cpu before initializing it.
-S: A gdbserver is created on the port
Open another Shell window
Three. Track the boot process of debugging Linux kernel
The experiment is as follows:
Simple analysis of Start_kernel:
Init_task the pcb,0 process, which is created manually, is the final idle process
Regardless of which part of the analysis kernel will be involved in Start_kernel
Trap_init (): Initialization of some interrupts
Dispatched to the idle process when no process is required for the system to execute
Four. Summary
Init is the first to invoke a program compiled with the standard C library. Prior to this, no standard C application was implemented. On a desktop Linux system, the first program to start is usually/sbin/init, which has a process number of 1. The init process is the initiator and controller of all processes, and it has two functions:
(1) Play the role of ending the parent process: All orphan processes will be taken over by the INIT process.
(2) System initialization work: such as setting keyboard, font, loading module, setting up network, etc.
After the initialization of the system, the INIT process will run the Getty (Login program) on the console and the login interface we are familiar with appears.
The third week constructs a simple Linux system menuos