GDT
include/boot/gdt.h View source View on GitHubStructs
Section titled “Structs”gdt_entry
Section titled “gdt_entry”struct gdt_entry {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_middle;
uint8_t access;
uint8_t granularity;
uint8_t base_high;
}; gdt_ptr
Section titled “gdt_ptr”struct gdt_ptr {
uint16_t limit;
uint64_t base;
}; gdt_entry_tss
Section titled “gdt_entry_tss”struct gdt_entry_tss {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_middle;
uint8_t access;
uint8_t granularity;
uint8_t base_high;
uint32_t base_upper;
uint32_t reserved;
}; Functions
Section titled “Functions”gdt_install
Section titled “gdt_install”void gdt_install(); Macros
Section titled “Macros”ACCESS_CODE_RING0
Section titled “ACCESS_CODE_RING0”#define ACCESS_CODE_RING0 0x9A // exec/read, ring 0 ACCESS_DATA_RING0
Section titled “ACCESS_DATA_RING0”#define ACCESS_DATA_RING0 0x92 // read/write, ring 0 ACCESS_CODE_RING3
Section titled “ACCESS_CODE_RING3”#define ACCESS_CODE_RING3 0xFA // exec/read, ring 3 ACCESS_DATA_RING3
Section titled “ACCESS_DATA_RING3”#define ACCESS_DATA_RING3 0xF2 // read/write, ring 3 GRAN_CODE
Section titled “GRAN_CODE”#define GRAN_CODE 0xAF // G=1, D/B=0, L=1, AVL=0 GRAN_DATA
Section titled “GRAN_DATA”#define GRAN_DATA 0xAF // G=1, D/B=0, L=0, AVL=0 GDT_KERNEL_CODE
Section titled “GDT_KERNEL_CODE”#define GDT_KERNEL_CODE 0x08 // index 1 GDT_KERNEL_DATA
Section titled “GDT_KERNEL_DATA”#define GDT_KERNEL_DATA 0x10 // index 2 KERNEL_CS
Section titled “KERNEL_CS”#define KERNEL_CS GDT_KERNEL_CODE KERNEL_DS
Section titled “KERNEL_DS”#define KERNEL_DS GDT_KERNEL_DATA GDT_USER_CODE
Section titled “GDT_USER_CODE”#define GDT_USER_CODE 0x28 // index 5 << 3 GDT_USER_DATA
Section titled “GDT_USER_DATA”#define GDT_USER_DATA 0x30 // index 6 << 3 USER_CS
Section titled “USER_CS”#define USER_CS (GDT_USER_CODE | 0x3) // == 0x2B USER_DS
Section titled “USER_DS”#define USER_DS (GDT_USER_DATA | 0x3) // == 0x33 USER_SS
Section titled “USER_SS”#define USER_SS USER_DS