input: Implement console input handling and add shell for real this time
Self explanatory, we finally have a working ish shell Now we need to do some more stuff or something, probably work on a fork or something Signed-off-by: kaguya <vpshinomiya@protonmail.com> Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -5,17 +5,50 @@
|
||||
#include <stddef.h>
|
||||
#include "mm/memory.h"
|
||||
#include "libk/string.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* Event ring-buffer
|
||||
* ------------------------------------------------------------------ */
|
||||
#define INPUT_BUF_SIZE 512
|
||||
#define CONSOLE_BUF_SIZE 256
|
||||
|
||||
static char s_console_buf[CONSOLE_BUF_SIZE];
|
||||
static size_t s_console_rpos = 0;
|
||||
static size_t s_console_wpos = 0;
|
||||
|
||||
static input_event_t s_buf[INPUT_BUF_SIZE];
|
||||
static size_t s_rpos = 0;
|
||||
static size_t s_wpos = 0;
|
||||
static spinlock_t s_lock = SPINLOCK_INIT;
|
||||
|
||||
/* Called from IRQ context */
|
||||
void input_push_char(char c)
|
||||
{
|
||||
spinlock_acquire_or_wait(&s_lock);
|
||||
size_t next = (s_console_wpos + 1) % CONSOLE_BUF_SIZE;
|
||||
if (next != s_console_rpos) { /* drop if full */
|
||||
s_console_buf[s_console_wpos] = c;
|
||||
s_console_wpos = next;
|
||||
}
|
||||
spinlock_drop(&s_lock);
|
||||
}
|
||||
|
||||
int input_read_console(void *buf, size_t len)
|
||||
{
|
||||
uint8_t *p = buf;
|
||||
size_t count = 0;
|
||||
|
||||
spinlock_acquire_or_wait(&s_lock);
|
||||
while (count < len && s_console_rpos != s_console_wpos) {
|
||||
p[count++] = s_console_buf[s_console_rpos];
|
||||
s_console_rpos = (s_console_rpos + 1) % CONSOLE_BUF_SIZE;
|
||||
}
|
||||
spinlock_drop(&s_lock);
|
||||
|
||||
return (int)count; /* 0 = no data yet (non-blocking) */
|
||||
}
|
||||
|
||||
static void push_event(const input_event_t *ev)
|
||||
{
|
||||
spinlock_acquire_or_wait(&s_lock);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* Generic input event types
|
||||
@@ -53,6 +54,9 @@ void input_push_mouse_rel(int16_t dx, int16_t dy);
|
||||
void input_push_mouse_btn(uint8_t button, bool pressed);
|
||||
void input_push_mouse_wheel(int8_t delta);
|
||||
|
||||
void input_push_char(char c);
|
||||
int input_read_console(void *buf, size_t len);
|
||||
|
||||
/* Consumer API */
|
||||
bool input_poll(input_event_t *out); /* non-blocking; false if empty */
|
||||
bool input_has_event(void);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "arch/x86_64/sys/ioapic.h"
|
||||
#include "arch/x86_64/sys/apic.h"
|
||||
#include "libk/stdio.h"
|
||||
#include "drivers/video/render.h"
|
||||
|
||||
/* ── PS/2 I/O ports ───────────────────────────────────────────────────────── */
|
||||
#define PS2_DATA_PORT 0x60 /* Read: scancode / Write: command data */
|
||||
@@ -150,9 +151,15 @@ void ps2_kbd_handler(Registers *regs)
|
||||
/* ── Push event ──────────────────────────────────────────────────── */
|
||||
input_push_key(scancode, ascii, pressed);
|
||||
|
||||
/* Optionally echo to debug port for development */
|
||||
|
||||
if (pressed && ascii) {
|
||||
/* e9_putc(ascii); ← uncomment if you have e9 debug output */
|
||||
input_push_char(ascii);
|
||||
|
||||
if (ascii == '\b') {
|
||||
backspace();
|
||||
} else {
|
||||
putchar(ascii);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "libk/stdio.h"
|
||||
#include "mm/memory.h"
|
||||
#include "libk/string.h"
|
||||
#include "drivers/input/input.h"
|
||||
|
||||
static spinlock_t s_vfs_lock = SPINLOCK_INIT;
|
||||
static vfs_file_t vfs_fd_table[VFS_MAX_FDS];
|
||||
@@ -111,6 +112,10 @@ int VFS_Read_internal(fd_t fd, uint8_t* buf, size_t size)
|
||||
if (fd < 0 || fd >= VFS_MAX_FDS)
|
||||
return -1;
|
||||
|
||||
if (fd == VFS_FD_STDIN) {
|
||||
return input_read_console(buf, size);
|
||||
}
|
||||
|
||||
vfs_file_t* file = &vfs_fd_table[fd];
|
||||
|
||||
if (!file->used)
|
||||
|
||||
Reference in New Issue
Block a user