Wei Hao--the third week of Linux kernel Analysis job: Linux system Boot process

Source: Internet
Author: User

Wei Hao--the third week of Linux kernel Analysis job: Linux system Boot process

First, the experimental part

Experimental guidance

    • Open the shell with a virtual machine in the lab building

1 cd linuxkernel/2 qemu-kernel linux-3.18. 6/arch/x86/boot/bzimage-initrd rootfs.img

After the kernel boot is completed into the menu program ("Software Engineering C Coding Practice" course project), support three commands help, version and quit, you can also add more commands, for elective "Software Engineering C Coding practice" of children's shoes should be a piece of cake.

    • Debug kernel with GDB trace

1 qemu-kernel linux-3.18. 6/arch/x86/boot/bzimage-initrd rootfs.img-s S # Description of the-s and-s options:2 #-s freeze CPU at Startu P (use ' C '-start execution)3 for-gdb tcp::1234 If you do not want to use 1234 ports, you can replace the-s option with-gdb tcp:xxxx

    • Open another Shell window

1 gdb 2 (gdb) file linux-3.18. 6/vmlinux # before Targe remote in GDB interface load symbol table 3 (GDB) target remote:1234  # To establish a connection between GDB and Gdbserver, press C to allow the Linux on QEMU to continue running 4 (gdb)  break Start_kernel # Breakpoint settings can be set at Target Before remote, you can also

Experiment:

Second, analyze the execution process of start_kernel function

Starting with the Start_kernel function, the kernel enters the C language section, which completes most of the initialization of the kernel, similar to the main function in the general executable program, Main.

Main function Analysis:

1.set_task_stack_end_magic (&init_task)

Init_task is a global variable, equivalent to the PCB of process No. 0 in Mykernel.

2.trap_init ()

Initialize the interrupt vector, set a lot of interrupt gate, hardware interrupt. where Set_system_trap_gate (syscall_vector) handles system calls, triggering an interrupt in the form of an instruction.

3.sched_init ()

Initialization of the Dispatch module

4.rest_init () Kernel_thread (Kernel_init,...) kernel_init->run_init_process

1th process in Linux, the first user-state process, the default process under the root directory

Rest_init ()kernel_thread (kthreadd,...)

Use a kernel thread to manage some of the system's resources

5..rest_init ()->cpu_startup_entry ()->cpu_idle_loop ()

Always loop, when the system no process needs to execute the time to dispatch the idle process, from the start of the kernel has been in existence, process No. 0. Process Number No. 0 creates a process number 1th and also creates some other service threads in the kernel.

Iii. Summary

This week we learned about the Linux kernel startup process and analyzed some of the key functions that need to be mastered. The process of booting the Linux kernel is to prepare for the process and process scheduling, and all the code before the Rest_init () function is initialized for the process, until Rest_init () occurs and the process is present. Since then, process No. 0 has been in existence, resulting in processes such as process 1th and so on, when the system does not need to execute the process to dispatch the idle process.

Wei Hao The original works reprint please indicate the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

Wei Hao--the third week of Linux kernel Analysis job: Linux system Boot process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.