43 lines
1.2 KiB
C
43 lines
1.2 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#define GDT_ADDRESS 0x00000800
|
|
#define GDT_SIZE 7
|
|
|
|
// 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)) ;
|
|
|
|
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
|
|
struct gdt_descriptor {
|
|
uint16_t size;
|
|
uint32_t base;
|
|
} __attribute__((packed));
|
|
|
|
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 |