From 4a844820866094ff7d57435a16b7c23a9126814d Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 3 Aug 2022 21:34:58 +0200 Subject: amd64: cleanup the irq code, #define the magic numbers --- src/kernel/arch/amd64/driver/ps2.c | 5 +++-- src/kernel/arch/amd64/driver/ps2.h | 2 +- src/kernel/arch/amd64/interrupts/irq.c | 15 +++++++-------- src/kernel/arch/amd64/interrupts/irq.h | 4 ++++ src/kernel/arch/amd64/interrupts/isr.c | 11 +++++------ 5 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src/kernel/arch/amd64') diff --git a/src/kernel/arch/amd64/driver/ps2.c b/src/kernel/arch/amd64/driver/ps2.c index 8a5a078..be20c66 100644 --- a/src/kernel/arch/amd64/driver/ps2.c +++ b/src/kernel/arch/amd64/driver/ps2.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -18,8 +19,8 @@ static struct vfs_backend backend = BACKEND_KERN(is_ready, accept); void ps2_init(void) { vfs_mount_root_register("/ps2", &backend); } -void ps2_recv(uint8_t s) { - ring_put1b((void*)&backlog, s); +void ps2_irq(void) { + ring_put1b((void*)&backlog, port_in8(0x60)); if (blocked_on) { accept(blocked_on); blocked_on = NULL; diff --git a/src/kernel/arch/amd64/driver/ps2.h b/src/kernel/arch/amd64/driver/ps2.h index 54e8fb2..e1b1521 100644 --- a/src/kernel/arch/amd64/driver/ps2.h +++ b/src/kernel/arch/amd64/driver/ps2.h @@ -1,5 +1,5 @@ #pragma once #include -void ps2_recv(uint8_t s); +void ps2_irq(void); void ps2_init(void); diff --git a/src/kernel/arch/amd64/interrupts/irq.c b/src/kernel/arch/amd64/interrupts/irq.c index 74bc48c..b5e9255 100644 --- a/src/kernel/arch/amd64/interrupts/irq.c +++ b/src/kernel/arch/amd64/interrupts/irq.c @@ -6,21 +6,20 @@ static const int PIC1 = 0x20; static const int PIC2 = 0xA0; void irq_init(void) { - port_out8(PIC1, 0x11); /* start init sequence */ + port_out8(PIC1, 0x11); /* start init sequence */ port_out8(PIC2, 0x11); - port_out8(PIC1+1, 0x20); /* interrupt offsets */ - port_out8(PIC2+1, 0x30); + port_out8(PIC1+1, IRQ_IBASE); /* interrupt offsets */ + port_out8(PIC2+1, IRQ_IBASE + 8); - port_out8(PIC1+1, 0x4); /* just look at the osdev wiki lol */ + port_out8(PIC1+1, 0x4); port_out8(PIC2+1, 0x2); - - port_out8(PIC1+1, 0x1); /* 8086 mode */ + port_out8(PIC1+1, 0x1); port_out8(PIC2+1, 0x1); uint8_t mask = 0xff; - mask &= ~(1 << 1); // keyboard - mask &= ~(1 << 4); // COM1 + mask &= ~(1 << IRQ_PS2); + mask &= ~(1 << IRQ_COM1); port_out8(PIC1+1, mask); port_out8(PIC2+1, 0xff); diff --git a/src/kernel/arch/amd64/interrupts/irq.h b/src/kernel/arch/amd64/interrupts/irq.h index f523154..3340101 100644 --- a/src/kernel/arch/amd64/interrupts/irq.h +++ b/src/kernel/arch/amd64/interrupts/irq.h @@ -2,5 +2,9 @@ #include #include +#define IRQ_IBASE 0x20 +#define IRQ_PS2 1 +#define IRQ_COM1 4 + void irq_init(void); void irq_eoi(uint8_t line); diff --git a/src/kernel/arch/amd64/interrupts/isr.c b/src/kernel/arch/amd64/interrupts/isr.c index bd560f5..71da27b 100644 --- a/src/kernel/arch/amd64/interrupts/isr.c +++ b/src/kernel/arch/amd64/interrupts/isr.c @@ -25,18 +25,17 @@ void isr_stage3(int interrupt, uint64_t *stackframe) { if (interrupt == 0xe || interrupt == 0xd) stackframe++; switch (interrupt) { case 0x34: - asm("nop" ::: "memory"); isr_test_interrupt_called = true; return; - case 0x21: // keyboard irq - ps2_recv(port_in8(0x60)); - irq_eoi(1); + case IRQ_IBASE + IRQ_PS2: + ps2_irq(); + irq_eoi(IRQ_PS2); return; - case 0x24: // COM1 irq + case IRQ_IBASE + IRQ_COM1: serial_irq(); - irq_eoi(1); + irq_eoi(IRQ_COM1); return; default: -- cgit v1.2.3