Performed by the real-mode 32-bit addressing mode into protected

Because the cpu in real mode address bus 20, the memory access to about 1M, more memory in order to operate, manufacturers design cpu protected mode, in this mode, up to 32-bit address bus, access memory significantly increased.

Protective mode to operate something called gdt use a 32-bit addressing, this gdt (Global Descriptor Table) called the Global Descriptor Table. My understanding of it is that it is like a directory, each kept the size of the head address of a segment in memory and this segment.

This segment will be understood to select a small piece in memory, give it a name, then he is a segment of memory.

This figure better described below

Of course, within the scope of gdt in memory location will certainly be accessible in real mode.

When you want to access a larger address to access a segment on the first entry in the segment access gdt, and then get his actual physical addresses, 32-bit bus access it start protection mode.

move ax [0x5a1]

Let's say you want the real mode memory read data 0x5a1 location ax register it with the top assembly statement on the line, of course, first base address register is set to 0.

 

If you want to access a memory location, then the data 5M in this way will not work, this time to use the following code

[SECTION .gdt]
 ;                                  段基址          段界限                属性
LABEL_GDT:          Descriptor        0,            0,                   0  
LABEL_DESC_CODE32:  Descriptor        0,      SegCode32Len - 1,       DA_C + DA_32
LABEL_DESC_VIDEO:   Descriptor     0B8000h,         0ffffh,           DA_DRW
LABEL_DESC_5M:      Descriptor     0500000h,        0ffffh,           DA_DRW

GdtLen     equ    $ - LABEL_GDT
GdtPtr     dw     GdtLen - 1
           dd     0

SelectorCode32    equ   LABEL_DESC_CODE32 -  LABEL_GDT
SelectorVideo     equ   LABEL_DESC_VIDEO  -  LABEL_GDT
Selector5M        equ   LABEL_DESC_5M - LABEL_GDT
mov   bx, Selector5M    ;用 es 指向5M内存描述符
mov   es, bx
mov   edi, 0
mov   ax, [es:edi]

The first block of code is written for a gdt, in this table to the segment memory 5M position of a name called LABEL_DESC_5M, size 0ffffh. I also wrote a number of other segments, we should not care.

The second is the use of the code block, which corresponds LABEL_DESC_5M Selector5M gdt this table in this section are few, there is the fourth. Es to pass it through the register bx register. This register is specifically es come to the middle of the table entries gdt. edi Lane 5M offset values ​​are relative to this position, then this position if the access 5M edi set to 0, and if a zero byte then 5M access edi to set 1, and so, of course, can not exceed the maximum segment range. Then last sentence is the position of the write data 5M ax them.

Consider, if the method of using real-mode memory access 5M then that mov ax [0x500000], of course, this is not run, registers and bus do not support.

mov ax, [es: edi] This sentence can be viewed as mov ax [0x500000 + 0], he has been able to run because of this [es: edi] triggered a protection mode, should be addressing on es then will start gdt protection mode read access larger amounts of memory, this implementation is a hardware implementation.

Summarized in the following chart

Published 24 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_42794321/article/details/104904047