AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
idt.c
Go to the documentation of this file.
1
5
6#include <core/system.h>
7#include "cpu.h"
8
9#if __pragma_pack
10#pragma pack(1)
11#endif
12static struct idt_entry {
13 uint32_t offset_lo : 16; /* the handler's address, bits 0 to 15 */
14 uint32_t selector : 16; /* the code segment it runs in */
15 uint32_t _unused : 8; /* unused, 0 */
16 uint32_t flags : 5; /* 01110: an interrupt gate */
17 uint32_t dpl : 2; /* the privilege level that may use int on it */
18 uint32_t p : 1; /* present */
19 uint16_t offset_hi : 16; /* the handler's address, bits 16 to 31 */
20#if ARCH_BITS==64
21 uint32_t offset_ext: 32; /* the handler's address, bits 32 to 63 */
22 uint32_t : 32; /* reserved */
23#endif
25
30#if __pragma_pack
31#pragma pack()
32#endif
33
34#define DPL0 0
35#define DPL3 3
36
46{
47 idt[id].offset_lo = (offset >> 0x00) & 0xFFFF;
48 idt[id].offset_hi = (offset >> 0x10) & 0xFFFF;
49#if ARCH_BITS==64
50 idt[id].offset_ext = (offset >> 0x20) & 0xFFFFFFFF;
51#endif
52
53 idt[id].selector = 0x8;
54 idt[id].p = 1;
55 idt[id].dpl = DPL0;
56 idt[id].flags = 0x0E;
57}
58
68{
69 idt[id].offset_lo = (offset >> 0x00) & 0xFFFF;
70 idt[id].offset_hi = (offset >> 0x10) & 0xFFFF;
71#if ARCH_BITS==64
72 idt[id].offset_ext = (offset >> 0x20) & 0xFFFFFFFF;
73#endif
74
75 idt[id].selector = 0x8;
76 idt[id].p = 1;
77 idt[id].dpl = DPL3;
78 idt[id].flags = 0x0E;
79}
80
83{
84 idt_pointer.limit = sizeof(idt) - 1;
87}
void x86_lidt(uintptr_t)
#define DPL0
Definition gdt.c:28
#define DPL3
Definition gdt.c:29
struct idt_ptr idt_pointer
void x86_idt_gate_user_set(uint32_t id, uintptr_t offset)
Sets an interrupt gate that user mode may raise with int too: the system call vector.
Definition idt.c:67
void x86_idt_gate_set(uint32_t id, uintptr_t offset)
Sets an interrupt gate that only the hardware (and the kernel) can raise: an exception or a device in...
Definition idt.c:45
void x86_idt_setup()
Loads the IDT on the running CPU.
Definition idt.c:82
static struct idt_entry idt[256]
#define __packed
Definition system.h:30
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
unsigned short int uint16_t
Definition stddef.h:21
Definition idt.c:12
uint32_t flags
Definition idt.c:16
uint32_t _unused
Definition idt.c:15
uint32_t offset_ext
Definition idt.c:21
uint16_t offset_hi
Definition idt.c:19
uint32_t dpl
Definition idt.c:17
uint32_t offset_lo
Definition idt.c:13
uint32_t p
Definition idt.c:18
uint32_t selector
Definition idt.c:14
Definition idt.c:26
uintptr_t base
Definition idt.c:28
uint16_t limit
Definition idt.c:27