furix
cute os
include/arch/x86_64/idt.h
2039 bytes raw
1#ifndef FURIX_ARCH_X86_64_IDT_H
2#define FURIX_ARCH_X86_64_IDT_H
3
4#include <io.h>
5#include <types.h>
6
7/* install the kernel IDT, with IST stacks wired up */
8void idt_init(void);
9
10/*
11 * the IDT the AP trampoline loads: same stubs, but no IST entries (an AP has
12 * no TSS) and gates selecting the trampoline's 64-bit code segment. written
13 * by idt_init(); nothing else should touch it.
14 */
15extern struct desc_ptr idt_ap_pointer;
16
17/*
18 * selector of the 64-bit code segment in the AP trampoline's flat GDT. must
19 * match arch/x86_64/ap_boot.S: index 3, so 0x18. the BSP's IDT uses 0x08 from
20 * the GDT in gdt.c, which is a 32-bit segment and so unusable from a long-mode
21 * interrupt gate.
22 */
23#define AP_CODE_SELECTOR_64 0x18
24
25/* register a C handler for one vector; NULL restores the halting default */
26void idt_set_handler(uint8_t vector, void (*handler)(void));
27
28/*
29 * the interrupt frame built by the assembly entry path in isr.S. field order
30 * and offsets must match the push sequence there; assert_layout() in idt.c
31 * checks the ones the C code actually reads.
32 */
33struct interrupt_frame {
34 /* pushed by isr_common, lowest address first */
35 uint64_t rax;
36 uint64_t rbx;
37 uint64_t rcx;
38 uint64_t rdx;
39 uint64_t rbp;
40 uint64_t rsi;
41 uint64_t rdi;
42 uint64_t r8;
43 uint64_t r9;
44 uint64_t r10;
45 uint64_t r11;
46 uint64_t r12;
47 uint64_t r13;
48 uint64_t r14;
49 uint64_t r15;
50
51 /* pushed by the stub, then by the CPU */
52 uint64_t vector;
53 uint64_t error_code;
54 uint64_t rip;
55 uint64_t cs;
56 uint64_t rflags;
57 uint64_t rsp;
58 uint64_t ss;
59};
60
61/* called from the assembly stubs with a pointer to the frame above */
62void interrupt_dispatch(const struct interrupt_frame *frame);
63
64/* vectors used by the kernel itself */
65#define VECTOR_NMI 2
66#define VECTOR_DOUBLE_FAULT 8
67#define VECTOR_GENERAL_PROTECTION 13
68#define VECTOR_PAGE_FAULT 14
69#define VECTOR_SPURIOUS 0xFF
70
71/* free vector for IPIs and other kernel-generated interrupts */
72#define VECTOR_IPI_BASE 0x30
73#define VECTOR_IPI_TIMER 0x30
74
75#endif /* FURIX_ARCH_X86_64_IDT_H */