My Kernel v0.1.0
Collaboration diagram for Global Descriptor Table:

Data Structures

struct  gdtr
 The GDT is pointed to by the value in the GDTR register. More...
 
struct  gdt_descriptor
 A single entry inside the GDT. More...
 
struct  tss
 Segment. More...
 
union  segment_selector
 Identifies a segment inside the GDT or LDT. More...
 

Enumerations

enum  {
}
 Known fixed indexes inside the GDT. More...
 

Functions

void gdt_init (void)
 Initialize the GDTR and GDT. More...
 
void gdt_load_segment (gdt_descriptor, u16 index)
 Load a segment descriptor into the Global Descriptor Table. More...
 
void gdt_log (void)
 Print the content of the GDT and GDTR.
 
void gdt_set_esp0 (u32)
 Modify the kernel stack pointer inside the current TSS.
 

Detailed Description

Global Descriptor Table

The GDT is responsible for segmenting the physical address space into different parts with different level of security each.

The segments can contain either code or data.

Each "segment" can then be accessed using a selector. These selectors are the ones stored inside the segement registers (cs, ds ..) When addressing a linear address (~physical), the processor infact dereferences an offset inside the related segment's address range.

Warning
This is a x86 structure only
See also
https://wiki.osdev.org/Global_Descriptor_Table

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GDT_ENTRY_KERNEL_CODE 

Required NULL segment.

GDT_ENTRY_KERNEL_DATA 

Kernel code segment.

GDT_ENTRY_USER_CODE 

Kernel data segment.

GDT_ENTRY_USER_DATA 

User code segment.

GDT_ENTRY_TSS 

User data segment.

Function Documentation

◆ gdt_init()

void gdt_init ( void  )
  • Load the GDT's base address int GDTR
  • Setup the NULL segment at offset 0
  • Add our global segment descriptors (ring 0)

◆ gdt_load_segment()

void gdt_load_segment ( gdt_descriptor  segment,
u16  index 
)
Parameters
segmentThe segment's content
indexThe segment's index within the GDT.