forked from uchan-nos/mikanos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupt.hpp
77 lines (64 loc) · 1.68 KB
/
interrupt.hpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @file interrupt.hpp
*
* 割り込み用のプログラムを集めたファイル.
*/
#pragma once
#include <array>
#include <cstdint>
#include <deque>
#include "x86_descriptor.hpp"
#include "message.hpp"
union InterruptDescriptorAttribute {
uint16_t data;
struct {
uint16_t interrupt_stack_table : 3;
uint16_t : 5;
DescriptorType type : 4;
uint16_t : 1;
uint16_t descriptor_privilege_level : 2;
uint16_t present : 1;
} __attribute__((packed)) bits;
} __attribute__((packed));
struct InterruptDescriptor {
uint16_t offset_low;
uint16_t segment_selector;
InterruptDescriptorAttribute attr;
uint16_t offset_middle;
uint32_t offset_high;
uint32_t reserved;
} __attribute__((packed));
extern std::array<InterruptDescriptor, 256> idt;
constexpr InterruptDescriptorAttribute MakeIDTAttr(
DescriptorType type,
uint8_t descriptor_privilege_level,
bool present = true,
uint8_t interrupt_stack_table = 0) {
InterruptDescriptorAttribute attr{};
attr.bits.interrupt_stack_table = interrupt_stack_table;
attr.bits.type = type;
attr.bits.descriptor_privilege_level = descriptor_privilege_level;
attr.bits.present = present;
return attr;
}
const int kISTForTimer = 1; // index of the interrupt stack table
void SetIDTEntry(InterruptDescriptor& desc,
InterruptDescriptorAttribute attr,
uint64_t offset,
uint16_t segment_selector);
class InterruptVector {
public:
enum Number {
kXHCI = 0x40,
kLAPICTimer = 0x41,
};
};
struct InterruptFrame {
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
};
void NotifyEndOfInterrupt();
void InitializeInterrupt();