2024-09-09 12:00:17 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2024-10-14 17:36:41 -04:00
|
|
|
#define GDT_ADDRESS 0xC0105040
|
2024-09-17 05:10:41 -04:00
|
|
|
#define GDT_SIZE 7
|
2024-09-10 05:19:23 -04:00
|
|
|
|
2024-09-09 12:00:17 -04:00
|
|
|
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
|
|
|
struct gdt_descriptor {
|
2024-09-17 05:10:41 -04:00
|
|
|
uint16_t size;
|
|
|
|
uint32_t base;
|
2024-09-09 12:00:17 -04:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2024-09-17 05:10:41 -04:00
|
|
|
void init_gdt();
|
2024-09-10 15:36:28 -04:00
|
|
|
|
|
|
|
#define GDT_FLAG_64BIT_MODE 0b0010
|
|
|
|
#define GDT_FLAG_32BIT_MODE 0b0100
|
2024-09-17 05:10:41 -04:00
|
|
|
#define GDT_FLAG_PAGE_MODE 0b1000
|
|
|
|
#define GDT_FLAG_BYTE_MODE 0b1000
|
2024-09-10 15:36:28 -04:00
|
|
|
|
2024-09-17 05:10:41 -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
|
2024-09-17 05:10:41 -04:00
|
|
|
#define GDT_ACCESS_A_ACCESSED 0b00000001
|
|
|
|
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
|
2024-10-02 08:15:49 -04:00
|
|
|
|
|
|
|
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
|