Segment descriptor


In memory addressing for Intel x86 computer architectures, segment descriptors are a part of the segmentation unit, used for translating a logical address to a linear address. Segment descriptors describe the memory segment referred to in the logical address.
The segment descriptor contains the following fields:
  1. A segment base address
  2. The segment limit which specifies the segment size
  3. Access rights byte containing the protection mechanism information
  4. Control bits

    Structure

The x86 and x86-64 segment descriptor has the following form:
Where the fields stand for:
; Base Address : 32 bit starting memory address of the segment
; Segment Limit : 20 bit length of the segment. How exactly this should be interpreted depends on other bits of the segment descriptor.
; G=Granularity : If clear, the limit is in units of bytes, with a maximum of 220 bytes. If set, the limit is in units of 4096-byte pages, for a maximum of 232 bytes.
; D=Default operand size : If clear, this is a 16-bit code segment; if set, this is a 32-bit segment.
; B=Big: If set, the maximum offset size for a data segment is increased to 32-bit 0xffffffff. Otherwise it's the 16-bit max 0x0000ffff. Essentially the same meaning as "D".
; L=Long : If set, this is a 64-bit segment, and code in this segment uses the 64-bit instruction encoding. "L" cannot be set at the same time as "D" aka "B".
; AVL=Available : For software use, not used by hardware
; P=Present : If clear, a "segment not present" exception is generated on any reference to this segment
; DPL=Descriptor privilege level : Privilege level required to access this descriptor
; Type: If set, this is a code segment descriptor. If clear, this is a data/stack segment descriptor, which has "D" replaced by "B", "C" replaced by "E"and "R" replaced by "W". This is in fact a special case of the 2-bit type field, where the preceding bit 12 cleared as "0" refers to more internal system descriptors, for LDT, LSS, and gates.
; C=Conforming : Code in this segment may be called from less-privileged levels.
; E=Expand-Down: If clear, the segment expands from base address up to base+limit. If set, it expands from maximum offset down to limit, a behavior usually used for stacks.
; R=Readable : If clear, the segment may be executed but not read from.
; W=Writable : If clear, the data segment may be read but not written to.
; A=Accessed : This bit is set to 1 by hardware when the segment is accessed, and cleared by software.