Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace system {
- namespace gdt {
- enum selector {
- Null = 0,
- Kernel_Code = 1,
- Kernel_Data = 2,
- User_Data = 3,
- User_Code = 4,
- Tss = 5,
- };
- enum flags : std::uint32_t {
- Segment = 0b00010000,
- Present = 0b10000000,
- User = 0b01100000,
- Executable = 0b00001000,
- Read_Write = 0b00000010,
- };
- enum granularity {
- Long_Mode = 0b0010,
- Flags = 0b1100,
- };
- struct [[gnu::packed]] tss {
- std::uint32_t reserved;
- std::array<uint64_t, 3> rsp;
- std::uint64_t reserved0;
- std::array<uint64_t, 7> ist;
- std::uint32_t reserved1;
- std::uint32_t reserved2;
- std::uint16_t reserved3;
- std::uint16_t iopb_offset;
- };
- struct [[gnu::packed]] gdt_entry {
- std::uint16_t limit_low;
- std::uint16_t base_low;
- std::uint8_t base_mid;
- std::uint8_t flags;
- std::uint8_t limit_high : 4;
- std::uint8_t granularity : 4;
- std::uint8_t base_high;
- constexpr gdt_entry() : gdt_entry(0, 0, 0, 0) {}
- constexpr gdt_entry(std::uint8_t flags, std::uint8_t granularity)
- : gdt_entry(0, 0, flags, granularity) {}
- constexpr gdt_entry(std::uint32_t base, std::uint32_t limit,
- std::uint8_t flags, std::uint8_t granularity)
- : limit_low(static_cast<uint16_t>(limit & 0xFFFF)),
- base_low(static_cast<uint16_t>(base & 0xFFFF)),
- base_mid(static_cast<uint8_t>((base >> 16) & 0xFF)),
- flags(flags),
- limit_high((limit >> 16) & 0x0F),
- granularity(granularity),
- base_high(static_cast<uint8_t>((base >> 24) & 0xFF)) {}
- };
- struct [[gnu::packed]] gdt_tss_entry {
- std::uint16_t len;
- std::uint16_t base_low;
- std::uint8_t base_mid;
- std::uint8_t flags1;
- std::uint8_t flags2;
- std::uint8_t base_high;
- std::uint32_t base_upper;
- std::uint32_t reserved;
- constexpr gdt_tss_entry() = default;
- gdt_tss_entry(const tss& _tss)
- : len(sizeof(tss)),
- base_low(reinterpret_cast<std::uintptr_t>(&_tss) & 0xFFFF),
- base_mid((reinterpret_cast<uintptr_t>(&_tss) >> 16) & 0xFF),
- flags1(0b10001001),
- flags2(0),
- base_high((reinterpret_cast<uintptr_t>(&_tss) >> 24) & 0xFF),
- base_upper(reinterpret_cast<uintptr_t>(&_tss) >> 32),
- reserved() {}
- };
- struct [[gnu::packed]] gdt {
- enum { Length = 6 };
- std::array<gdt_entry, Length - 1> entries;
- gdt_tss_entry tss_entry;
- gdt(const tss& _tss);
- };
- struct [[gnu::packed]] gdt_descriptor {
- std::uint16_t limit;
- std::uint64_t base;
- gdt_descriptor(const gdt& base)
- : limit(sizeof(gdt) - 1),
- base(reinterpret_cast<std::uintptr_t>(&base)) {}
- void load() const { gdt_load(this); }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement