feat: partially implement PS/2 input subsystem with keyboard and mouse support
This implementation is incomplete, and doesn't work, but it will soon, to be determined, hopefully, uh, yknow. Signed-off-by kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
@@ -2,12 +2,55 @@
|
||||
#include <video/render.h>
|
||||
#include <arch/x86_64/e9.h>
|
||||
#include "mp/spinlock.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
static spinlock_t s_vfs_lock = SPINLOCK_INIT;
|
||||
static vfs_file_t vfs_fd_table[VFS_MAX_FDS];
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
int (*read)(void* buf, size_t len);
|
||||
int (*write)(const void* buf, size_t len);
|
||||
} vfs_chardev_t;
|
||||
|
||||
#define VFS_MAX_CHARDEVS 8
|
||||
static vfs_chardev_t s_chardevs[VFS_MAX_CHARDEVS];
|
||||
static int s_num_chardevs = 0;
|
||||
|
||||
int VFS_RegisterCharDev(const char* path,
|
||||
int (*read)(void* buf, size_t len),
|
||||
int (*write)(const void* buf, size_t len))
|
||||
{
|
||||
if (s_num_chardevs >= VFS_MAX_CHARDEVS) {
|
||||
printf("VFS: too many char devices!\n");
|
||||
return -1;
|
||||
}
|
||||
s_chardevs[s_num_chardevs].path = path;
|
||||
s_chardevs[s_num_chardevs].read = read;
|
||||
s_chardevs[s_num_chardevs].write = write;
|
||||
printf("VFS: registered chardev %s\n", path);
|
||||
s_num_chardevs++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fd_t VFS_Open_internal(const char* path)
|
||||
{
|
||||
for (int i = 0; i < s_num_chardevs; i++) {
|
||||
if (strcmp(s_chardevs[i].path, path) == 0) {
|
||||
for (int fd = 4; fd < VFS_MAX_FDS; fd++) {
|
||||
if (!vfs_fd_table[fd].used) {
|
||||
vfs_fd_table[fd].used = true;
|
||||
vfs_fd_table[fd].type = VFS_NODE_CHARDEV;
|
||||
vfs_fd_table[fd].offset = 0;
|
||||
vfs_fd_table[fd].chardev.dev_idx = i;
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ino = ext2_resolve_path(path);
|
||||
if (ino == 0)
|
||||
return -1;
|
||||
@@ -92,6 +135,14 @@ int VFS_Read(fd_t fd, uint8_t* buf, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
case VFS_NODE_CHARDEV:
|
||||
{
|
||||
int idx = file->chardev.dev_idx;
|
||||
if (idx < 0 || idx >= s_num_chardevs || !s_chardevs[idx].read)
|
||||
return -1;
|
||||
return s_chardevs[idx].read(buf, size);
|
||||
}
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@@ -143,5 +194,13 @@ int VFS_Write(fd_t file, uint8_t* data, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
if (f->type == VFS_NODE_CHARDEV)
|
||||
{
|
||||
int idx = f->chardev.dev_idx;
|
||||
if (idx >= 0 && idx < s_num_chardevs && s_chardevs[idx].write)
|
||||
return s_chardevs[idx].write(data, size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user