Global Descriptor Table. More...
Data Structures | |
struct | gdtr_t |
the GDTR register pointing to the GDT More... | |
union | gdt_selector_t |
A selector in the GDT. More... | |
struct | gdt_entry_t |
An entry in the GDT. More... | |
Macros | |
#define | GDT_ENTRIES 6 |
number of entries in the GDT More... | |
#define | GDT_RING0_CODE_SEG 1 |
kernel code segment index | |
#define | GDT_RING0_DATA_SEG 2 |
kernel data segment index | |
#define | GDT_RING3_CODE_SEG 3 |
user code segment index | |
#define | GDT_RING3_DATA_SEG 4 |
user data segment index | |
#define | GDT_TASK_STATE_SEG 5 |
task state segment index | |
Functions | |
void | gdt_init_entry (size_t entry, uint32_t base, uint32_t limit) |
Sets basic parameters of a GDT entry. More... | |
static void | gdt_load () |
Loads the GDT into the GDTR register. | |
void | gdt_flush () |
Loads the kernel code and data segments into the segment registers. More... | |
void | gdt_init () |
Initializes the GDT. More... | |
uint16_t | gdt_get_selector (size_t entry) |
Returns a selector ready to be loaded in a segment register. More... | |
Variables | |
static gdt_entry_t | gdt [GDT_ENTRIES] |
The GDT itself. It is located inside the kernel. | |
Global Descriptor Table.
The GDT defines memory segments that can be used for memory protection. Here we use a flat memory model, therefore we only need 2 entries for the kernel and user space each and a TSS.
#define GDT_ENTRIES 6 |
void gdt_flush | ( | ) |
uint16_t gdt_get_selector | ( | size_t | entry | ) |
Returns a selector ready to be loaded in a segment register.
These selectors are used in segment registers, the IDT and to switch to user space.
entry | index into the GDT |
Definition at line 103 of file gdt.c.
void gdt_init | ( | ) |
Initializes the GDT.
Creates the following descriptors for a flat memory model:
Then loads the GDT into GDTR and sets the segments registers.
It also loads the TSS into the TR register.
Definition at line 72 of file gdt.c.