Xyris  0.5
idt.cpp
Go to the documentation of this file.
1 /**
2  * @file idt.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief
5  * @version 0.3
6  * @date 2019-11-15
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2019
9  *
10  */
11 #include <Arch/i686/idt.hpp>
12 #include <Arch/i686/regs.hpp>
13 
14 #define ARCH_IDT_MAX_ENTRIES 256
15 
16 namespace IDT {
17 
19 struct Registers::IDTR idtr;
20 
21 void setGate(int n, uint32_t handler_addr)
22 {
23  struct Gate* gate = &idt[n];
24  union Offset offset = { .value = handler_addr };
25  gate->offset_low = offset.section.low;
26  gate->selector = {
27  .privilege = 0,
28  .table = 0,
29  .index = 1,
30  };
31  gate->reserved = 0;
32  gate->flags = {
34  .offset = 0,
35  .privilege = 0,
36  .present = 1,
37  };
38  gate->offset_high = offset.section.high;
39 }
40 
41 void init()
42 {
43  // Update the IDT table
44  idtr.size = sizeof(idt) - 1;
45  idtr.base = (uint32_t)&idt;
46  // Load the IDT table into the IDT register
47  asm volatile(
48  "lidt (%0)"
49  :
50  : "r"(&idtr)
51  : "memory");
52 }
53 
54 } // !namespace IDT
ARCH_IDT_MAX_ENTRIES
#define ARCH_IDT_MAX_ENTRIES
Definition: idt.cpp:14
IDT::INTERRUPT_GATE_32_BIT
@ INTERRUPT_GATE_32_BIT
Definition: idt.hpp:23
IDT::Offset::value
uint32_t value
Definition: idt.hpp:40
IDT::Gate::selector
struct Segment selector
Definition: idt.hpp:45
IDT::idt
struct Gate idt[ARCH_IDT_MAX_ENTRIES]
Definition: idt.cpp:18
IDT::Gate::type
enum GateType type
Definition: idt.hpp:49
IDT::init
void init()
Calls the lidt instruction and installs the IDT onto the CPU.
Definition: idt.cpp:41
regs.hpp
i686 control register definitions. C & C++ compatible header.
IDT::Offset::section
struct IDT::Offset::OffsetSections section
IDT
Definition: idt.cpp:16
IDT::Gate::offset_high
uint16_t offset_high
Definition: idt.hpp:54
IDT::Gate::reserved
uint8_t reserved
Definition: idt.hpp:46
IDT::Segment::privilege
uint8_t privilege
Definition: idt.hpp:28
IDT::Offset
Definition: idt.hpp:34
IDT::Offset::OffsetSections::low
uint16_t low
Definition: idt.hpp:37
IDT::setGate
void setGate(int n, uint32_t handler_addr)
Sets the handler function (via address) for a specific IDT.
Definition: idt.cpp:21
IDT::Offset::OffsetSections::high
uint16_t high
Definition: idt.hpp:38
idt.hpp
Interrupt Descriptor Table header.
IDT::Gate::offset_low
uint16_t offset_low
Definition: idt.hpp:44
IDT::idtr
struct Registers::IDTR idtr
Definition: idt.cpp:19
IDT::Gate::flags
struct IDT::Gate::@0 flags
IDT::Gate
Definition: idt.hpp:43