Three kinds of models for memory addressing

Source: Internet
Author: User
 1. Type of address

First, define the two concepts of logical address and linear address:

1. Logical Address

2. Linear address

3. Physical Address 1.1 logical address:

The logical address is compiler generated, we use in Linux environment, when using the C language pointer, the value of the pointer is the logical address. For each process, they all have the same process address space, similar logical addresses, and possibly even the same. 1.2 Linear Address:

The linear address is the transformation of the logical address by the piecewise mechanism, and if there is no piecewise mechanism, then the logical address of the program is the linear address. 1.3 Physical Address

The physical address is the level signal which the CPU sends on the address bus select、read, to obtain the physical address, must have the logical address to pass through the subsection, the paging and so on the mechanism transforms. 2. Three addressing models

There are three main memory addressing models used in the x86 architecture:

1. Real mode flat model flat

2. Real mode segmented model segment

3. Protection mode flat model protected mode flat models

Here is a description of the three models

Real mode vs. protected mode, real mode runs on 20-bit address bus, protection mode enabled the 32-bit address bus, the address is using a virtual address, introduced a descriptive chart; Although both have introduced a paragraph such a concept, but the real mode of the segment is 64KB fixed size, only 16KB a different segment, CS, DS, and so on, stores the sequence number of segments ( think why .) )。 The protection mode introduces the data structure of the GDT and LDT segment descriptors to define each segment.

The flat model and the segmented model are relative, the difference is whether the program's linear address is to share an address space or to be divided into segments, that is, for multiple programs running in the same cs,ds or each program has its own cs,ds: the former (flat) instruction's logical address to form a linear address, Do not need to switch cs,ds, the latter's logical address, must go through the segment selector to find the segment descriptor, switching cs,ds to form a linear address. 3. Real-mode flat model

This mode only appears in processors 386 and higher.

80386 real mode, that is, the CPU available address line only 20 bits, can address the 0~1MB. Note : The real mode of 80386 is not equal to the real mode of 8086/8088, the real mode of the latter is actually the piecewise model of real mode.

The flat model means that we don't use any segment registers here. (In fact, still use the cs,ds, just do not need to show the programmer to the register to assign value, JMP instructions when the CS, DS set up)

Linux boot code arch/i386/boot/bootsect. S is working in this mode.

Logical address----> Physical Address

4. Real-mode segmentation model

For 8086/8088 of programs running in real mode, it is actually running in the real-mode segmented model. For different programs, there are different cs,ds values, and each program has a different starting address for the segment. For such a program, the 16-bit attribute of the offset address determines that each segment is only 64KB in size.

Detailed procedures can be described in the following diagram: The figure is from http://duartes.org/gustavo/blog/

5. Protection Mode Flat Model

Our Linux, Window XP/7 using the memory addressing model, Linux, segments are divided into 4 types, that is, the kernel code segment, kernel data segments, user code snippets, user data segments.

For kernel code snippets and data segments, the value of the Cs,ds is 0xc00000000, and the Cs,ds value of the user code and data segment is 0x00000000

When the CPU is running in 32-bit mode, both registers and instructions can address the entire line of addresses, so there is no need to use the base address at all. The base address can be set to a uniform value.

The following is an example of a graph from the http://duartes.org/gustavo/blog/

The flat model is well represented here, and this user-space program base address is 0. In fact, all the user-space programs whose GDT point to the base address are 0.

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.