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;3A parameter:;1. Segment Base: +-bit4bytes);2. segment Boundary: Low --bit3Properties ABits (Low in high-byte4Bit is always0)%macroDescriptor3; Define macro descriptor, there are3A parameter DW%2& 0FFFFh, with parameters2The Low -Bit fills a word DW%1& 0FFFFh, with parameters1The Low -Bit fills a word db (%1>> -) & 0FFh, with parameters1Of -- -Bit fills a byte DW (%2>>8) & 0f00h) | (%3& 0f0ffh), with parameters2Of -- +Bits and parameters3Of1-8Bits and -- -Bit fills a word dw (%1>> -) & 0FFh, with parameters1Of -- +Bit fills a word%endmacro
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
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. (Article Source: http://blog.luoyuanhang.com)
"Write the operating system family from scratch" Implementing a-GDT (1)