2019-2020-1 20199304 "Linux kernel principle and Analysis" in the fourth week of work

Chapter III MenuOs construction

A. Antecedent Review

Computer three magic weapons:

 -存储程序计算机
 -函数调用堆栈
 -中断

The two swords operating system:

 -中断上下文的切换(保存现场和恢复现场)
 -进程上下文的切换

Two .3.1 Linux kernel source code Introduction

Linux kernel version number in accordance with A, B, C are named:

 -A代表大幅度转变的内核
 -B代表重大修改的内核
 -C指轻微修改的内核(C是内核的真实版本)
 -D是安全补丁和bug修复

Linux kernel source code root directory:

III. Analysis of the Linux kernel boot process tracking

experiment procedure

1. The following code starting the kernel program menu after finished.

cd LinuxKernel/
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img


2. gdb trace debug the kernel, adding -s (create a gdb-server on port 1234, and then open another window can be used gdb kernel symbol table with the image loaded in, and then the connection set breakpoints tracking kernel gdb srever ) and -S (CPU before he began to freeze up) two parameters.

$ qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img -s -S 

# 关于-s和-S选项的说明:
# 1. -S
#   -S freeze CPU at startup (use ’c’ to start execution)
# 2. -s
#   -s shorthand for -gdb tcp::1234 
# 若不想使用1234端口,则可以使用-gdb tcp:xxxx来取代-s选项

Kernel is frozen.

3. Open another window, start gdb, the kernel is loaded, to establish a connection.
Enter the following command in gdb

file linux-3.18.6/vmlinux 
target remote:1234
break start_kernel 
c //按c让qemu上的Linux继续运行

Experimental problem

When then open a window when starting gdb, gdb interface when loaded in the symbol table before the targe remote there is a problem: the system prompts "linux-3.18.6 / vmlinux: No such file or directory"
- Solution:
- First View students publish a blog to find a solution similar problems, such as Yang Lei new students there have been such problems, the reason is when the last step of the kernel boot QEMU window closed leads. (Checked, not the cause of such operations)
- On reflection, it was found that mistakes do not enter LinuxKernel directory, then solve the problem.

Start_kernel function analysis

asmlinkage __visible void __init start_kernel(void)
{
    char *command_line;
    char *after_dashes;
    
    /*
     * Need to run as early as possible, to initialize the
     * lockdep hash:
     */
    lockdep_init();
    set_task_stack_end_magic(&init_task);// init_task即手工创建的PCB,0号进程即最终的idle进程
    smp_setup_processor_id();
    debug_objects_early_init();
    // ...
    trap_init();                          // 中断向量的初始化
    mm_init();                            // 内存模块的初始化
    sched_init();                         // 调度模块的初始化
    // ...
    rest_init();                          // rest_init是0号进程(是使用宏初始化的),它创建1号进程init和其他的一些服务进程
}

Guess you like

Origin www.cnblogs.com/20199304lbs/p/11627863.html