Hardware Reference
In-Depth Information
Bits
13
1 2
INDEX
0 = GDT
1 = LDT
Privilege level (0-3)
Figure 6-12. A Core i7 selector.
for segments. The other 2 bits relate to protection and will be described later. De-
scriptor 0 is invalid and causes a trap if used. It may be safely loaded into a seg-
ment register to indicate that the segment register is not currently available, but it
causes a trap if used.
At the time a selector is loaded into a segment register, the corresponding de-
scriptor is fetched from the LDT or GDT and stored in internal MMU registers, so
it can be accessed quickly. A descriptor consists of 8 bytes, including the seg-
ment's base address, size, and other information, as depicted in Fig. 6-13.
Relative
address
0
4
32 Bits
BASE 0-15
LIMIT 0-15
BASE 24-31 G D 0
LIMIT 16-19 P DPL
TYPE
BASE 16-23
Segment type and protection
Privilege level (0-3)
0 : Segment is absent from memory
1 : Segment is present in memory
0 : LIMIT is in bytes
1 : LIMIT is in pages
0 : 16-bit segment
1 : 32-bit segment
Figure 6-13. A Core i7 code segment descriptor. Data segments differ slightly.
The format of the selector has been cleverly chosen to make locating the de-
scriptor easy. First either the LDT or GDT is selected, based on selector bit 2.
Then the selector is copied to an MMU scratch register, and the 3 low-order bits
are set to 0, effectively multiplying the 13-bit selector number by eight. Finally,
the address of either the LDT or GDT table (kept in internal MMU registers) is
added to it, to give a direct pointer to the descriptor. For example, selector 72
refers to entry 9 in the GDT, which is located at address GDT + 72.
Let us trace the steps by which a (selector, offset) pair is converted to a physi-
cal address. As soon as the hardware knows which segment register is being used,
it can find the complete descriptor corresponding to that selector in its internal reg-
isters. If the segment does not exist (selector 0) or is currently not in memory ( P is
0), a trap occurs. The former case is a programming error; the latter case requires
the operating system to go get it.
Search WWH ::




Custom Search