Experimental process:
Open the shell terminal and execute the following command:
CD linuxkernel/
Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img
After execution, the Qemu window will pop up, output the Linux kernel boot information and display menuos after successful startup.
Enter help to indicate that the streamlined system supports three commands: Assist, version, quit
Debug kernel with GDB trace
Open the shell terminal and execute the following command:
CD linuxkernel/
Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD Rootfs.img-s-S
Notes on the-s and-s options:
-S freeze CPU at startup (using ' C ' to start execution) freezes the CPU at system startup and continues with the C key
-S shorthand for-gdb tcp::1234 open remote debugging port, TCP protocol 1234 is used by default, and if you do not want to use port 1234, you can use-gdb tcp:xxxx instead of-s option
Open another shell terminal and execute the following command:
(gdb) file Home/shiyanlou/linuxkernel/vmlinux
(GDB) Target remote:1234 # Establish a connection between GDB and Gdbserver, press C to keep the Linux on qemu running
(GDB) Breakstart_kernel # Breakpoint can be set to continue execution to Start_kernel () function before target remote, by pressing C key
Enter the list command to view the Start_kernel () function code
Enter the following directives:
(GDB) Break Rest_init set a breakpoint
Enter the list command to view the Rest_init () function code
Analysis:
The Linux kernel boot code is roughly divided into 2 parts:
Part of the hardware platform-related, stored in the./arch/directory, the platform to distinguish between different directories, such as the x86 platform in the./arch/x86/directory, written by the assembly language.
The other part is hardware platform-independent, written by C language.
The Start_kernel () function in the./INIT/MAIN.C is the first function executed by the Linux kernel boot process from platform-dependent to platform-independent code, in which the Linux kernel begins to actually enter the initialization phase.
Experiment Summary:
When the computer system is power-up, the BIOS code is called to execute, and then starts to invoke the execution of the Linux kernel initialization code, after the platform-related assembly code is executed, it jumps to the Start_kernel () function and starts the real kernel initialization, where Init_task creates the No. 0 process, That is the final idle process, then the Rest_init () function creates the init process, that is, process 1th, and the Kthreadd process, the 2nd process, and the system begins to work.
Number No. 0 Process->1 Kernel process->1 number user process (init process)->getty process->shell Process
Note that the above procedure description mentions: The 1th kernel process call executes Init and becomes the 1th user-state process (the INIT process), where Init is the function and the latter is a process.
Linux kernel and analysis the boot process of the Linux kernel in the third week