diff options
author | Marvin Borner | 2021-05-20 20:41:24 +0200 |
---|---|---|
committer | Marvin Borner | 2021-05-20 20:41:24 +0200 |
commit | 298aaf63f15350e6248d5a96e8c6a63b0ec93e0f (patch) | |
tree | 952331f841b4d02d0b7189da716648df5cdb4d8e /kernel/inc/drivers/gdt.h | |
parent | b22346a9b830b642e684e13cf4946d8ef8d8e1ca (diff) |
Major restructuring
Diffstat (limited to 'kernel/inc/drivers/gdt.h')
-rw-r--r-- | kernel/inc/drivers/gdt.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/kernel/inc/drivers/gdt.h b/kernel/inc/drivers/gdt.h new file mode 100644 index 0000000..7b9c65a --- /dev/null +++ b/kernel/inc/drivers/gdt.h @@ -0,0 +1,68 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef GDT_H +#define GDT_H + +#include <def.h> + +#define GDT_ROOT_CODE_GATE 1 +#define GDT_ROOT_DATA_GATE 2 +#define GDT_USER_CODE_GATE 3 +#define GDT_USER_DATA_GATE 4 +#define GDT_TSS_GATE 5 + +#define GDT_SUPER_CODE_OFFSET (gdt_offset(GDT_ROOT_CODE_GATE)) +#define GDT_SUPER_DATA_OFFSET (gdt_offset(GDT_ROOT_DATA_GATE)) +#define GDT_USER_CODE_OFFSET (gdt_offset(GDT_USER_CODE_GATE) | 3) +#define GDT_USER_DATA_OFFSET (gdt_offset(GDT_USER_DATA_GATE) | 3) +#define GDT_TSS_OFFSET (gdt_offset(GDT_TSS_GATE)) + +struct gdt_entry { + u16 limit_low; + u16 base_low; + u8 base_middle; + u8 access; + u8 granularity; + u8 base_high; +} PACKED; + +struct gdt_ptr { + u16 limit; + void *base; +} PACKED; + +struct tss_entry { + u32 prev_tss; + u32 esp0; + u32 ss0; + u32 esp1; + u32 ss1; + u32 esp2; + u32 ss2; + u32 cr3; + u32 eip; + u32 eflags; + u32 eax; + u32 ecx; + u32 edx; + u32 ebx; + u32 esp; + u32 ebp; + u32 esi; + u32 edi; + u32 es; + u32 cs; + u32 ss; + u32 ds; + u32 fs; + u32 gs; + u32 ldt; + u16 trap; + u16 iomap_base; +} PACKED; + +CONST u8 gdt_offset(u8 gate); +void gdt_install(u32 esp); +void tss_set_stack(u32 esp); + +#endif |