UnnamedOS

Global Descriptor Table. More...

+ Collaboration diagram for GDT:

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.
 

Detailed Description

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.

See also
gdt_asm.S
http://www.lowlevel.eu/wiki/Global_Descriptor_Table
http://wiki.osdev.org/Segmentation
http://wiki.osdev.org/GDT
http://wiki.osdev.org/GDT_Tutorial
https://en.wikibooks.org/wiki/X86_Assembly/Global_Descriptor_Table
https://stackoverflow.com/questions/23978486/far-jump-in-gdt-in-bootloader/23979175#23979175

Macro Definition Documentation

#define GDT_ENTRIES   6

number of entries in the GDT

See also
gdt_init

Definition at line 12 of file gdt.h.

Function Documentation

void gdt_flush ( )

Loads the kernel code and data segments into the segment registers.

See also
gdt_flush in gdt_asm.S

+ Here is the caller graph for this function:

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.

Parameters
entryindex into the GDT
Returns
a GDT selector corresponding to the GDT entry
See also
GDT_RING0_CODE_SEG
GDT_RING0_DATA_SEG
GDT_RING3_CODE_SEG
GDT_RING3_DATA_SEG
GDT_TASK_STATE_SEG

Definition at line 103 of file gdt.c.

+ Here is the caller graph for this function:

void gdt_init ( )

Initializes the GDT.

Creates the following descriptors for a flat memory model:

  • null descriptor
  • kernel code segment
  • kernel data segment
  • user code segment
  • user data segment
  • task state segment

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.

+ Here is the call graph for this function:

void gdt_init_entry ( size_t  entry,
uint32_t  base,
uint32_t  limit 
)

Sets basic parameters of a GDT entry.

Parameters
entryindex into the GDT
basewhere the segment begins
limitmaximum offset allowed

Definition at line 49 of file gdt.c.

+ Here is the caller graph for this function: