summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2022-03-27 14:47:50 +0200
committerdzwdz2022-03-27 14:47:50 +0200
commit45283c43460900d080478973c873339b5db3013e (patch)
treecde5d7afdf54fa57b07c8aa5f2a61cc663261445 /src/kernel
parentcc16c5d9847da67b3ff369c13712fcae4bebe2ae (diff)
kernel/tty: poll only on IRQs, don't burn cycles
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/arch/i386/interrupts/irq.c21
-rw-r--r--src/kernel/arch/i386/interrupts/isr.c4
-rw-r--r--src/kernel/arch/i386/tty/serial.c4
-rw-r--r--src/kernel/arch/i386/tty/tty.c1
4 files changed, 15 insertions, 15 deletions
diff --git a/src/kernel/arch/i386/interrupts/irq.c b/src/kernel/arch/i386/interrupts/irq.c
index cb33bc8..7b8c166 100644
--- a/src/kernel/arch/i386/interrupts/irq.c
+++ b/src/kernel/arch/i386/interrupts/irq.c
@@ -5,27 +5,24 @@
static const int PIC1 = 0x20;
static const int PIC2 = 0xA0;
-static void irq_unmask(uint8_t line) {
- uint16_t pic = line < 8 ? PIC1 : PIC2;
- line &= 7;
-
- port_out8(pic+1, port_in8(pic+1) & ~(1 << line));
-}
-
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(PIC1+1, 0x20); /* interrupt offsets */
port_out8(PIC2+1, 0x30);
- port_out8(PIC1+1, 0x4); /* just look at the osdev wiki lol */
+ port_out8(PIC1+1, 0x4); /* just look at the osdev wiki lol */
port_out8(PIC2+1, 0x2);
- port_out8(PIC1+1, 0x1); /* 8086 mode */
+ port_out8(PIC1+1, 0x1); /* 8086 mode */
port_out8(PIC2+1, 0x1);
- port_out8(PIC1+1, 0xfd); /* mask */
+ uint8_t mask = 0xff;
+ mask &= ~(1 << 1); // keyboard
+ mask &= ~(1 << 4); // COM1
+
+ port_out8(PIC1+1, mask);
port_out8(PIC2+1, 0xff);
}
diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c
index 1448f44..cc90fae 100644
--- a/src/kernel/arch/i386/interrupts/isr.c
+++ b/src/kernel/arch/i386/interrupts/isr.c
@@ -24,6 +24,10 @@ void isr_stage3(int interrupt) {
irq_eoi(1);
return;
+ case 0x24:; // COM1 irq
+ irq_eoi(1);
+ return;
+
default:
// TODO check if the exception was in the kernel
process_kill(process_current, interrupt);
diff --git a/src/kernel/arch/i386/tty/serial.c b/src/kernel/arch/i386/tty/serial.c
index e77ff5c..054f956 100644
--- a/src/kernel/arch/i386/tty/serial.c
+++ b/src/kernel/arch/i386/tty/serial.c
@@ -14,15 +14,13 @@ static void serial_selftest(void) {
void serial_init(void) {
// see https://www.sci.muni.cz/docs/pc/serport.txt
-
- port_out8(COM1 + 1, 0x00); // disable interrupts, we won't be using them
-
// set baud rate divisor
port_out8(COM1 + 3, 0b10000000); // enable DLAB
port_out8(COM1 + 0, 0x01); // divisor = 1 (low byte)
port_out8(COM1 + 1, 0x00); // (high byte)
port_out8(COM1 + 3, 0b00000011); // 8 bits, no parity, one stop bit
+ port_out8(COM1 + 1, 0x01); // enable the Data Ready IRQ
port_out8(COM1 + 2, 0b11000111); // enable FIFO with 14-bit trigger level (???)
serial_selftest();
diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c
index f3fecf3..a63c16a 100644
--- a/src/kernel/arch/i386/tty/tty.c
+++ b/src/kernel/arch/i386/tty/tty.c
@@ -19,6 +19,7 @@ void tty_read(char *buf, size_t len) {
for (;;) {
if (serial_poll_read(&buf[i])) break;
if (keyboard_poll_read(&buf[i])) break;
+ asm("hlt" ::: "memory");
}
}
}