LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
gdt.h
Go to the documentation of this file.
9#ifndef KERNEL_ARCH_X86_64_GDT_H
10#define KERNEL_ARCH_X86_64_GDT_H
11
12#include <lib/kstring.h>
13#include <stdbool.h>
14#include <kernel/tools.h>
15#include <kernel/log.h>
16#include <stdint.h>
17
18#define CODE_DATA_SEGMENT true
19#define LIMIT_BYTES false
20#define LIMIT_4KIB_PAGES true
21#define SEGMENT_32_BIT true
22#define SEGMENT_16_BIT false
23
25struct __attribute__((packed)) gdt_entry {
26 uint16_t limit;
27 uint16_t base1;
28 uint8_t base2;
30 uint8_t access;
32 uint8_t flags;
33 uint8_t base3;
34};
35
37struct __attribute__((packed)) tss {
38 uint32_t reserved0;
39 uint64_t rsp0, rsp1, rsp2;
40 uint64_t reserved1;
42 uint64_t ist[7];
43 uint64_t reserved2;
44 uint16_t reserved3;
45 uint16_t iopb_offset;
46};
47
48_Static_assert(sizeof(struct tss) == 104, "TSS must be 104 bytes");
49
51struct __attribute__((packed)) gdtr {
53 uint16_t limit;
55 uint64_t base;
56};
57
61void init_gdt(void);
62
69void gdt_set_entry(int index, uint8_t access, uint8_t flags);
70
79uint8_t get_access_byte(bool rw, bool exec, bool type, uint8_t dpl);
80
88uint8_t get_flag_byte(bool granularity, bool size, bool long_mode);
89
90#endif
uint8_t get_access_byte(bool rw, bool exec, bool type, uint8_t dpl)
Generates the access byte for the GDT.
Definition gdt.c:120
uint8_t get_flag_byte(bool granularity, bool size, bool long_mode)
Generates the flag byte for the GDT.
Definition gdt.c:128
void gdt_set_entry(int index, uint8_t access, uint8_t flags)
Sets an entry of the gdt with the correct access and flags.
Definition gdt.c:110
void init_gdt(void)
Initializes the gdt and loads it.
Definition gdt.c:29
Utilities for memory and string operations.
Logging utilities for the kernel.
Extra kernel utilities.