42_KFS/headers/gdt.h

33 lines
1.2 KiB
C
Raw Normal View History

#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
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
struct gdt_descriptor {
uint16_t size;
uint32_t base;
} __attribute__((packed));
void init_gdt();
2024-09-10 15:36:28 -04:00
#define GDT_FLAG_64BIT_MODE 0b0010
#define GDT_FLAG_32BIT_MODE 0b0100
#define GDT_FLAG_PAGE_MODE 0b1000
#define GDT_FLAG_BYTE_MODE 0b1000
2024-09-10 15:36:28 -04:00
#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
2024-09-10 15:36:28 -04:00
#define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010
#define GDT_ACCESS_A_ACCESSED 0b00000001
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000