Files
mango/arch/x86_64/include/arch/irq.h
2023-03-20 20:41:39 +00:00

80 lines
1.3 KiB
C

#ifndef ARCH_IRQ_H_
#define ARCH_IRQ_H_
#include <socks/compiler.h>
#include <socks/queue.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define NR_IDT_ENTRIES 48
typedef enum irq_vector {
IRQ0 = 32,
IRQ1,
IRQ2,
IRQ3,
IRQ4,
IRQ5,
IRQ6,
IRQ7,
IRQ8,
IRQ9,
IRQ10,
IRQ11,
IRQ12,
IRQ13,
IRQ14,
IRQ15,
} irq_vector_t;
typedef struct irq_hook {
queue_entry_t irq_entry;
int (*irq_callback)(void);
} irq_hook_t;
struct cpu_context {
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
uint64_t rdi, rsi, rbp, unused_rsp, rbx, rdx, rcx, rax;
uint64_t int_no, err_no;
uint64_t rip, cs, rflags, rsp, ss;
} __packed;
struct idt_entry {
uint16_t base_low;
uint16_t selector;
uint8_t always0;
uint8_t type : 4;
uint8_t zero : 1;
uint8_t dpl : 2;
uint8_t present : 1;
uint16_t base_middle;
uint32_t base_high;
uint32_t reserved;
} __packed;
struct idt {
struct idt_entry i_entries[NR_IDT_ENTRIES];
};
struct idt_ptr {
uint16_t i_limit;
uintptr_t i_base;
} __packed;
typedef void (*int_hook)(struct cpu_context *);
extern int idt_init(struct idt_ptr *idtp);
extern int idt_load(struct idt_ptr *idtp);
extern void hook_irq(irq_vector_t vec, irq_hook_t *hook);
extern void unhook_irq(irq_vector_t vec, irq_hook_t *hook);
#ifdef __cplusplus
}
#endif
#endif