next up previous contents index
Next: 10.7.2 base_gdt_init: initialize the Up: (X86) Base Environment: Segmentation Previous: (X86) Base Environment: Segmentation

10.7.1 base_gdt: default global descriptor table for the base environment

   

SYNOPSIS

#include <oskit/x86/base_gdt.h>

extern struct x86_desc base_gdt [GDTSZ];

DESCRIPTION

This variable is used in the base environment as the default global descriptor table. The default base_gdt definition contains GDTSZ selector slots, including the Intel-reserved, permanently unused slot 0.

The following symbols are defined in base_gdt.h to be segment selectors for the descriptors in the base GDT. These selectors can be converted to indices into the GDT descriptor array base_gdt by dividing by 8 (the processor reserves the low three bits of all selectors for other information).

BASE_TSS
A selector for the base task state segment (base_tss). The BASE_TSS segment descriptor is initialized by base_gdt_init, but the base_tss structure itself is initialized by base_tss_init and loaded into the processor by base_tss_load; see Section 10.7.6 for more details.
KERNEL_CS
This is the default kernel code segment selector. It is initialized by base_gdt_init to be a flat-model, 4GB, readable, ring 0 code segment; base_gdt_load loads this segment into the CS register while reinitializing the processor's segment registers.
KERNEL_DS
This is the default kernel data segment selector. It is initialized by base_gdt_init to be a flat-model, 4GB, writable, ring 0 data segment; base_gdt_load loads this segment into the DS, ES, and SS registers while reinitializing the processor's segment registers.
KERNEL_16_CS
This selector is identical to KERNEL_CS except that it is a 16-bit code segment (the processor defaults to 16-bit operand and addressing modes rather than 32-bit while running code in this segment), and it has a 64KB limit rather than 4GB. This selector is used when switching between real and protected mode, to provide an intermediate 16-bit protected mode execution context. It is unused in kernels that never execute in real mode (e.g., typical MultiBoot kernels).
KERNEL_16_DS
This selector is a data segment synonym for KERNEL_16_CS; it is generally only used when switching from protected mode back to real mode. It is used to ensure that the segment registers contain sensible real-mode values before performing the switch, as recommended in Intel literature.
LINEAR_CS
This selector is set up to be a ring 0 code segment that directly maps the entire linear address space: in other words, it has an offset of zero and a 4GB limit. In some environments, where kernel virtual addresses are the same as linear addresses, this selector is a synonym for KERNEL_CS.
LINEAR_DS
This is a data segment otherwise identical to LINEAR_CS.
USER_CS
This selector is left unused and uninitialized by the OSKit; nominally, it is intended to be used as a code segment for unprivileged user-level code.
USER_DS
This selector is left unused and uninitialized by the OSKit; nominally, it is intended to be used as a data segment for unprivileged user-level code.

If the client OS wants to make use of the base GDT but needs more selector slots for its own purposes, it can define its own instance of the base_gdt variable so that it has room for more than GDTSZ elements; base_gdt_init will initialize only the first ``standard'' segment descriptors, leaving the rest for the client OS's use.

On multiprocessor systems, the client OS may want each processor to have its own GDT. In this case, the OS can create a separate clone of the base GDT for each additional processor besides the boot processor, and leave the boot processor using the base GDT. Alternatively, the OS could use the base GDT only during initialization, and switch all processors to custom GDTs later; this approach provides the most flexibility to the OS, since the custom GDTs can be arranged in whatever way is most convenient.


next up previous contents index
Next: 10.7.2 base_gdt_init: initialize the Up: (X86) Base Environment: Segmentation Previous: (X86) Base Environment: Segmentation

University of Utah Flux Research Group