-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.gdt.d
44 lines (37 loc) · 833 Bytes
/
kernel.gdt.d
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
// Copyright (C) 2021 Mateus de Lima Oliveira
module kernel.gdt;
extern(C)
struct GDTEntry
{
align (1):
ushort limit_low;
ushort base_low;
ubyte base_middle;
ubyte access;
ubyte granularity;
ubyte base_high;
}
extern(C)
struct GDTPointer {
align (1):
ushort limit;
uint base;
}
extern(C) void load_gdt(GDTPointer *p);
static __gshared GDTEntry[6] gdt;
static __gshared GDTPointer gdtPtr;
@trusted void SetGDTGate
(uint entry,
uint base,
uint limit,
ubyte access,
ubyte granularity)
{
gdt[entry].base_low = (base & 0xFFFF);
gdt[entry].base_middle = (base >> 16) & 0xFF;
gdt[entry].base_high = (base >> 24) & 0xFF;
gdt[entry].limit_low = (limit & 0xFFFF);
gdt[entry].granularity = (limit >> 16) & 0x0F; // limit high
gdt[entry].granularity |= granularity & 0xF0; // flags
gdt[entry].access = access;
}