2026-03-20 14:53:46 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include "stddef.h"
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
// thank you osdev.
|
|
|
|
|
#define PIC1 0x20 // master PIC
|
|
|
|
|
#define PIC2 0xA0 // slave PIC
|
|
|
|
|
#define PIC1_COMMAND PIC1
|
|
|
|
|
#define PIC1_DATA (PIC1+1)
|
|
|
|
|
#define PIC2_COMMAND PIC2
|
|
|
|
|
#define PIC2_DATA (PIC2+1)
|
|
|
|
|
#define PIC_EOI 0x20
|
|
|
|
|
#define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */
|
|
|
|
|
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
|
|
|
|
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
|
|
|
|
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
|
|
|
|
#define ICW1_INIT 0x10 /* Initialization - required! */
|
|
|
|
|
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
|
|
|
|
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
|
|
|
|
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
|
|
|
|
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
|
|
|
|
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
|
|
|
|
#define CASCADE_IRQ 2
|
2026-03-21 00:21:32 +01:00
|
|
|
#define IDT_MAX_DESCRIPTORS 32
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint16_t isr_low; // The lower 16 bits of the ISR's address
|
|
|
|
|
uint16_t kernel_cs; // The GDT segment selector that the CPU will load into CS before calling the ISR
|
|
|
|
|
uint8_t reserved; // Set to zero
|
|
|
|
|
uint8_t attributes; // Type and attributes; see the IDT page
|
|
|
|
|
uint16_t isr_high; // The higher 16 bits of the ISR's address
|
|
|
|
|
} __attribute__((packed)) idt_entry_t;
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint16_t limit;
|
|
|
|
|
uint32_t base;
|
|
|
|
|
} __attribute__((packed)) idtr_t;
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint32_t ds;
|
|
|
|
|
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
|
|
|
|
|
uint32_t int_no, err_code;
|
|
|
|
|
uint32_t eip, cs, eflags, useresp, ss;
|
|
|
|
|
} INT_registers_t;
|
2026-03-20 14:53:46 +01:00
|
|
|
|
|
|
|
|
inline void PIC_sendEOI(uint8_t irq) {
|
|
|
|
|
if (irq >= 8) { // slave also needs EOI
|
|
|
|
|
outb(PIC2_COMMAND,PIC_EOI);
|
|
|
|
|
}
|
|
|
|
|
outb(PIC1_COMMAND,PIC_EOI);
|
|
|
|
|
}
|
2026-03-21 00:21:32 +01:00
|
|
|
void PIC_remap(int offset1, int offset2);
|
|
|
|
|
__attribute__((noreturn))
|
|
|
|
|
void INT_exhand(INT_registers_t regs);
|
|
|
|
|
void INT_IRQ(uint8_t IRQ, INT_registers_t regs);
|
|
|
|
|
void idt_set_descriptor(uint8_t vector, void* isr, uint8_t flags);
|
|
|
|
|
void idt_init();
|
|
|
|
|
|
|
|
|
|
__attribute__((aligned(0x10)))
|
|
|
|
|
extern idt_entry_t idt[256];
|
|
|
|
|
extern idtr_t idtr;
|
|
|
|
|
extern void* isr_stub_table[];
|
|
|
|
|
extern void* irq_stub_table[];
|
|
|
|
|
extern uint8_t INT_vectors[IDT_MAX_DESCRIPTORS];
|
|
|
|
|
extern char *exception_messages[];
|