#pragma once #include #define GDT_ADDRESS 0xC0105040 #define GDT_SIZE 7 // https://wiki.osdev.org/Global_Descriptor_Table#GDTR struct gdt_descriptor { uint16_t size; uint32_t base; } __attribute__((packed)); void init_gdt(); #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 extern uint8_t gdt_entries[GDT_SIZE * 8]; #define GDT_OFFSET_KERNEL_CODE 0x08 #define GDT_OFFSET_KERNEL_DATA 0x10 #define GDT_OFFSET_KERNEL_STACK 0x18 #define GDT_OFFSET_USER_CODE 0x20 #define GDT_OFFSET_USER_DATA 0x28 #define GDT_OFFSET_USER_STACK 0x30