Advertisement
My-Bad-2

idt_new.hpp

Nov 1st, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | Source Code | 0 0
  1. namespace system {
  2. namespace interrupts {
  3. enum type {
  4.     User = 0x60,
  5.     Gate = 0x8E,
  6.     Trap = 0xEF,
  7. };
  8.  
  9. struct [[gnu::packed]] idt_entry {
  10.     std::uint16_t offset_low;
  11.     std::uint16_t code_segment;
  12.     std::uint8_t ist;
  13.     std::uint8_t attributes;
  14.     std::uint16_t offset_mid;
  15.     std::uint32_t offset_high;
  16.     std::uint32_t zero;
  17.  
  18.     idt_entry() = default;
  19.  
  20.     idt_entry(std::uintptr_t handler, uint8_t ist, uint8_t attributes)
  21.         : offset_low(handler),
  22.           code_segment(0x8),
  23.           ist(ist),
  24.           attributes(attributes),
  25.           offset_mid(handler >> 16),
  26.           offset_high(handler >> 32),
  27.           zero(0) {}
  28. };
  29.  
  30. struct [[gnu::packed, gnu::aligned(0x10)]] idt {
  31.     enum { Length = 256 };
  32.     // standard stl array
  33.     std::array<idt_entry, Length> entries{};
  34. };
  35.  
  36. struct [[gnu::packed]] idt_descriptor {
  37.     std::uint16_t limit;
  38.     std::uint64_t base;
  39.  
  40.     idt_descriptor(std::uint16_t limit, std::uint64_t base)
  41.         : limit(limit), base(base) {}
  42.  
  43.     idt_descriptor(idt& _idt)
  44.         : limit(sizeof(idt) - 1),
  45.           base(reinterpret_cast<std::uint64_t>(&_idt)) {}
  46.  
  47.     void load() { load_idt(this); }
  48. };
  49.  
  50. void init();
  51. }  // namespace interrupts
  52. }  // namespace system
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement