-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidt.h
More file actions
86 lines (73 loc) · 2.11 KB
/
idt.h
File metadata and controls
86 lines (73 loc) · 2.11 KB
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
78
79
80
81
82
83
84
85
86
#pragma once
#include <stdbool.h>
#include <stdint.h>
// ========================================================
// IDT Gate Present bit
#define IDT_GATE_PRESENT (1 << 15)
// ========================================================
// IDT Gate DLP
#define IDT_GATE_DPL_RING0 0
#define IDT_GATE_DPL_RING1 (0x1 << 13)
#define IDT_GATE_DPL_RING2 (0x2 << 13)
#define IDT_GATE_DPL_RING3 (0x3 << 13)
// ========================================================
// IDT Gate Types
#define IDT_GATE_TASK (0x5 << 8)
#define IDT_GATE_16INT (0x6 << 8)
#define IDT_GATE_16TRAP (0x7 << 8)
#define IDT_GATE_32INT (0xE << 8)
#define IDT_GATE_32TRAP (0xF << 8)
// Interrupt Descriptor Table
struct __attribute__((__packed__)) idtr {
uint16_t len;
uint32_t offset;
};
// Interrupt Descriptor Table Gate
struct __attribute__((__packed__)) idt_gate {
uint16_t offset_low;
uint16_t segment;
uint16_t flags;
uint16_t offset_high;
};
struct idt_int_handler {
/*
* Handler function that is called when the interrupt is triggered.
*
* @param int_n interrupt number
* @param userdata the userdata passed at the registration
*
* @return true if the interrupt is handled; false if the interrupt is not
* handled (ex: the INT may come from an other device in case of shared
* interrupt lines).
*/
bool (*handler)(uint8_t int_n, void *userdata);
/*
* Arbitrary user data. Passed to the handler as a parameter.
*/
void *userdata;
// internal
struct idt_int_handler *_next; // included in this struct to push the
// allocation responsibility to the caller
};
/*
* Register a new handler for the specified interrupt.
* The interrupt handers are called in the order they registered.
* The handler is not called if a previous handler is already handled the
* interrupt.
*
* @param int_n interrupt number
* @param h handler
*/
void idt_reg_handler(uint8_t int_n, struct idt_int_handler *h);
/*
* Load a new IDT
*
* @param idtr Pointer to idtr to use
*/
void idt_set(struct idtr *idtr);
/*
* Get current IDT
*
* @param idtr Currently loaded idtr is returned here
*/
void idt_get(struct idtr *idtr);