diff options
author | Benji Dial <benji@benjidial.net> | 2024-01-27 23:14:29 -0500 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-01-27 23:14:29 -0500 |
commit | a8a80d326de9550b2a25b1255a2093ab43219ede (patch) | |
tree | d42a800f735caf93679d1728e2d5f20004db3b65 /kernel/include/hilbert | |
parent | 7199e74aa22e592a3b77bdd81f735edca5470596 (diff) | |
download | hilbert-os-a8a80d326de9550b2a25b1255a2093ab43219ede.tar.gz |
keyboard input
Diffstat (limited to 'kernel/include/hilbert')
-rw-r--r-- | kernel/include/hilbert/kernel/input.hpp | 26 | ||||
-rw-r--r-- | kernel/include/hilbert/kernel/panic.hpp | 6 | ||||
-rw-r--r-- | kernel/include/hilbert/kernel/utility.hpp | 50 | ||||
-rw-r--r-- | kernel/include/hilbert/kernel/vfile.hpp | 8 |
4 files changed, 86 insertions, 4 deletions
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 <hilbert/kernel/utility.hpp> + +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<uint32_t> *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 <class value_t> + 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); } |