From be6695219143a142850d465779d635ae5b5ba8c8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 24 Jun 2020 16:24:26 +0200 Subject: Base: added basic shell --- src/pOS/arch/x86/kernel/shell.cpp | 46 +++++++++++++++++++++++++++++++++++++++ src/pOS/include/kernel/kernel.h | 1 + src/pOS/include/kernel/shell.h | 18 +++++++++++++++ src/pOS/kernel/kernel.cpp | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 src/pOS/arch/x86/kernel/shell.cpp create mode 100644 src/pOS/include/kernel/shell.h 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 + +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 #include +#include #include #include #include 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 +#include + +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); -- cgit 1.4.1