Deep understanding of Linux kernel reading notes-Chapter 2-memory addressing (1)

Source: Internet
Author: User
Memory Address: logical address: the address used to specify an operand or an instruction in the machine language instruction. Linear Address: a 32-bit unsigned integer, also known as a virtual address. Physical Address: used for addressing memory chip-level memory units, and sending the address pins from the microprocessor to the memory bus... Info & nb memory address:
 
Logical address: the address that is included in the machine language instruction to specify an operand or an instruction.
 
Linear Address: a 32-bit unsigned integer, also known as a virtual address.
 
Physical Address: used for addressing memory chip-level memory units, which correspond to electrical signals sent from the address pins of the microprocessor to the memory bus.
 
In a multi-processor system, all CPUs share the same memory, which means that the RAM chip can be accessed concurrently by an independent CPU. Since read or write operations on the RAM chip must be performed in serial mode,
Therefore, the hardware circuit of a memory arbitration device is inserted between the bus and each RAM chip. its function is to allow a CPU access if a RAM chip is idle.
The request service from another processor delays access to the CPU.
 
Even on a single processor, the memory arbitration is used. The single-processor system contains a special processor called the DMA controller, and the DMA controller and CPU are operated concurrently.
 
 
Segment in hardware:
 
A logical address consists of a 16-bit segment identifier (or segment selector, as shown below) and a 32-bit intra-segment offset.
 
The segment selector contains 13-bit index numbers, 1-bit TI table indicators, and 2-bit RPL requestor privilege levels.
 
Each segment is represented by an 8-byte segment descriptor, which is stored in the global descriptor table (GDT) or local descriptor table (LDT. Generally, only one GDT is defined, and each process has
Have your own LDT.
 
The first item of GDT is always set to 0, which ensures that the logical address of the null segment separator is considered invalid and can cause a processor exception. Therefore, the maximum number of descriptors in GDT is 213-1.
For example, if the GDT value is 0x0020000 (this value is stored in the gdtr register ), and the index number specified by the segment selector is 2 (that is, the 13-bit value of the segment selector is 2), because the first entry of GDT is 0,
The segment descriptor address specified by the segment identifier is 0x0020000 + 2*8 or 0x0020010.
 
The logical address is converted to the corresponding linear address. the segment unit first checks the TI field of the segment selection operator to determine the storage location of the segment descriptor (GDT or LDT). if it is GDT, the segment unit starts from the gdtr register.
To obtain the linear base address of GDT. if it is an active LDT, the segment unit obtains the linear base address of LDT from the ldtr register. then, the segment descriptor address of the index field is selected from the segment, set
This address is added to the offset field value in the logical address to obtain the linear address.
 
Segment in Linux:
 
Segments can allocate different linear address spaces to each process, while paging can map the same linear address space to different physical spaces. Compared with segments, Linux prefers paging,
This is because memory management becomes easier when all processes use the same segment register value. one of the Linux design goals is to be transplanted to most processor platforms, while
Limited support.
 
Linux mainly uses four segments: user segments, user segments, kernel segments, and kernel data segments. The corresponding segment selection characters include macro _ USER_CS, _ USER_DS, _ KERNEL_CS,
_ KERNEL_DS is defined. the kernel only needs to load the value generated by the corresponding macro into the cs segment register to address the corresponding segment.
 
When a pointer pointing to a command or data structure is saved, the kernel does not need to set a segment selection character for the logical address, because the cs register contains the current segment selection character.
 
For example, when the kernel calls a function, it executes a call assembly language instruction. this instruction only specifies the offset of the logical address, and the segment selection operator is not set, because "execution in kernel state"
Only kernel code segments are defined by _ KERNEL_CS.
 
In a single processor system, there is only one GDT, while in a multi-processor system, each CPU corresponds to one GDT.
 
In Linux, each GDT contains 18 segment descriptors pointing to the following segments:
L There are 4 segments and data segments in the user and kernel states;
L task status segment. each processor has one;
L 1 segment containing the default local descriptor table, which is usually shared by all processes;
L three local Thread storage (TLS) segments;
L three segments related to advanced battery management;
L five segments related to BIOS service programs supporting the plug-and-play function;
L a special TSS segment used by the kernel to handle "double errors" exceptions;
Note: when processing an exception, another exception may be thrown, which may cause a double error.
 
Linux programs in most user mode do not use LDT, so the kernel defines a default LDT for most processes to share.

Author: Crazy Bird

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.