blob: 202fe775c91e47144f1e5806e30f6b1c0fc0fa6c (
plain)
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
|
#include "gdt.h"
GDT::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, uint8_t type) {
base_low = base & 0xffff;
base_high = (base >> 16) & 0xff;
base_vhigh = (base >> 24) & 0xff;
}
uint32_t GDT::SegmentDescriptor::base() const {
uint32_t base = base_vhigh;
base = (base << 8) + base_high;
base = (base << 8) + base_low;
return base;
}
uint32_t GDT::SegmentDescriptor::limit() const {
return 0;
}
GDT::GDT()
: segments{{0, 0, 0}, // null segment
{0, 64 * 1024 * 1024 /* 64MB */, 0x9a}, // code segment
{0, 64 * 1024 * 1024 /* 64MB */, 0x92}} // data segment
{
Pointer gdtr{.limit = sizeof(segments) - 1, .base = reinterpret_cast<uint32_t>(segments)};
asm volatile("lgdt %0" : : "p"(gdtr));
}
|