diff options
Diffstat (limited to 'src/kernel/arch')
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.c | 28 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.h | 7 | ||||
-rw-r--r-- | src/kernel/arch/i386/interrupts/isr.c | 4 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/keyboard.c | 30 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/keyboard.h | 6 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/ps2_keymap.h | 23 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/tty.c | 5 |
7 files changed, 39 insertions, 64 deletions
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c new file mode 100644 index 0000000..1af3166 --- /dev/null +++ b/src/kernel/arch/i386/driver/ps2.c @@ -0,0 +1,28 @@ +#include <kernel/arch/i386/driver/ps2.h> +#include <kernel/arch/i386/interrupts/irq.h> +#include <shared/mem.h> + +#define BACKLOG_CAPACITY 16 + +/* TODO move away from tty/ */ + +static volatile uint8_t backlog[BACKLOG_CAPACITY] = {}; +static volatile size_t backlog_size = 0; + +void ps2_recv(uint8_t s) { + if (backlog_size >= BACKLOG_CAPACITY) return; + backlog[backlog_size++] = s; +} + +size_t ps2_read(uint8_t *buf, size_t max_len) { + irq_interrupt_flag(true); + while (backlog_size == 0) + asm("hlt" ::: "memory"); + irq_interrupt_flag(false); + + size_t len = backlog_size; + if (len > max_len) len = max_len; + backlog_size = 0; + memcpy(buf, (void*)backlog, len); + return len; +} diff --git a/src/kernel/arch/i386/driver/ps2.h b/src/kernel/arch/i386/driver/ps2.h new file mode 100644 index 0000000..4b56056 --- /dev/null +++ b/src/kernel/arch/i386/driver/ps2.h @@ -0,0 +1,7 @@ +#pragma once +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +void ps2_recv(uint8_t scancode); +size_t ps2_read(uint8_t *buf, size_t max_len); diff --git a/src/kernel/arch/i386/interrupts/isr.c b/src/kernel/arch/i386/interrupts/isr.c index 001827a..e3bb6d6 100644 --- a/src/kernel/arch/i386/interrupts/isr.c +++ b/src/kernel/arch/i386/interrupts/isr.c @@ -1,7 +1,7 @@ +#include <kernel/arch/i386/driver/ps2.h> #include <kernel/arch/i386/interrupts/irq.h> #include <kernel/arch/i386/interrupts/isr.h> #include <kernel/arch/i386/port_io.h> -#include <kernel/arch/i386/tty/keyboard.h> #include <kernel/arch/io.h> #include <kernel/panic.h> #include <kernel/proc.h> @@ -20,7 +20,7 @@ void isr_stage3(int interrupt) { return; case 0x21: // keyboard irq - keyboard_recv(port_in8(0x60)); + ps2_recv(port_in8(0x60)); irq_eoi(1); return; diff --git a/src/kernel/arch/i386/tty/keyboard.c b/src/kernel/arch/i386/tty/keyboard.c deleted file mode 100644 index a321aab..0000000 --- a/src/kernel/arch/i386/tty/keyboard.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <kernel/arch/i386/tty/keyboard.h> -#include <kernel/arch/i386/tty/ps2_keymap.h> - -static volatile bool keyboard_pressed = false; -static volatile char keyboard_char; - -static bool keys[0x80] = {0}; - -void keyboard_recv(uint8_t s) { - bool shift = keys[0x2A] || keys[0x36]; - bool down = !(s & 0x80); - s &= 0x7f; - keys[s] = down; - - char c = shift ? keymap_upper[s] : keymap_lower[s]; - - if (down && c) { - keyboard_char = c; - keyboard_pressed = true; - } -} - -bool keyboard_poll_read(char *c) { - if (!keyboard_pressed) return false; - keyboard_pressed = false; - *c = keyboard_char; - return true; -} - - diff --git a/src/kernel/arch/i386/tty/keyboard.h b/src/kernel/arch/i386/tty/keyboard.h deleted file mode 100644 index c3a8232..0000000 --- a/src/kernel/arch/i386/tty/keyboard.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include <stdbool.h> -#include <stdint.h> - -bool keyboard_poll_read(char *c); -void keyboard_recv(uint8_t scancode); diff --git a/src/kernel/arch/i386/tty/ps2_keymap.h b/src/kernel/arch/i386/tty/ps2_keymap.h deleted file mode 100644 index 891b9d7..0000000 --- a/src/kernel/arch/i386/tty/ps2_keymap.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -static const char keymap_lower[] = { - '\0', '\0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\r', '\0', 'a', 's', - 'd', 'f', 'g', 'h', 'j', 'k', 'l', '\0', '\'', '`', '\0', '\\', 'z', 'x', 'c', 'v', - 'b', 'n', 'm', ',', '.', '/', '\0', '*', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '8', '9', '-', '4', '5', '6', '+', '1', - '2', '3', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', -}; - -static const char keymap_upper[] = { - '\0', '\0', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b', '\t', - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\r', '\0', 'A', 'S', - 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', '\0', '|', 'Z', 'X', 'C', 'V', - 'B', 'N', 'M', '<', '>', '?', '\0', '*', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '8', '9', '-', '4', '5', '6', '+', '1', - '2', '3', '0', '.', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', -}; diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c index a63c16a..ebe0fd3 100644 --- a/src/kernel/arch/i386/tty/tty.c +++ b/src/kernel/arch/i386/tty/tty.c @@ -1,5 +1,4 @@ #include <kernel/arch/i386/interrupts/irq.h> -#include <kernel/arch/i386/tty/keyboard.h> #include <kernel/arch/i386/tty/serial.h> #include <kernel/arch/i386/tty/vga.h> #include <kernel/arch/io.h> @@ -17,11 +16,11 @@ void tty_read(char *buf, size_t len) { irq_interrupt_flag(true); for (size_t i = 0; i < len; i++) { for (;;) { - if (serial_poll_read(&buf[i])) break; - if (keyboard_poll_read(&buf[i])) break; + if (serial_poll_read(&buf[i])) break; asm("hlt" ::: "memory"); } } + irq_interrupt_flag(false); } void tty_write(const char *buf, size_t len) { |