background image

3-10 Vol. 3A

PROTECTED-MODE MEMORY MANAGEMENT

The flags and fields in a segment descriptor are as follows:
Segment limit field

Specifies the size of the segment. The processor puts together the two segment limit fields to form 
a 20-bit value. The processor interprets the segment limit in one of two ways, depending on the 
setting of the G (granularity) flag:

If the granularity flag is clear, the segment size can range from 1 byte to 1 MByte, in byte incre-
ments.

If the granularity flag is set, the segment size can range from 4 KBytes to 4 GBytes, in 4-KByte 
increments.

The processor uses the segment limit in two different ways, depending on whether the segment is 
an expand-up or an expand-down segment. See Section 3.4.5.1, “Code- and Data-Segment 
Descriptor Types”
, for more information about segment types. For expand-up segments, the offset 
in a logical address can range from 0 to the segment limit. Offsets greater than the segment limit 
generate general-protection exceptions (#GP, for all segments other than SS) or stack-fault excep-
tions (#SS for the SS segment). For expand-down segments, the segment limit has the reverse 
function; the offset can range from the segment limit plus 1 to FFFFFFFFH or FFFFH, depending on 
the setting of the B flag. Offsets less than or equal to the segment limit generate general-protection 
exceptions or stack-fault exceptions. Decreasing the value in the segment limit field for an expand-
down segment allocates new memory at the bottom of the segment's address space, rather than at 
the top. IA-32 architecture stacks always grow downwards, making this mechanism convenient for 
expandable stacks.

Base address fields

Defines the location of byte 0 of the segment within the 4-GByte linear address space. The 
processor puts together the three base address fields to form a single 32-bit value. Segment base 
addresses should be aligned to 16-byte boundaries. Although 16-byte alignment is not required, 
this alignment allows programs to maximize performance by aligning code and data on 16-byte 
boundaries.

Type field

Indicates the segment or gate type and specifies the kinds of access that can be made to the 
segment and the direction of growth. The interpretation of this field depends on whether the 
descriptor type flag specifies an application (code or data) descriptor or a system descriptor. The 
encoding of the type field is different for code, data, and system descriptors (see Figure 5-1). See 
Section 3.4.5.1, “Code- and Data-Segment Descriptor Types”, for a description of how this field is 
used to specify code and data-segment types. 

Figure 3-8.  Segment Descriptor

31

24 23 22 21 20 19

16 15

13

14

12 11

8 7

0

P

Base 31:24

G

D
P

L

Type

S

L

4

31

16 15

0

Base Address 15:00

Segment Limit 15:00

0

Base 23:16

D

/

B

A
V

L

Seg.

Limit

19:16

G

— Granularity

LIMIT — Segment Limit
P

— Segment present

S

— Descriptor type (0 = system; 1 = code or data)

TYPE — Segment type

DPL

— Descriptor privilege level

AVL

— Available for use by system software

BASE — Segment base address

D/B

— Default operation size (0 = 16-bit segment; 1 = 32-bit segment)

L

— 64-bit code segment (IA-32e mode only)