2024-09-09 12:00:17 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2024-09-10 15:36:28 -04:00
|
|
|
#define GDT_ADDRESS 0x00000800
|
|
|
|
#define GDT_SIZE 7
|
2024-09-10 05:19:23 -04:00
|
|
|
|
2024-09-10 15:36:28 -04:00
|
|
|
// https://wiki.osdev.org/Global_Descriptor_Table#Segment_Descriptor
|
|
|
|
struct gdt_entry
|
|
|
|
{
|
|
|
|
uint16_t limit_low;
|
|
|
|
uint16_t base_low;
|
|
|
|
uint8_t base_middle;
|
|
|
|
uint8_t access;
|
|
|
|
uint8_t limit_high_and_flags;
|
|
|
|
uint8_t base_high;
|
|
|
|
} __attribute__((packed)) ;
|
2024-09-09 12:00:17 -04:00
|
|
|
|
|
|
|
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
|
|
|
struct gdt_descriptor {
|
|
|
|
uint16_t size;
|
|
|
|
uint32_t base;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2024-09-10 15:36:28 -04:00
|
|
|
void initGdt();
|
|
|
|
|
|
|
|
#define GDT_FLAG_64BIT_MODE 0b0010
|
|
|
|
#define GDT_FLAG_32BIT_MODE 0b0100
|
|
|
|
#define GDT_FLAG_PAGE_MODE 0b1000
|
|
|
|
#define GDT_FLAG_BYTE_MODE 0b1000
|
|
|
|
|
|
|
|
#define GDT_ACCESS_P_VALID 0b10000000
|
|
|
|
#define GDT_ACCESS_DPL_KERNEL_MODE 0b00000000
|
|
|
|
#define GDT_ACCESS_DPL_USER_MODE 0b01100000
|
|
|
|
#define GDT_ACCESS_S_CODE_OR_DATA 0b00010000
|
|
|
|
#define GDT_ACCESS_S_SYSTEM_SEGMENT 0b00010000
|
|
|
|
#define GDT_ACCESS_E_EXECUTABLE 0b00001000
|
|
|
|
#define GDT_ACCESS_E_NOT_EXECUTABLE 0b00000000
|
|
|
|
#define GDT_ACCESS_DC_CONFORM 0b00000100 // TODO UNDERSTAND THIS BIT
|
|
|
|
#define GDT_ACCESS_DC_NOT_CONFORM 0b00000000
|
|
|
|
#define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010
|
|
|
|
#define GDT_ACCESS_A_ACCESSED 0b00000001
|
|
|
|
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
|