3.4 Protected Mode
64-bit Segrnent Descriptor
Bit 31 24 23 22 21 20 19 16 15 14 13 12 11 8 7 Bit 0
Base 31:24
G
D/B
L
AVL
Limit 19:16
P
DPL
S
Type
Base 23:16
Bit 31
16
15
BitO
Base Address, bits 15:00
Segment Limit, bits 15:00
Segment Limit (20-bits) Segment size (if G = 0; I byte - 1 MB, if G = 1:4 KB to 4 GB)
Base Address (32-bits) Base linear address used to form the final linear address
Type Field Type of segment (code or data), access, and growth direction
S Flag If S is dear, system segment. If S is set, application segment
DPL Descriptor privilege level (00 = Ring 0, 11 = Ring 3)
P Flag If P is set, segment is resident in memory
AVL No explicit purpose, available for use by operating system
L Flag IA-32 processors set this bit to zero (indicates 64-bit code)
D/B Meaning varies according to segment type (code, data, or stack)
G Flag See description of segment limit field
Figure 3.12
The type field and the Sflag are used together to determine what sort of
descriptor we're dealing with. As it turns out, there are several different types
of segment descriptors because there are different types of memory segments.
Specifically, the S flag defines two classes of segment descriptors:
■ Code and data segment descriptors (S = 1).
■ System segment descriptors (S = 0).
Code and data segment descriptors are used to refer to pedestrian, everyday
application segments. System segment descriptors are used to jump to seg¬
ments whose privilege level is greater than that of the current executing task
(currentprivilege level, or CPL). For example, when a user application in¬
vokes a system call implemented in Ring 0, a system segment descriptor must
be used. We'll meet system segment descriptors later on when we discuss
gate descriptors.
For our purposes, there are really three fields that we're interested in: the base
address field, the DPL field, and the limit field (take a look at Figure 3.10
again). I've included all of the other stuff to help reinforce the idea that the
descriptor is a compound data structure. At first glance this may seem compli¬
cated, but it's really not that bad. In fact, it's fairly straightforward once you
get a grasp of the basic mechanics. The Windows driver stack, which we'll
meet later on in the book, dwarfs Intel's memory management scheme in
terms of sheer scope and complexity (people make their living writing kernel-
mode drivers, and when you're done with this book you'll understand why).
Parti I 93