diff options
author | Your Name <you@example.com> | 2020-06-25 02:07:49 +0200 |
---|---|---|
committer | Your Name <you@example.com> | 2020-06-25 02:09:45 +0200 |
commit | 86d8dd5feeec97998970f87c6aa335c3d6cd75f9 (patch) | |
tree | 021e65b99eb2f4c0b33b841bc37eb9cc09165177 | |
parent | stdlib: changed assert from inline to a normal function (diff) | |
download | pOS-86d8dd5feeec97998970f87c6aa335c3d6cd75f9.tar.gz pOS-86d8dd5feeec97998970f87c6aa335c3d6cd75f9.tar.bz2 pOS-86d8dd5feeec97998970f87c6aa335c3d6cd75f9.zip |
Base: added support for signals.
Added signals. Programs can sign up to recieve said signals and interpret them how they want.
-rw-r--r-- | src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h | 1 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp | 16 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/shell.cpp | 27 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/signals.cpp | 33 | ||||
-rw-r--r-- | src/pOS/include/kernel/shell/shell.h | 1 | ||||
-rw-r--r-- | src/pOS/include/kernel/signals.h | 23 |
6 files changed, 88 insertions, 13 deletions
diff --git a/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h b/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h index 6b76fa0..566765a 100644 --- a/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h +++ b/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h @@ -3,6 +3,7 @@ #include <stdbool.h> #include <kernel/tty.h> +#include <kernel/signals.h> #include "scancodes.h" #define KEYBUFSIZ 128 diff --git a/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp b/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp index 0892865..7bc3766 100644 --- a/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp +++ b/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp @@ -19,30 +19,24 @@ int KB_BUF::scan(unsigned char code) switch(code) { - /* IMPLEMENT WITH SIG CODES */ case ESC: + Signals::send_signal(ESC_SIG); break; case UP_ARROW: - if(shifted) - TTY::tty_scroll(+1); - else - TTY::tty_cursor_move(0, -1); + Signals::send_signal(UP_ARROW_SIG); break; case LEFT_ARROW: - TTY::tty_cursor_move(-1, 0); + Signals::send_signal(LEFT_ARROW_SIG); break; case RIGHT_ARROW: - TTY::tty_cursor_move(1, 0); + Signals::send_signal(RIGHT_ARROW_SIG); break; case DOWN_ARROW: - if(shifted) - TTY::tty_scroll(-1); - else - TTY::tty_cursor_move(0, +1); + Signals::send_signal(DOWN_ARROW_SIG); break; /* IMPLEMENT WITH SIG CODES */ diff --git a/src/pOS/arch/x86/kernel/shell/shell.cpp b/src/pOS/arch/x86/kernel/shell/shell.cpp index 9dc1fcd..bbaf182 100644 --- a/src/pOS/arch/x86/kernel/shell/shell.cpp +++ b/src/pOS/arch/x86/kernel/shell/shell.cpp @@ -2,22 +2,45 @@ char Shell::prefix[10]; +void signal_handler(Signal_Type signal) +{ + switch(signal) + { + case ESC_SIG: + break; + case LEFT_ARROW_SIG: + TTY::tty_cursor_move(-1, 0); + break; + case RIGHT_ARROW_SIG: + TTY::tty_cursor_move(+1, 0); + break; + case UP_ARROW_SIG: + /* TODO: implement history */ + break; + case DOWN_ARROW_SIG: + break; + case KILL_SIG: + break; + } +} + int Shell::init(void) { Shell::set_prefix("pOS# "); + Signals::register_recieve(signal_handler); return run(); } int Shell::run(void) { char c; - char cmd[20]; /* Mem management */ int indx = 0; + char cmd[20]; /* Mem management */ printf("pOS# "); while((c = getc()) && c != EOF) { putc(c); - /* TODO: Handle signals */ + if(c == '\b') indx--; else if(c == '\n') diff --git a/src/pOS/arch/x86/kernel/signals.cpp b/src/pOS/arch/x86/kernel/signals.cpp new file mode 100644 index 0000000..b43c9fb --- /dev/null +++ b/src/pOS/arch/x86/kernel/signals.cpp @@ -0,0 +1,33 @@ +#include <kernel/signals.h> + +static int index = 0; + +static void* singnal_handlers[10] = +{ + 0,0,0,0,0,0,0,0,0,0 +}; + +int Signals::send_signal(Signal_Type signal) +{ + for(size_t i = 0; i < 10; i++) + { + void (*handler)(Signal_Type sig); + + handler = reinterpret_cast<void (*)(Signal_Type sig)>(singnal_handlers[i]); + if (handler) + { + handler(signal); + } + } + + return 0; +} + +int Signals::register_recieve(void (*handler)(Signal_Type sig)) +{ + singnal_handlers[index++] = reinterpret_cast<void *&>(handler); + if(index >= 10) /* 10 max, temp*/ + index = 0; + + return 0; +} diff --git a/src/pOS/include/kernel/shell/shell.h b/src/pOS/include/kernel/shell/shell.h index ced7ca6..32ab101 100644 --- a/src/pOS/include/kernel/shell/shell.h +++ b/src/pOS/include/kernel/shell/shell.h @@ -3,6 +3,7 @@ #include <stdio.h> #include <assert.h> +#include <kernel/signals.h> #include <kernel/shell/cmd.h> class Shell diff --git a/src/pOS/include/kernel/signals.h b/src/pOS/include/kernel/signals.h new file mode 100644 index 0000000..65b9c62 --- /dev/null +++ b/src/pOS/include/kernel/signals.h @@ -0,0 +1,23 @@ +#ifndef _SIGNALS_H_ +#define _SIGNALS_H_ + +#include <stddef.h> + +enum Signal_Type +{ + ESC_SIG, + LEFT_ARROW_SIG, + RIGHT_ARROW_SIG, + UP_ARROW_SIG, + DOWN_ARROW_SIG, + KILL_SIG +}; + +class Signals +{ +public: + static int send_signal(Signal_Type signal); + static int register_recieve(void (*handler)(Signal_Type sig)); +}; + +#endif |