This commit is contained in:
alexvoste
2026-05-07 02:22:25 +03:00
commit 1a9fd27a31
226 changed files with 29188 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#ifndef IDT_H
#define IDT_H
#include <stdint.h>
#include <stdbool.h>
#define IDT_MAX_DESCRIPTORS 256
#define IS_FLAG_SETTED(x, flag) ((x) | (flag))
#define FLAG_SET(x, flag) ((x) |= (flag))
#define FLAG_UNSET(x, flag) ((x) &= ~(flag))
typedef enum {
IDT_FLAG_GATE_TASK = 0x5,
IDT_FLAG_GATE_16BIT_INT = 0x6,
IDT_FLAG_GATE_16BIT_TRAP = 0x7,
IDT_FLAG_GATE_32BIT_INT = 0xE,
IDT_FLAG_GATE_32BIT_TRAP = 0xF,
IDT_FLAG_RING0 = (0 << 5),
IDT_FLAG_RING1 = (1 << 5),
IDT_FLAG_RING2 = (2 << 5),
IDT_FLAG_RING3 = (3 << 5),
IDT_FLAG_PRESENT = 0x80,
} IDT_FLAGS;
typedef struct {
uint16_t base_low;
uint16_t kernel_cs;
uint8_t ist;
uint8_t attributes;
uint16_t base_mid;
uint32_t base_high;
uint32_t reserved;
}__attribute__((packed)) idt_entry_t;
typedef struct {
uint16_t limit;
idt_entry_t *base;
}__attribute__((packed)) idtr_t;
extern idtr_t idtr;
void setup_interrupt_descriptor_table(uint64_t kernel_code_segment);
void idt_load(void);
#endif
+77
View File
@@ -0,0 +1,77 @@
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
#include <stdint.h>
struct int_frame_t {
uint64_t ds;
uint64_t r15;
uint64_t r14;
uint64_t r13;
uint64_t r12;
uint64_t r11;
uint64_t r10;
uint64_t r9;
uint64_t r8;
uint64_t rbp;
uint64_t rdi;
uint64_t rsi;
uint64_t rdx;
uint64_t rcx;
uint64_t rbx;
uint64_t rax;
uint64_t interrupt;
uint64_t error;
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
} __attribute__((packed));
typedef void (*int_handler_f)(struct int_frame_t* frame);
typedef struct {
uint64_t vector;
int_handler_f handler;
} int_desc_t;
#define __CHECK_HANDLER(fn) \
_Static_assert( \
__builtin_types_compatible_p( \
typeof(fn), void (*)(struct int_frame_t *)), \
"Invalid interrupt handler signature")
#define __CONCAT(a, b) a##b
#define __UNIQUE_NAME(base) __CONCAT(base, __COUNTER__)
#define DEFINE_ISR(_vector, _name) \
static void _name(struct int_frame_t *frame); \
static const int_desc_t __UNIQUE_NAME(__isr_desc_##_name) \
__attribute__((used, section(".isr_handlers"))) = { \
.vector = (_vector), \
.handler = _name, \
}; \
static void _name(struct int_frame_t *frame)
#define DEFINE_IRQ(_vector, _name) \
static void _name(struct int_frame_t *frame); \
static const int_desc_t __UNIQUE_NAME(__irq_desc_##_name) \
__attribute__((used, section(".irq_handlers"))) = { \
.vector = (_vector), \
.handler = _name, \
}; \
static void _name(struct int_frame_t *frame)
#define IPI_RESCHEDULE_VECTOR 0x40
#define IPI_TLB_SHOOTDOWN 0x41
void init_interrupt_system();
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef IRQ_H
#define IRQ_H
#include <stdint.h>
#include "interrupts.h"
#define IRQ_INTERRUPTS_COUNT 224
static const char* irq_default_names[] __attribute__((unused)) = {
"IRQ0 timer",
"IRQ1 keyboard",
"IRQ2 cascade",
"IRQ3 COM2",
"IRQ4 COM1",
"IRQ5 LPT2",
"IRQ6 floppy",
"IRQ7 LPT1",
"IRQ8 RTC",
"IRQ9 ACPI",
"IRQ10 reserved",
"IRQ11 reserved",
"IRQ12 mouse",
"IRQ13 FPU",
"IRQ14 ATA1",
"IRQ15 ATA2"
};
void irq_common_handler(struct int_frame_t* regs);
void setup_defined_irq_handlers(void);
#endif
+81
View File
@@ -0,0 +1,81 @@
#ifndef ISR_H
#define ISR_H
#include "interrupts.h"
#define ISR_EXCEPTION_COUNT 32
enum {
EXCEPTION_DIVIDE_ERROR = 0,
EXCEPTION_DEBUG,
EXCEPTION_NMI,
EXCEPTION_BREAKPOINT,
EXCEPTION_OVERFLOW,
EXCEPTION_BOUND_RANGE,
EXCEPTION_INVALID_OPCODE,
EXCEPTION_DEVICE_NOT_AVAILABLE,
EXCEPTION_DOUBLE_FAULT,
EXCEPTION_COPROCESSOR_SEGMENT_OVERRUN,
EXCEPTION_INVALID_TSS,
EXCEPTION_SEGMENT_NOT_PRESENT,
EXCEPTION_STACK_SEGMENT_FAULT,
EXCEPTION_GENERAL_PROTECTION_FAULT,
EXCEPTION_PAGE_FAULT,
EXCEPTION_RESERVED15,
EXCEPTION_X87_FPU_ERROR,
EXCEPTION_ALIGNMENT_CHECK,
EXCEPTION_MACHINE_CHECK,
EXCEPTION_SIMD_FPU_EXCEPTION,
EXCEPTION_VIRTUALIZATION_EXCEPTION,
EXCEPTION_RESERVED21,
EXCEPTION_RESERVED22,
EXCEPTION_RESERVED23,
EXCEPTION_RESERVED24,
EXCEPTION_RESERVED25,
EXCEPTION_RESERVED26,
EXCEPTION_RESERVED27,
EXCEPTION_RESERVED28,
EXCEPTION_RESERVED29,
EXCEPTION_SECURITY_EXCEPTION = 30,
EXCEPTION_RESERVED31
};
static const char* exception_names[] __attribute__((unused)) = {
"Divide Error",
"Debug",
"Non-Maskable Interrupt",
"Breakpoint",
"Overflow",
"Bound Range Exceeded",
"Invalid Opcode",
"Device Not Available",
"Double Fault",
"Coprocessor Segment Overrun",
"Invalid TSS",
"Segment Not Present",
"Stack Segment Fault",
"General Protection Fault",
"Page Fault",
"Reserved",
"x87 Floating-Point Exception",
"Alignment Check",
"Machine Check",
"SIMD Floating-Point Exception",
"Virtualization Exception",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Security Exception",
"Reserved"
};
void isr_common_handler(struct int_frame_t* regs);
void setup_defined_isr_handlers(void);
#endif