Basic preparations for learning Linux kernel source code with cainiao

Source: Internet
Author: User

Note: Most of the content below is taken from the Linux kernel programming entry and the Linux kernel complete annotation.

 

During this period of work, I found that I was familiar with the painting of Visio. I always liked to understand the source code, structure, and so on as a flowchart, because for the diagram, there is a very intuitive understanding, so the next step is to take the image as the center.

 

Linux kernel architecture

Speaking of operating systems, we will all know Windows OS, Linux OS, Apple's iOS OS, the former Popular Saipan operating system, and the Android operating system that has recently become popular in consumer electronics. A complete operating system is divided into four parts.


We can understand this as our mobile phone. The hardware system is the entire cell phone we see, CPU, memory, which we can't see without being split, or touch screen or buttons. The operating system kernel is what we call Android, but it includes the Linux kernel. The operating system service is a set of Android structures, which gives us an intuitive interface. We can click to implement the desired function. User applications are commonly used QQ, navigation, and of course a variety of interesting games, Angry Birds, graffiti, and fruit ninja. Do you want to play? Alas, I 'd better study it, although the phone is next to it.

For Linux kernel systems in single kernel mode, it can be divided into the following:


The Linux kernel can be divided into five modules.

The relationships and main functions can be found:



About Linux memory

The physical memory can be divided:

The kernel occupies the first part of the memory. The next part is the shared hard disk, the high-speed buffer used by the floppy disk, which deducts the Display memory and bios 640k to 1 m, and then the virtual disk; the last part is the main memory zone that can be used by all programs.


In Linux memory management, segment conversion: converts a logical address consisting of segment delimiters and intra-segment offsets into a linear address. Page Transformation: converts a linear address to a corresponding physical address. As shown in the following figure:


Virtual Address: it refers to the address generated by the program, which consists of the segment selection character and the offset address in the segment. Why is it a virtual address? Because the addresses composed of these two parts do not directly access the physical memory, they need to be processed or mapped through the address translation mechanism to correspond to the corresponding physical memory address.

Segment descriptor: Provides the CPU with the information necessary to map logical addresses into linear addresses. Descriptors are created by the program compiler, linker, loader, or operating system.

Descriptor Table: stores the descriptor in the descriptor table. There are two types:

1. Global Descriptor Table --- gdt)

2. Local Descriptor Table --- LDT)

A Descriptor Table is an array in the memory of an 8-byte descriptor. The processor uses gdt and ldtr registers to locate the gdt table and the current LDT table. A maximum of 8192 (2 ^ 13) descriptors can be contained.

Selector: The selection part of the logical address. It is used to specify a descriptor. It is completed by specifying a descriptor table and indexing one of the descriptor items.

Segment register: The processor saves the information in the descriptor in the segment register, thus avoiding querying the descriptor table every time the memory is accessed.

 

 

 

Linear address: by specifying a page table, a page in the page table, and the Offset Value in the page, it indirectly points to the corresponding physical address.

Page table: A simple array of 32-bit page indicators. The page table itself is also a one-page memory, so it contains 4 K bytes of memory and can accommodate 1 K 32-bit items.

 

Offset = 2 ^ 12 = 4 K, table = 2 ^ 10, directory = 2 ^ 10, so the linear address space is 2 ^ 10*2 ^ 10*4 k = 4G.

Since the 0.11 kernel defines the maximum available virtual memory space of each process as 64 MB, the logical address of each process can be set to * 64 m with the task number, it can be converted to linear space addresses.

 

 

About Linux Processes

Processes can run in the kernel or user mode. when resources are available, the system is awakened and enters the ready state. When a process is in a sleep state that can be interrupted, the system can wake up upon receiving a signal; when the sleep state is not interrupted, it can only be awakened using wakeup or other functions. when the process is paused, a signal can be sent to make it ready. When the process is frozen, when it has stopped running, the parent process has not called the wait query status. Once the parent process calls wait to obtain the sub-process information, the data structure of the process task will be released.

 

 


Linux File System and source code directory

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 





About Linux kernel makefile

The Linux MAKEFILE file is a parameter configuration file used to compile the make software of the auxiliary tool. The main purpose of the make tool software is to identify which files have been modified, so as to automatically determine which files need to be re-compiled in a program system that contains multiple source program files.


Here, makefile is mainly used to instruct the make program to use the build executable program in the tools/directory connected by independent compilation to connect all the kernel compilation code and combine it into a runable kernel image file.. Specifically, bootsect. s and setup. s in the boot/directory are compiled using the 8086 assembler to generate their respective execution modules. Compile all other programs in the source code using the GNU Compiler gcc/gas and connect them to the module system. Use the build tool to combine these three parts into a kernel image file.

 

 

 

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.