Transferred from: http://blog.csdn.net/luoyhang003/article/details/47338019
Rights statement: This article for Bo Master original article, without Bo Master permission not reproduced. (Article Source: http://blog.luoyuanhang.com)
Directory (?) [-]
- Introducing GDT
- What is a GDT?
- Descriptor structure
In this article we have completed the following:
- Introducing GDT
- Introduction to segment Descriptors
- Implementation of a segment descriptor
What is the introduction of GDTGDT?
The GDT (Global descriptor Table) is a data structure used to provide a segment storage mechanism, which is provided together with a segment register and a descriptor in the GDT.
In the protection mode, although the register now has 32 bits, but we still use "segment: Offset" in the form of addressing, but the concept of "paragraph" is equivalent to the GDT, the segment value is still 16-bit CS, DS and other registers are represented, but this period value is only equivalent to an index, point to a data structure, This data structure is a GDT table item, which defines the starting address, bounds, attributes, and so on of the segment, which is also called the Descriptor (descriptor)
Descriptor structure
Code Snippets and data segment descriptors
A segment descriptor is a 8-byte structure that contains information such as segment base, Segment bounds, segment properties, and so on
- Segment Base (32-bit): Represents the Physical address
- Segment Bounds (20 bits): Indicates the length of the segment (not the address, but the byte length)
- Segment Properties (12 bits): System, gate, data, etc. properties
Let's implement this structure:
; a descriptor;3 parameters:;1. Segment Base:32-bit (4 bytes);2. Segment Boundary: Low20 bits;3. Properties:12-bit (low in high-byte4-bit always0)%macro Descriptor3. Define macro descriptor, there are3 parameter DW%2 & 0FFFFh, with parameters2 of Low16-bit populate a word DW%1 & 0FFFFh, with parameters1 of Low 16 bit fills a word db (%1 >> 16) & 0FFh; 1 17- 25 bits populate a byte DW ( (%2 >> 8) & 0f00h) | (%3 & 0F0FFH); 2 with parameters 17- 21 bits and parameters 3 13- 16-bit populated with a word DW (%1 >> 24) & 0FFh; 1" with parameters 32-bit fills a word%endmacro
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
From the code we can parse the valid bits of each parameter: (f is valid)
Let's describe the role of each person:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Article Source: http://blog.luoyuanhang.com
Very good!!! "Write OS series from scratch" Implements a-GDT (1) "Go"