x86x86-64hardwareintelgdt

How are segment types distinguished from one another?


How are different types of segment identified as different? Wikipedia states:

Segments can be defined to be either code, data, or system segments

It also states:

Descriptors with bit 12 clear are "system descriptors" and are used for specialized purposes.

So, I gather that this "system bit" is used to identify a system segment, but what about code and data segments? Additionally, since these identifiers are stored separately instead of as a single 2-bit value, can you get combination-types, like system code and system data segments?


Solution

  • The Type field of a segment descriptor is not one bit but four.

    Format of a segment descriptor with 1 bit for the system/non-system type and 4 bit of sub type

    The S field defines if the descriptor is a system descriptor (bit is clear) or not.
    The interpretation of the Type field depends on the value of S.

    Non system descriptors

    Non system descriptors

    System descriptors

    System descriptors


    To better understand how protected/long mode segmentation works I advice you dropping Wikipedia in favour of the Intel manuals.