blob: 9a9fd01f5d06aa208ce7f95ebcb460f480a0f4e8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// MIT License, Copyright (c) 2021 Marvin Borner
#ifndef GDT_H
#define GDT_H
#include <def.h>
#define GDT_SUPER_CODE_OFFSET 0x08 // Super (kernel) code segment offset in GDT
#define GDT_SUPER_DATA_OFFSET 0x10 // Super (kernel) data segment offset in GDT
#define GDT_USER_CODE_OFFSET 0x1b // User code segment offset in GDT (with ring3 mask)
#define GDT_USER_DATA_OFFSET 0x23 // User data segment offset in GDT (with ring3 mask)
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;
void gdt_install(u32 esp);
void tss_set_stack(u32 ss, u32 esp);
#endif
|