Xyris
0.5
idt.hpp
Go to the documentation of this file.
1
/**
2
* @file idt.hpp
3
* @author Keeton Feavel (
[email protected]
)
4
* @brief Interrupt Descriptor Table header.
5
* @version 0.3
6
* @date 2019-11-15
7
*
8
* @copyright Copyright the Xyris Contributors (c) 2019
9
*
10
*/
11
12
#pragma once
13
#include <
Arch/i686/Arch.i686.hpp
>
14
#include <stdint.h>
15
16
namespace
IDT
{
17
18
enum
GateType
: uint8_t
19
{
20
TASK_GATE
= 0x5,
21
INTERRUPT_GATE_16_BIT
= 0x6,
22
TRAP_GATE_16_BIT
= 0x7,
23
INTERRUPT_GATE_32_BIT
= 0xE,
24
TRAP_GATE_32_BIT
= 0xF,
25
};
26
27
struct
[[gnu::packed]]
Segment
{
28
uint8_t
privilege
: 2;
// Ring privilege level
29
uint8_t
table
: 1;
// 1 = LDT entry, 0 = GDT entry
30
uint16_t
index
: 13;
// Index into table (LDT or GDT)
31
};
32
static_assert(
sizeof
(
struct
Segment
) == 2);
33
34
union
Offset
{
35
struct
[[gnu::packed]]
OffsetSections
36
{
37
uint16_t
low
: 16;
38
uint16_t
high
: 16;
39
}
section
;
40
uint32_t
value
;
41
};
42
43
struct
[[gnu::packed]]
Gate
{
44
uint16_t
offset_low
: 16;
// Lower 16 bits of handler function address
45
struct
Segment
selector;
// Kernel segment selector
46
uint8_t
reserved
: 8;
// Should always be 0
47
struct
48
{
49
enum
GateType
type : 4;
// Interrupt or Trap, 16 or 32 bit
50
uint8_t
offset
: 1;
// Should always be 0
51
uint8_t
privilege
: 2;
// Rings allowed to access via `INT` instruction (Ignored by hardware interrupts)
52
uint8_t
present
: 1;
// Gate is present
53
} flags;
54
uint16_t
offset_high
: 16;
// Higher 16 bits of handler function address
55
};
56
static_assert(
sizeof
(
struct
Gate
) == 8);
57
58
/**
59
* @brief Sets the handler function (via address) for a specific IDT.
60
*
61
* @param n IDT index
62
* @param handler Handler address
63
*/
64
void
setGate
(
int
n, uint32_t handler);
65
66
/**
67
* @brief Calls the lidt instruction and installs the IDT onto the CPU.
68
*
69
*/
70
void
init
();
71
72
}
// !namespace IDT
IDT::Segment::table
uint8_t table
Definition:
idt.hpp:29
IDT::INTERRUPT_GATE_16_BIT
@ INTERRUPT_GATE_16_BIT
Definition:
idt.hpp:21
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::privilege
uint8_t privilege
Definition:
idt.hpp:51
IDT::init
void init()
Calls the lidt instruction and installs the IDT onto the CPU.
Definition:
idt.cpp:41
IDT::TRAP_GATE_32_BIT
@ TRAP_GATE_32_BIT
Definition:
idt.hpp:24
Arch.i686.hpp
i686 architecture implementation of Arch.hpp
IDT::Gate::present
uint8_t present
Definition:
idt.hpp:52
IDT::TASK_GATE
@ TASK_GATE
Definition:
idt.hpp:20
IDT::Offset::section
struct IDT::Offset::OffsetSections section
IDT
Definition:
idt.cpp:16
IDT::Offset::OffsetSections
Definition:
idt.hpp:35
IDT::GateType
GateType
Definition:
idt.hpp:18
IDT::Segment::index
uint16_t index
Definition:
idt.hpp:30
IDT::Gate::offset
uint8_t offset
Definition:
idt.hpp:50
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::TRAP_GATE_16_BIT
@ TRAP_GATE_16_BIT
Definition:
idt.hpp:22
IDT::Segment
Definition:
idt.hpp:27
IDT::Gate::offset_low
uint16_t offset_low
Definition:
idt.hpp:44
IDT::Gate
Definition:
idt.hpp:43
Kernel
Arch
i686
idt.hpp
Generated by
1.8.17