KernOS
GDT Namespace Reference

global descriptor table More...

Classes

union  GdtEntry
 Global descriptor table entry. More...
 
struct  Selector
 convenience structure used to set bits of GdtEntry More...
 

Enumerations

enum  Segment : uint16_t {
  Null = 0, K_CS, K_DS, U_CS,
  U_DS
}
 Code segments. More...
 

Functions

constexpr uint8_t SEG_OFFSET (const Segment Seg)
 Translates code segment enum to code segment selector. More...
 
void SetGlobalDescriptorEntry (GdtEntry GdtTable[], const Selector SelectorTable[])
 Set entries in GdtTable from array of Selector. More...
 
void Load_gdt (void *gdtAddress, uint16_t LimitUse)
 assembly instruction to load gdt table to CPU More...
 
void Install_gdt ()
 Creates global descriptor entries in gdt_table, and loads into CPU. More...
 

Variables

const uint8_t GDT_ENTRIES = 5
 
const uint32_t NULL_LIMIT = 0x00000000
 
const uint32_t KERN_CS_LIMIT = 0x000FFFFF
 
const uint32_t KERN_DS_LIMIT = 0x000FFFFF
 
const uint32_t USER_CS_LIMIT = 0x000FFFFF
 
const uint32_t USER_DS_LIMIT = 0x000FFFFF
 
const uint32_t NULL_BASE = 0x00000000
 
const uint32_t KERN_CS_BASE = 0x00000000
 
const uint32_t KERN_DS_BASE = 0x00000000
 
const uint32_t USER_CS_BASE = 0x00000000
 
const uint32_t USER_DS_BASE = 0x00000000
 
const uint8_t NULL_GRANULARITY = 0x00
 
const uint8_t KERN_CS_GRANULARITY = 0xC0
 
const uint8_t KERN_DS_GRANULARITY = 0xC0
 
const uint8_t USER_CS_GRANULARITY = 0xC0
 
const uint8_t USER_DS_GRANULARITY = 0xC0
 

Detailed Description

global descriptor table

Enumeration Type Documentation

◆ Segment

enum GDT::Segment : uint16_t

Code segments.

Enumerator
Null 

null descriptor

K_CS 

kernel code segment

K_DS 

kernel data segment

U_CS 

user code segment

U_DS 

user data segment

Definition at line 16 of file gdt.h.

Function Documentation

◆ Install_gdt()

void GDT::Install_gdt ( )

Creates global descriptor entries in gdt_table, and loads into CPU.

We are going to use x86 protected mode, thus the segment selectors won't be used for either virtual memory, or memory protection. However since segmentation cannot be turned off on an x86, we simply set the kernel/user space segments to 0 base to simulate flat memory model

See also
Segmentation in x86 in practice

Definition at line 125 of file gdt.cpp.

◆ Load_gdt()

void GDT::Load_gdt ( void *  gdtAddress,
uint16_t  LimitUse 
)
inline

assembly instruction to load gdt table to CPU

Parameters
gdtAddress
LimitUse

Definition at line 104 of file gdt.cpp.

◆ SEG_OFFSET()

constexpr uint8_t GDT::SEG_OFFSET ( const Segment  Seg)
inline

Translates code segment enum to code segment selector.

Parameters
Seg- enum of kernel/user space code/data segment
Returns
Byte position of code segment in gdt_table

Definition at line 29 of file gdt.h.

◆ SetGlobalDescriptorEntry()

void GDT::SetGlobalDescriptorEntry ( GdtEntry  GdtTable[],
const Selector  SelectorTable[] 
)

Set entries in GdtTable from array of Selector.

Parameters
[out]GdtTableto be loaded into CPU later
[in]SelectorTableused to specify entries to GdtTable

Definition at line 82 of file gdt.cpp.

Variable Documentation

◆ GDT_ENTRIES

const uint8_t GDT::GDT_ENTRIES = 5

Definition at line 12 of file gdt.h.

◆ KERN_CS_BASE

const uint32_t GDT::KERN_CS_BASE = 0x00000000

Definition at line 65 of file gdt.cpp.

◆ KERN_CS_GRANULARITY

const uint8_t GDT::KERN_CS_GRANULARITY = 0xC0

Definition at line 71 of file gdt.cpp.

◆ KERN_CS_LIMIT

const uint32_t GDT::KERN_CS_LIMIT = 0x000FFFFF

Definition at line 59 of file gdt.cpp.

◆ KERN_DS_BASE

const uint32_t GDT::KERN_DS_BASE = 0x00000000

Definition at line 66 of file gdt.cpp.

◆ KERN_DS_GRANULARITY

const uint8_t GDT::KERN_DS_GRANULARITY = 0xC0

Definition at line 72 of file gdt.cpp.

◆ KERN_DS_LIMIT

const uint32_t GDT::KERN_DS_LIMIT = 0x000FFFFF

Definition at line 60 of file gdt.cpp.

◆ NULL_BASE

const uint32_t GDT::NULL_BASE = 0x00000000

Definition at line 64 of file gdt.cpp.

◆ NULL_GRANULARITY

const uint8_t GDT::NULL_GRANULARITY = 0x00

Definition at line 70 of file gdt.cpp.

◆ NULL_LIMIT

const uint32_t GDT::NULL_LIMIT = 0x00000000

Definition at line 58 of file gdt.cpp.

◆ USER_CS_BASE

const uint32_t GDT::USER_CS_BASE = 0x00000000

Definition at line 67 of file gdt.cpp.

◆ USER_CS_GRANULARITY

const uint8_t GDT::USER_CS_GRANULARITY = 0xC0

Definition at line 73 of file gdt.cpp.

◆ USER_CS_LIMIT

const uint32_t GDT::USER_CS_LIMIT = 0x000FFFFF

Definition at line 61 of file gdt.cpp.

◆ USER_DS_BASE

const uint32_t GDT::USER_DS_BASE = 0x00000000

Definition at line 68 of file gdt.cpp.

◆ USER_DS_GRANULARITY

const uint8_t GDT::USER_DS_GRANULARITY = 0xC0

Definition at line 74 of file gdt.cpp.

◆ USER_DS_LIMIT

const uint32_t GDT::USER_DS_LIMIT = 0x000FFFFF

Definition at line 62 of file gdt.cpp.