Data iiiflwjif Dtwripict

& «1 60 59 5S 5? 5<S 55 54 51 52 5! 47 46 15 4J 43 42 41 40 39 U 5/ 36 E 54 33 12

BJUEI24-31)

G

B

0

1

HUT (16-19)

1

P 1

1

TVPE

BA5E(1M3i

BA5ÉÎD-15J

LiMTß-15)

il 3D J1) M Li JS Zi J-1 ij Li Jll M IV 14 1J là 1: II 13 U 11 10 'J a J h i 4 3 ï 1 0

il 3D J1) M Li JS Zi J-1 ij Li Jll M IV 14 1J là 1: II 13 U 11 10 'J a J h i 4 3 ï 1 0

foft ¡¡iiflWJIf JÎP HlVififlr

& il 60 59 5S 5- 50 55 54 51 52 51 50 4* 44 JT 46 45 4J 4] 42 41 40 39 18 Î7 36 E 54 33 12

BJUEI24-31)

G

D

0

V 1

UMIT (16-19)

1

P 1

S 1

TVPE

BASE (16-¿Î}

BASEiD-15}

UMTß-15)

il 3D J1) 2S Li JS ¿L. J-1 ii LL Jll M Vi 14 1/ 16 1: M Ii U 11 10 'J a / 6 i fl 3 il 0

il 3D J1) 2S Li JS ¿L. J-1 ii LL Jll M Vi 14 1/ 16 1: M Ii U 11 10 'J a / 6 i fl 3 il 0

fytm i e^mwif Qfw^fw

61 & il 60 59 5S 5- 56 55 54 51 52 51 50 44 JT 46 V 4J 4] 42 41 40 39 16 57 36 E 54 15 12

BJUEI24-31)

G

0

(16-19)

1

P 1

D

TYPE

ËAÎÉÎD-15J

LIMIT 15)

il 3D J1) ÏS Jï JS Zi J-1 ii JJ Jll M IV 14 i; 16 1: II 1J U 11 10 'J a / 6 i i 3 il 0

il 3D J1) ÏS Jï JS Zi J-1 ii JJ Jll M IV 14 i; 16 1: II 1J U 11 10 'J a / 6 i i 3 il 0

Usually only one GDT is defined, while each process is permitted to have its own LDT if it needs to create additional segments besides those stored in the GDT. The address of the GDT in main memory is contained in the gdtr processor register and the address of the currently used LDT is contained in the ldtr processor register.

Each Segment Descriptor consists of the following fields:

• A 32-bit Base field that contains the linear address of the first byte of the segment.

• A G granularity flag. If it is cleared (equal to 0), the segment size is expressed in bytes; otherwise, it is expressed in multiples of 4096 bytes.

• A 20-bit Limit field that denotes the segment length in bytes (segments that have a Limit field equal to zero are considered null). When G is set to 0, the size of a nonnull segment may vary between 1 byte and 1 MB; otherwise, it may vary between 4 KB and 4 GB.

• An s system flag. If it is cleared, the segment is a system segment that stores kernel data structures; otherwise, it is a normal code or data segment.

• A 4-bit Type field that characterizes the segment type and its access rights. The following list shows Segment Descriptor types that are widely used.

Code Segment Descriptor

Indicates that the Segment Descriptor refers to a code segment; it may be included either in the GDT or in the LDT. The descriptor has the S flag set.

Data Segment Descriptor

Indicates that the Segment Descriptor refers to a data segment; it may be included either in the GDT or in the LDT. The descriptor has the S flag set. Stack segments are implemented by means of generic data segments.

Task State Segment Descriptor (TSSD)

Indicates that the Segment Descriptor refers to a Task State Segment (TSS) — that is, a segment used to save the contents of the processor registers (see Section 3.3.2); it can appear only in the GDT. The corresponding Type field has the value 11 or 9, depending on whether the corresponding process is currently executing on a CPU. The S flag of such descriptors is set to 0.

Local Descriptor Table Descriptor (LDTD)

Indicates that the Segment Descriptor refers to a segment containing an LDT; it can appear only in the GDT. The corresponding Type field has the value 2. The S flag of such descriptors is set to 0. The next section shows how 80 x 86 processors are able to decide whether a segment descriptor is stored in the GDT or in the LDT of the process.

• A dpl (Descriptor Privilege Level ) 2-bit field used to restrict accesses to the segment. It represents the minimal CPU privilege level requested for accessing the segment. Therefore, a segment with its dpl set to 0 is accessible only when the cpl is 0 — that is, in Kernel Mode — while a segment with its dpl set to 3 is accessible with every cpl value.

• A Segment-Present flag that is equal to 0 if the segment is currently not stored in main memory. Linux always sets this field to 1, since it never swaps out whole segments to disk.

• An additional flag called d or b depending on whether the segment contains code or data. Its meaning is slightly different in the two cases, but it is basically set (equal to 1) if the addresses used as segment offsets are 32 bits long and it is cleared if they are 16 bits long (see the Intel manual for further details).

• An avl flag that may be used by the operating system but is ignored in Linux. 2.2.3 Fast Access to Segment Descriptors

We recall that logical addresses consist of a 16-bit Segment Selector and a 32-bit Offset, and that segmentation registers store only the Segment Selector.

To speed up the translation of logical addresses into linear addresses, the 80 x 86 processor provides an additional nonprogrammable register—that is, a register that cannot be set by a programmer—for each of the six programmable segmentation registers. Each nonprogrammable register contains the 8-byte Segment Descriptor (described in the previous section) specified by the Segment Selector contained in the corresponding segmentation register. Every time a Segment Selector is loaded in a segmentation register, the corresponding Segment Descriptor is loaded from memory into the matching nonprogrammable CPU register. From then on, translations of logical addresses referring to that segment can be performed without accessing the GDT or LDT stored in main memory; the processor can just refer directly to the CPU register containing the Segment Descriptor. Accesses to the GDT or LDT are necessary only when the contents of the segmentation register change (see Figure 2-3). Each Segment Selector includes the following fields:

• A 13-bit index (described further in the text following this list) that identifies the corresponding Segment Descriptor entry contained in the GDT or in the LDT

• A ti (Table Indicator) flag that specifies whether the Segment Descriptor is included in the GDT (ti = 0) or in the LDT (ti = 1)

• An rpl (Requestor Privilege Level ) 2-bit field, which is precisely the Current Privilege Level of the CPU when the corresponding Segment Selector is loaded into the cs register^1!

Was this article helpful?

0 0

Post a comment