Linux Kernel Learning Summary
He Bong
Original works reproduced please indicate the source
"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
One, the blog work directory.
1. Start with the assembly code of the C simple program to understand how the computer works.
Http://www.cnblogs.com/L1nke/p/5218790.html
2. LINUX Kernel Analysis: Complete a simple time slice rotation multi-channel program kernel code.
Http://www.cnblogs.com/L1nke/p/5247152.html
3. linux Kernel analysis Experiment Three: Trace analysis of the Linux kernel boot process.
Http://www.cnblogs.com/L1nke/p/5270262.html
4. Experiment Four: use the same system call using the Library function API and the C code to embed the assembly code in two ways.
Http://www.cnblogs.com/L1nke/p/5297663.html
5. Experiment Five: Analyze the System_call interrupt processing process. (PS. submit the job when the connection submitted wrong .... so that the points are very low)
Http://www.cnblogs.com/L1nke/p/5323966.html
6. Analyze The process of creating a new process for the Linux kernel.
Http://www.cnblogs.com/L1nke/p/5347984.html
7. How the LINUX kernel loads and launches an executable program.
Http://www.cnblogs.com/L1nke/p/5374617.html
8. Understand the process of process scheduling and process switching during time tracking analysis process scheduling.
Http://www.cnblogs.com/L1nke/p/5401757.html
Second, learning experience.
1. Graphical analysis of assembly code to understand how a computer works
Von Neumann architecture of the computer, also known as the storage program computer, from the hardware point of view, its working model is that the CPU reads in-memory instructions in turn to complete the work. The core idea is that the system is binary, and the computer should be executed in the order of the program.
Five addressing modes for assembly languages:1. Register Addressing Registermode 2. Immediate Addressing Immediate 3. Direct Addressing Direct 4. Indirect addressing Indirect 5. variable address addressing displaced
2. Analysis of kernel code of a simple time-slice rotation multi-channel program based on Mykernel
Mykernel is a kernel platform built by the teacher to open your own operating system, based on the Linux Kernel 3.9.4 source code. Through this talk of learning and experimentation, we know that the core function of the operating system is: process scheduling and interrupt mechanism, through the cooperation with the hardware to achieve multi-tasking, coupled with the support of the upper application software, and eventually become a computer system that can make it easy for users to operate.
3. using GDB to track the Linux kernel boot process
Start_kernel () is the interface between the Assembly of the kernel and the C language, before which the kernel code is written in sinks, completing some of the most basic initialization and environment setup work. Start_kernel is like the main function in C code. Regardless of your focus on Linux kernel modules, you can always leave the Start_kernel function, because most of the initialization work of the module is done in Start_kernel. Following the experimental steps in this lesson, we can track the boot process of the Linux kernel.
4. Use the same system call using the library function API and The embed assembly code in C code two ways
Even the simplest programs will inevitably use operations such as input, output, and exit, while doing so requires invoking the service provided by the operating system, which is called the system. Unless your program only completes mathematical operations such as subtraction, it is difficult to avoid using system calls. There are two ways to make a system call under the Linux platform: by using the encapsulated C Library (LIBC) or by assembly-direct invocation. This article starts with an example, describes the concept of system invocation, and how to use system calls.
5. Analyze the process of System_call interruption
Through GDB we can call the system kernel in the program such as Sys_write, Sys_time set breakpoints, and let the program stop at the breakpoint, the breakpoint tracking system call in the process. Since System_call is a function that is written entirely in sinks, although we can also set breakpoints at System_call, we cannot stop the system at System_call, so we cannot learn the process in a single-step tracking. However, System_call is the entry of all system calls and a function that cannot be crossed when the program is transferred from the user state to the kernel state, so we follow the teacher's simplified assembly code and the source code to learn its main process.
6. The description of the beginner Linux process and the creation of the process
To manage the process, the kernel must have a clear description of each process, and the process descriptor provides the process information that the kernel needs to understand. Process descriptor task_struct Source Link: http://codelab.shiyanlou.com/xref/linux-3.18.6/include/linux/sched.h#1235. In the development of Linux applications, a sub-process can be created through APIs such as fork, Vfork, and clone, and their corresponding system calls in the Linux kernel are sys_fork, sys_vfork, and Sys_clone functions, respectively. These functions will eventually call Do_fork to complete the creation of the child process. Do_fork primarily replicates the task_struct of the parent process, and then modifies the necessary information to get the task_struct of the child process.
7. Learn how the Linux kernel loads and starts an executable program
The Linux system can start a new process via the Execve API, which also calls the SYS_EXECVE system call, is responsible for replacing the new program code and data into the new process, opening the executable file, loading the dependent library file, requesting a new memory space, and finally executing the Start_ Thread (regs, Elf_entry, bprm->p), set NEW_IP, NEW_SP, complete the new process of code and data substitution, and then return, followed by the execution of the new process code.
8. Beginner linux process scheduling and process switching process
The general implementation of the Linux system, the most common situation is: The running user-state process x switch to run the user-state process y process to go through the following steps
1). Running user-state process X
2). Interrupt occurred: Save Cs:eip/esp/eflags (current) to kernel stack, then load CS:EIP (entry of a specific ISR) and Ss:esp (Point to Ke Rnel stack).
3). Save_all//Save site, here is the process that has entered the kernel interrupt
4). Schedule () was called during interrupt processing or before the interrupt was returned, where Switch_to made a critical process context switch
5). After the label 1 begins to run the user-state process y (where Y has been switched out through the above steps so it can continue from label 1)
6). Restore_all//Recovery site
7). Iret-pop Cs:eip/ss:esp/eflags from kernel stack
8). Continue to run user-state process y
Third, harvest and sentiment.
Eight weeks of study, fleeting, Meng teacher for us in the Linux Learning Path opened a window, very grateful to the teacher's hard pay. Eight weeks of study, but also just a few, in the future I will continue to learn Linux.
The first few weeks of the content is still very easy, but the process switch is very difficult to understand, but also need to learn.
Linux Kernel Learning summary