diff options
author | Your Name <you@example.com> | 2020-06-24 16:24:26 +0200 |
---|---|---|
committer | Your Name <you@example.com> | 2020-06-24 16:24:26 +0200 |
commit | be6695219143a142850d465779d635ae5b5ba8c8 (patch) | |
tree | b92d8e403f8d5edd80f23e8e7c5815e061ac58d6 | |
parent | Base: improved debug printing (diff) | |
download | pOS-be6695219143a142850d465779d635ae5b5ba8c8.tar.gz pOS-be6695219143a142850d465779d635ae5b5ba8c8.tar.bz2 pOS-be6695219143a142850d465779d635ae5b5ba8c8.zip |
Base: added basic shell
-rw-r--r-- | src/pOS/arch/x86/kernel/shell.cpp | 46 | ||||
-rw-r--r-- | src/pOS/include/kernel/kernel.h | 1 | ||||
-rw-r--r-- | src/pOS/include/kernel/shell.h | 18 | ||||
-rw-r--r-- | src/pOS/kernel/kernel.cpp | 2 |
4 files changed, 67 insertions, 0 deletions
diff --git a/src/pOS/arch/x86/kernel/shell.cpp b/src/pOS/arch/x86/kernel/shell.cpp new file mode 100644 index 0000000..b6e74be --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell.cpp @@ -0,0 +1,46 @@ +#include <kernel/shell.h> + +char Shell::prefix[10]; + +int Shell::init(void) +{ + Shell::set_prefix("pOS# "); + return run(); +} + +int Shell::run(void) /* TODO: implement args */ +{ + char c; + char cmd[20]; /* Mem management */ + int indx = 0; + printf("pOS# "); + while((c = getc()) && c != EOF) + { + putc(c); + + if(c == '\n') + { + cmd[indx] = '\0'; + indx = 0; + + handle_cmd(cmd); + printf(Shell::prefix); + } + else + cmd[indx++] = c; + } + + ASSERT(c == EOF); + return 0; +} + +int Shell::handle_cmd(const char* cmd) +{ + printf("Unknown cmd: %s\n", cmd); + return 0; +} + +void Shell::set_prefix(const char* new_prefix) +{ + strncpy(prefix, new_prefix, sizeof(prefix)); +} diff --git a/src/pOS/include/kernel/kernel.h b/src/pOS/include/kernel/kernel.h index 622ef88..671bee6 100644 --- a/src/pOS/include/kernel/kernel.h +++ b/src/pOS/include/kernel/kernel.h @@ -5,6 +5,7 @@ #include <math.h> #include <assert.h> +#include <kernel/shell.h> #include <kernel/time.h> #include <kernel/debug.h> #include <kernel/drivers.h> diff --git a/src/pOS/include/kernel/shell.h b/src/pOS/include/kernel/shell.h new file mode 100644 index 0000000..cb1cc4b --- /dev/null +++ b/src/pOS/include/kernel/shell.h @@ -0,0 +1,18 @@ +#ifndef _SHELL_H_ +#define _SHELL_H_ + +#include <stdio.h> +#include <assert.h> + +class Shell +{ +public: + static int init(void); + static void set_prefix(const char* prefix); +private: + static int run(void); + static int handle_cmd(const char* cmd); + static char prefix[10]; +}; + +#endif diff --git a/src/pOS/kernel/kernel.cpp b/src/pOS/kernel/kernel.cpp index 4b76b81..1de0818 100644 --- a/src/pOS/kernel/kernel.cpp +++ b/src/pOS/kernel/kernel.cpp @@ -23,6 +23,8 @@ extern "C" int kmain(void) printf("Current time: %s (%s-%d-%d%d)\n", Time::get_date_formatted(), Time::get_month_string(), Time::get_day(), Time::get_century() - 1, Time::get_year()); + Shell::init(); + System::idle_loop(); ASSERT(false); |