From a8a80d326de9550b2a25b1255a2093ab43219ede Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 27 Jan 2024 23:14:29 -0500 Subject: keyboard input --- kernel/include/hilbert/kernel/input.hpp | 26 ++++++++++++++++ kernel/include/hilbert/kernel/panic.hpp | 6 ++++ kernel/include/hilbert/kernel/utility.hpp | 50 +++++++++++++++++++++++++++++++ kernel/include/hilbert/kernel/vfile.hpp | 8 ++--- 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 kernel/include/hilbert/kernel/input.hpp create mode 100644 kernel/include/hilbert/kernel/panic.hpp (limited to 'kernel/include') diff --git a/kernel/include/hilbert/kernel/input.hpp b/kernel/include/hilbert/kernel/input.hpp new file mode 100644 index 0000000..cccb71f --- /dev/null +++ b/kernel/include/hilbert/kernel/input.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace hilbert::kernel::input { + + enum : uint32_t { + LEFT_SHIFT = 1 << 8, + RIGHT_SHIFT = 1 << 9, + LEFT_CTRL = 1 << 10, + RIGHT_CTRL = 1 << 11, + LEFT_ALT = 1 << 12, + RIGHT_ALT = 1 << 13, + LEFT_WIN = 1 << 14, + RIGHT_WIN = 1 << 15, + CAPS_LOCK = 1 << 16, + NUM_LOCK = 1 << 17, + BREAK = 1 << 18, + }; + + extern utility::queue *key_queue; + + //must be post switch to kernel page tables and mounting of file systems + void init_input(); + +} diff --git a/kernel/include/hilbert/kernel/panic.hpp b/kernel/include/hilbert/kernel/panic.hpp new file mode 100644 index 0000000..545d703 --- /dev/null +++ b/kernel/include/hilbert/kernel/panic.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace hilbert::kernel { + //prints to terminal and then halts. + [[noreturn]] void panic(const char *string_sz); +} diff --git a/kernel/include/hilbert/kernel/utility.hpp b/kernel/include/hilbert/kernel/utility.hpp index 2df1d65..47f78ea 100644 --- a/kernel/include/hilbert/kernel/utility.hpp +++ b/kernel/include/hilbert/kernel/utility.hpp @@ -294,4 +294,54 @@ namespace hilbert::kernel::utility { }; + template + struct queue { + + value_t *buffer; + unsigned buffer_len; + unsigned count; + unsigned next_read_index; + + queue(unsigned initial_len = 1024) : buffer(new value_t[initial_len]), + buffer_len(initial_len), count(0), next_read_index(0) { } + + ~queue() { + delete[] buffer; + } + + void insert(const value_t &v) { + + if (count == buffer_len) { + value_t *new_buffer = new value_t[buffer_len * 2]; + for (unsigned i = 0; i < buffer_len - next_read_index; ++i) + new_buffer[i] = move(buffer[i + next_read_index]); + for (unsigned i = buffer_len - next_read_index; i < buffer_len; ++i) + new_buffer[i] = move(buffer[i + next_read_index - buffer_len]); + delete[] buffer; + buffer = new_buffer; + buffer_len *= 2; + next_read_index = 0; + } + + buffer[(count + next_read_index) % buffer_len] = v; + ++count; + + } + + //assumes not empty + const value_t &peek() const { + return buffer[next_read_index]; + } + + //assumes not empty + value_t &&take() { + value_t &&ret = move(buffer[next_read_index]); + if (++next_read_index == buffer_len) + next_read_index = 0; + --count; + return move(ret); + } + + }; + } diff --git a/kernel/include/hilbert/kernel/vfile.hpp b/kernel/include/hilbert/kernel/vfile.hpp index f8a387d..b64ae63 100644 --- a/kernel/include/hilbert/kernel/vfile.hpp +++ b/kernel/include/hilbert/kernel/vfile.hpp @@ -55,9 +55,9 @@ namespace hilbert::kernel::vfile { //TODO: see comment at top of file. void set_root(const vfile &root); - //path must be absolute. follows symlinks on all but the last node. - //relative_to should be a directory to do the lookup inside; e.g., - //if relative_to is /a/b and path is c, then out becomes /a/b/c. - storage::fs_result lookup_path(const canon_path &path, vfile &out); + //path must be absolute. follows symlinks on all but the last node + //always, and on the last node when follow_final_symlink is true. + storage::fs_result lookup_path( + const canon_path &path, vfile &out, bool follow_final_symlink); } -- cgit v1.2.3