feat(kernel): implement Phase 2 - IDT64, 8259 PIC, 100Hz PIT timer & PS/2 keyboard driver

This commit is contained in:
Adam Eehan committed 2026-10-23 09:37:54 +05:30
1 parent eec88c14c0
commit 7251770d7f
16 files changed
+863 -19

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
#ifndef AIRLYS_IDT_H
#define AIRLYS_IDT_H
#include <airlys/types.h>
/* 64-Bit Interrupt Descriptor Table Entry */
typedef struct __attribute__((packed)) {
uint16_t offset_low; /* Target address bits 0..15 */
uint16_t selector; /* Kernel code segment selector (0x08) */
uint8_t ist; /* Interrupt Stack Table index (bits 0..2) */
uint8_t type_attr; /* Type and attributes (flags) */
uint16_t offset_mid; /* Target address bits 16..31 */
uint32_t offset_high; /* Target address bits 32..63 */
uint32_t zero; /* Reserved (must be zero) */
} idt_entry_t;
/* IDTR register pointer */
typedef struct __attribute__((packed)) {
uint16_t limit;
uint64_t base;
} idt_ptr_t;
/* Register state saved on the stack by assembly ISR stubs */
typedef struct __attribute__((packed)) {
/* Pushed by common assembly stub (reverse order of push) */
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
uint64_t rbp, rdi, rsi, rdx, rcx, rbx, rax;
/* Pushed by individual ISR stub */
uint64_t int_no;
uint64_t err_code;
/* Pushed automatically by CPU hardware on interrupt */
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
} registers_t;
typedef void (*isr_handler_t)(registers_t*);
void idt_init(void);
void idt_set_gate(uint8_t num, uint64_t base, uint16_t sel, uint8_t flags);
void register_interrupt_handler(uint8_t n, isr_handler_t handler);
#endif /* AIRLYS_IDT_H */
+33
View File
@@ -0,0 +1,33 @@
#ifndef AIRLYS_IO_H
#define AIRLYS_IO_H
#include <airlys/types.h>
/* Direct Hardware I/O Port operations */
static inline void outb(uint16_t port, uint8_t val) {
__asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
}
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
__asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline void outw(uint16_t port, uint16_t val) {
__asm__ volatile ("outw %0, %1" : : "a"(val), "Nd"(port));
}
static inline uint16_t inw(uint16_t port) {
uint16_t ret;
__asm__ volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
/* Wait for I/O operations to complete (useful for PIC remapping) */
static inline void io_wait(void) {
outb(0x80, 0);
}
#endif /* AIRLYS_IO_H */
+8
View File
@@ -0,0 +1,8 @@
#ifndef AIRLYS_KEYBOARD_H
#define AIRLYS_KEYBOARD_H
#include <airlys/types.h>
void keyboard_init(void);
#endif /* AIRLYS_KEYBOARD_H */
+21
View File
@@ -0,0 +1,21 @@
#ifndef AIRLYS_PIC_H
#define AIRLYS_PIC_H
#include <airlys/types.h>
#define PIC1_COMMAND 0x20
#define PIC1_DATA 0x21
#define PIC2_COMMAND 0xA0
#define PIC2_DATA 0xA1
#define PIC_EOI 0x20
#define PIC1_OFFSET 32
#define PIC2_OFFSET 40
void pic_init(void);
void pic_send_eoi(uint8_t irq);
void pic_mask_irq(uint8_t irq);
void pic_unmask_irq(uint8_t irq);
#endif /* AIRLYS_PIC_H */
+10
View File
@@ -0,0 +1,10 @@
#ifndef AIRLYS_TIMER_H
#define AIRLYS_TIMER_H
#include <airlys/types.h>
void timer_init(uint32_t frequency_hz);
uint64_t timer_get_ticks(void);
void timer_sleep(uint32_t ticks);
#endif /* AIRLYS_TIMER_H */