background image

3-12 Vol. 3A

PROTECTED-MODE MEMORY MANAGEMENT

offset against the segment limit. For example, when the granularity flag is set, a limit of 0 results in 
valid offsets from 0 to 4095.

L (64-bit code segment) flag

In IA-32e mode, bit 21 of the second doubleword of the segment descriptor indicates whether a 
code segment contains native 64-bit code. A value of 1 indicates instructions in this code segment 
are executed in 64-bit mode. A value of 0 indicates the instructions in this code segment are 
executed in compatibility mode. If L-bit is set, then D-bit must be cleared. When not in IA-32e mode 
or for non-code segments, bit 21 is reserved and should always be set to 0.

Available and reserved bits

Bit 20 of the second doubleword of the segment descriptor is available for use by system software.

3.4.5.1  

Code- and Data-Segment Descriptor Types

When the S (descriptor type) flag in a segment descriptor is set, the descriptor is for either a code or a data 
segment. The highest order bit of the type field (bit 11 of the second double word of the segment descriptor) then 
determines whether the descriptor is for a data segment (clear) or a code segment (set). 
For data segments, the three low-order bits of the type field (bits 8, 9, and 10) are interpreted as accessed (A), 
write-enable (W), and expansion-direction (E). See Table 3-1 for a description of the encoding of the bits in the 
type field for code and data segments. Data segments can be read-only or read/write segments, depending on the 
setting of the write-enable bit. 

Stack segments are data segments which must be read/write segments. Loading the SS register with a segment 
selector for a nonwritable data segment generates a general-protection exception (#GP). If the size of a stack 
segment needs to be changed dynamically, the stack segment can be an expand-down data segment (expansion-
direction flag set). Here, dynamically changing the segment limit causes stack space to be added to the bottom of 

Table 3-1.  Code- and Data-Segment Types 

Type Field

Descriptor

Type

Description

Decimal

11

10

E

9

W

8

A

0

0

0

0

0

Data

Read-Only

1

0

0

0

1

Data

Read-Only, accessed

2

0

0

1

0

Data

Read/Write

3

0

0

1

1

Data

Read/Write, accessed

4

0

1

0

0

Data

Read-Only,  expand-down

5

0

1

0

1

Data

Read-Only, expand-down, accessed

6

0

1

1

0

Data

Read/Write, expand-down

7

0

1

1

1

Data

Read/Write, expand-down, accessed

C

R

A

8

1

0

0

0

Code

Execute-Only

9

1

0

0

1

Code

Execute-Only, accessed

10

1

0

1

0

Code

Execute/Read

11

1

0

1

1

Code

Execute/Read, accessed

12

1

1

0

0

Code

Execute-Only,  conforming

13

1

1

0

1

Code

Execute-Only,  conforming,  accessed

14

1

1

1

0

Code

Execute/Read,  conforming

15

1

1

1

1

Code

Execute/Read, conforming, accessed