core: use define for gdt offset

This commit is contained in:
Starnakin 2024-10-02 14:15:49 +02:00
parent 64a3f6ee0d
commit a3bbffcfd9
2 changed files with 15 additions and 6 deletions

View File

@ -30,3 +30,12 @@ void init_gdt();
#define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010 #define GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA 0b00000010
#define GDT_ACCESS_A_ACCESSED 0b00000001 #define GDT_ACCESS_A_ACCESSED 0b00000001
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000 #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

View File

@ -42,7 +42,7 @@ void init_gdt(void)
set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x08, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_KERNEL_CODE, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_EXECUTABLE |
GDT_ACCESS_DC_NOT_CONFORM | GDT_ACCESS_DC_NOT_CONFORM |
@ -50,7 +50,7 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel code GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel code
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x10, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_KERNEL_DATA, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE |
GDT_ACCESS_DC_NOT_CONFORM | GDT_ACCESS_DC_NOT_CONFORM |
@ -58,7 +58,7 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel data GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel data
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x18, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_KERNEL_STACK, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_KERNEL_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE |
GDT_ACCESS_DC_CONFORM | GDT_ACCESS_DC_CONFORM |
@ -67,7 +67,7 @@ void init_gdt(void)
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel stack GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // Kernel stack
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x20, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_USER_CODE, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_EXECUTABLE |
GDT_ACCESS_DC_CONFORM | GDT_ACCESS_DC_CONFORM |
@ -75,7 +75,7 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User code GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User code
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x28, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_USER_DATA, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE |
GDT_ACCESS_DC_NOT_CONFORM | GDT_ACCESS_DC_NOT_CONFORM |
@ -83,7 +83,7 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User data GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User data
set_gdt_entry_value( set_gdt_entry_value(
gdt_entries + 0x30, 0, 0xFFFFF, gdt_entries + GDT_OFFSET_USER_STACK, 0, 0xFFFFF,
GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE | GDT_ACCESS_P_VALID | GDT_ACCESS_DPL_USER_MODE |
GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE | GDT_ACCESS_S_CODE_OR_DATA | GDT_ACCESS_E_NOT_EXECUTABLE |
GDT_ACCESS_DC_CONFORM | GDT_ACCESS_DC_CONFORM |