Segments in the 80386

Segment registers are used in address translation to generate a linear address from a logical (virtual) address.

#screen2185#

The linear address is then translated into a physical address by the paging hardware. Each segment in the system is described by a 8 byte segment descriptor which contains all pertinent information (base, limit, type, privilege).

<#2188#> The segments are:<#2188#>

<#2189#> Regular segments<#2189#>

<#2192#> System segments<#2192#>

Characteristics of system segments:

To keep track of all these segments, the 386 uses a global descriptor table (GDT) that is setup in memory by the system (located by the GDT register). The GDT contains a segment descriptors for each task state segment, each local descriptor tablet and also regular segments. The Linux GDT contains just two normal segment entries: The rest of the GDT is filled with TSS and LDT system descriptors: <#2207#> Note LDT[n] != LDTn<#2207#> At present the GDT has a total of 256 entries or room for as many as 126 tasks. The kernel segments have base 0xc0000000 which is where the kernel lives in the linear view. Before a segment can be used, the contents of the descriptor for that segment must be loaded into the segment register. The 386 has a complex set of criteria regarding access to segments so you can't simply load a descriptor into a segment register. Also these segment registers have programmer invisible portions. The visible portion is what is usually called a segment register: cs, ds, es, fs, gs, and ss. The programmer loads one of these registers with a 16-bit value called a selector. The selector uniquely identifies a segment descriptor in one of the tables. Access is validated and the corresponding descriptor loaded by the hardware. Currently \ largely ignores the (overly?) complex segment level protection afforded by the 386. It is biased towards the paging hardware and the associated page level protection. The segment level rules that apply to user processes are
  1. A process cannot directly access the kernel data or code segments
  2. There is always limit checking but given that every user segment goes from 0x00 to 0xc0000000 it is unlikely to apply. <#2211#> [This has changed, and needs updating, please.]<#2211#>