Kernel: Move the translated keyboard to /dev/console and make /dev/kbd provide raw scancodes
This commit is contained in:
parent
c604c074a1
commit
42a805fd60
@ -6,4 +6,10 @@ namespace ConsoleDevice
|
|||||||
VFS::Node* create_new(const char* devname);
|
VFS::Node* create_new(const char* devname);
|
||||||
|
|
||||||
ssize_t write(VFS::Node* node, size_t offset, size_t size, const char* buffer);
|
ssize_t write(VFS::Node* node, size_t offset, size_t size, const char* buffer);
|
||||||
|
|
||||||
|
ssize_t read(VFS::Node* node, size_t offset, size_t size, char* buffer);
|
||||||
|
|
||||||
|
int would_block(VFS::Node* node);
|
||||||
|
|
||||||
|
void append(char c);
|
||||||
}
|
}
|
@ -5,20 +5,30 @@
|
|||||||
#include "std/stdlib.h"
|
#include "std/stdlib.h"
|
||||||
#include "std/string.h"
|
#include "std/string.h"
|
||||||
|
|
||||||
extern uint64_t clock_boot();
|
char* conin_buffer = nullptr;
|
||||||
|
uint64_t conin_bufsize = 0;
|
||||||
|
|
||||||
|
int ConsoleDevice::would_block(VFS::Node*)
|
||||||
|
{
|
||||||
|
return conin_bufsize == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern uint64_t clock_now();
|
||||||
|
|
||||||
VFS::Node* ConsoleDevice::create_new(const char* devname)
|
VFS::Node* ConsoleDevice::create_new(const char* devname)
|
||||||
{
|
{
|
||||||
VFS::Node* dev = new VFS::Node;
|
VFS::Node* dev = new VFS::Node;
|
||||||
dev->write_func = ConsoleDevice::write;
|
dev->write_func = ConsoleDevice::write;
|
||||||
|
dev->read_func = ConsoleDevice::read;
|
||||||
|
dev->block_func = ConsoleDevice::would_block;
|
||||||
dev->inode = 0;
|
dev->inode = 0;
|
||||||
dev->length = 0;
|
dev->length = 0;
|
||||||
dev->type = VFS_DEVICE;
|
dev->type = VFS_DEVICE;
|
||||||
dev->flags = 0;
|
dev->flags = 0;
|
||||||
dev->tty = 1;
|
dev->tty = 1;
|
||||||
dev->uid = dev->gid = 0;
|
dev->uid = dev->gid = 0;
|
||||||
dev->mode = 0222;
|
dev->mode = 0666;
|
||||||
dev->atime = dev->ctime = dev->mtime = clock_boot();
|
dev->atime = dev->ctime = dev->mtime = clock_now();
|
||||||
strncpy(dev->name, devname, sizeof(dev->name));
|
strncpy(dev->name, devname, sizeof(dev->name));
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
@ -29,3 +39,23 @@ ssize_t ConsoleDevice::write(VFS::Node* node, size_t, size_t size, const char* b
|
|||||||
TextRenderer::write(buffer, size);
|
TextRenderer::write(buffer, size);
|
||||||
return (ssize_t)size;
|
return (ssize_t)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t ConsoleDevice::read(VFS::Node* node, size_t, size_t size, char* buffer)
|
||||||
|
{
|
||||||
|
if (!node) return -1;
|
||||||
|
if (!conin_buffer) return 0;
|
||||||
|
if (size > conin_bufsize) size = conin_bufsize;
|
||||||
|
memcpy(buffer, conin_buffer, size);
|
||||||
|
memmove(conin_buffer, conin_buffer + size, conin_bufsize - size);
|
||||||
|
conin_bufsize -= size;
|
||||||
|
conin_buffer = (char*)krealloc(conin_buffer, conin_bufsize);
|
||||||
|
return (ssize_t)size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleDevice::append(char c)
|
||||||
|
{
|
||||||
|
conin_bufsize++;
|
||||||
|
conin_buffer = (char*)krealloc(
|
||||||
|
conin_buffer, conin_bufsize); // FIXME: We should probably not be calling realloc every time a key is pressed.
|
||||||
|
conin_buffer[conin_bufsize - 1] = c;
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "interrupts/IRQ.h"
|
#include "interrupts/IRQ.h"
|
||||||
#include "fs/devices/Keyboard.h"
|
#include "fs/devices/Keyboard.h"
|
||||||
|
#include "fs/devices/Console.h"
|
||||||
#include "io/IO.h"
|
#include "io/IO.h"
|
||||||
#include "io/PIC.h"
|
#include "io/PIC.h"
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
@ -21,10 +22,11 @@ void IRQ::interrupt_handler(Context* context)
|
|||||||
break;
|
break;
|
||||||
case 1: {
|
case 1: {
|
||||||
unsigned char scancode = IO::inb(0x60);
|
unsigned char scancode = IO::inb(0x60);
|
||||||
|
KeyboardDevice::append((char)scancode);
|
||||||
bool ignore = false;
|
bool ignore = false;
|
||||||
char key = translate_scancode(scancode, &ignore);
|
char key = translate_scancode(scancode, &ignore);
|
||||||
if (ignore) break;
|
if (ignore) break;
|
||||||
KeyboardDevice::append(key);
|
ConsoleDevice::append(key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: kwarnln("Unhandled IRQ: %ld", context->irq_number); break;
|
default: kwarnln("Unhandled IRQ: %ld", context->irq_number); break;
|
||||||
|
@ -58,7 +58,7 @@ extern char* program_invocation_name;
|
|||||||
|
|
||||||
extern "C" void initialize_libc(int, char** argv)
|
extern "C" void initialize_libc(int, char** argv)
|
||||||
{
|
{
|
||||||
check_for_file(STDIN_FILENO, &stdin, "/dev/kbd", "r");
|
check_for_file(STDIN_FILENO, &stdin, "/dev/console", "r");
|
||||||
check_for_file(STDOUT_FILENO, &stdout, "/dev/console", "a");
|
check_for_file(STDOUT_FILENO, &stdout, "/dev/console", "a");
|
||||||
check_for_file(STDERR_FILENO, &stderr, "/dev/console", "a");
|
check_for_file(STDERR_FILENO, &stderr, "/dev/console", "a");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user