diff options
author | Your Name <you@example.com> | 2020-06-24 20:28:18 +0200 |
---|---|---|
committer | Your Name <you@example.com> | 2020-06-24 20:28:18 +0200 |
commit | 8ef0249d88a07a42075cef387bb8e3def9f20cf0 (patch) | |
tree | 62c9a9e2e1c092028292eef6ccfe9647d224747c | |
parent | ACPI: added halt() (diff) | |
download | pOS-8ef0249d88a07a42075cef387bb8e3def9f20cf0.tar.gz pOS-8ef0249d88a07a42075cef387bb8e3def9f20cf0.tar.bz2 pOS-8ef0249d88a07a42075cef387bb8e3def9f20cf0.zip |
Shell: added some basic commands
Added simple temp command manager. Added clear, halt, shutdown and reboot.
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/cmd.cpp | 33 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/cmds/clear.cpp | 9 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/cmds/halt.cpp | 9 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp | 9 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp | 9 | ||||
-rw-r--r-- | src/pOS/arch/x86/kernel/shell/shell.cpp (renamed from src/pOS/arch/x86/kernel/shell.cpp) | 19 | ||||
-rw-r--r-- | src/pOS/include/kernel/kernel.h | 2 | ||||
-rw-r--r-- | src/pOS/include/kernel/shell/cmd.h | 29 | ||||
-rw-r--r-- | src/pOS/include/kernel/shell/shell.h (renamed from src/pOS/include/kernel/shell.h) | 1 |
9 files changed, 108 insertions, 12 deletions
diff --git a/src/pOS/arch/x86/kernel/shell/cmd.cpp b/src/pOS/arch/x86/kernel/shell/cmd.cpp new file mode 100644 index 0000000..cc34f6e --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell/cmd.cpp @@ -0,0 +1,33 @@ +#include <string.h> +#include <stdio.h> +#include <kernel/shell/cmd.h> + +#include <kernel/debug.h> + +int CMD_MANAGER::execute(char* cmd) +{ + //char* arg = strtok(cmd, " "); + + dbgprintf("cmd: %s\n", cmd); + + switch(str2int(cmd)) + { + case str2int("clear"): + case str2int("cls"): + case str2int("c"): + return CMD_Clear().execute(cmd); + + case str2int("halt"): + case str2int("hlt"): + return CMD_Halt().execute(cmd); + + case str2int("shutdown"): + return CMD_Shutdown().execute(cmd); + + case str2int("reboot"): + return CMD_Reboot().execute(cmd); + } + + printf("Unknown cmd: %s\n", cmd); + return -1; +} diff --git a/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp b/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp new file mode 100644 index 0000000..1919a3a --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp @@ -0,0 +1,9 @@ +#include <kernel/shell/cmd.h> +#include <kernel/tty.h> + +int CMD_Clear::execute(const char* args) +{ + UNUSED_VARIABLE(args); + TTY::tty_initialize(); + return 0; +} diff --git a/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp b/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp new file mode 100644 index 0000000..2993af3 --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp @@ -0,0 +1,9 @@ +#include <kernel/shell/cmd.h> +#include <kernel/acpi.h> + +int CMD_Halt::execute(const char* args) +{ + UNUSED_VARIABLE(args); + ACPI::halt(); + return 0; +} diff --git a/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp b/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp new file mode 100644 index 0000000..bf2dac3 --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp @@ -0,0 +1,9 @@ +#include <kernel/shell/cmd.h> +#include <kernel/acpi.h> + +int CMD_Reboot::execute(const char* args) +{ + UNUSED_VARIABLE(args); + ACPI::reboot(); + return 0; +} diff --git a/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp b/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp new file mode 100644 index 0000000..e0939d9 --- /dev/null +++ b/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp @@ -0,0 +1,9 @@ +#include <kernel/shell/cmd.h> +#include <kernel/acpi.h> + +int CMD_Shutdown::execute(const char* args) +{ + UNUSED_VARIABLE(args); + ACPI::shutdown(); + return 0; +} diff --git a/src/pOS/arch/x86/kernel/shell.cpp b/src/pOS/arch/x86/kernel/shell/shell.cpp index b6e74be..9dc1fcd 100644 --- a/src/pOS/arch/x86/kernel/shell.cpp +++ b/src/pOS/arch/x86/kernel/shell/shell.cpp @@ -1,4 +1,4 @@ -#include <kernel/shell.h> +#include <kernel/shell/shell.h> char Shell::prefix[10]; @@ -8,7 +8,7 @@ int Shell::init(void) return run(); } -int Shell::run(void) /* TODO: implement args */ +int Shell::run(void) { char c; char cmd[20]; /* Mem management */ @@ -17,13 +17,16 @@ int Shell::run(void) /* TODO: implement args */ while((c = getc()) && c != EOF) { putc(c); - - if(c == '\n') + /* TODO: Handle signals */ + if(c == '\b') + indx--; + else if(c == '\n') { cmd[indx] = '\0'; indx = 0; - handle_cmd(cmd); + CMD_MANAGER::execute(cmd); + printf(Shell::prefix); } else @@ -34,12 +37,6 @@ int Shell::run(void) /* TODO: implement args */ 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 671bee6..cbe5f3d 100644 --- a/src/pOS/include/kernel/kernel.h +++ b/src/pOS/include/kernel/kernel.h @@ -5,7 +5,7 @@ #include <math.h> #include <assert.h> -#include <kernel/shell.h> +#include <kernel/shell/shell.h> #include <kernel/time.h> #include <kernel/debug.h> #include <kernel/drivers.h> diff --git a/src/pOS/include/kernel/shell/cmd.h b/src/pOS/include/kernel/shell/cmd.h new file mode 100644 index 0000000..48c3d58 --- /dev/null +++ b/src/pOS/include/kernel/shell/cmd.h @@ -0,0 +1,29 @@ +#ifndef _CMD_H_ +#define _CMD_H_ + +#define ADD_CMD(name) \ + class name : public CMD \ + { \ + public: \ + int execute(const char* args); \ + }; + +class CMD_MANAGER +{ +public: + static int execute(char* cmd); +}; + +class CMD +{ +public: + virtual int execute(const char* args); +}; + +/* SHELL CMDS */ +ADD_CMD(CMD_Clear); +ADD_CMD(CMD_Shutdown); +ADD_CMD(CMD_Reboot); +ADD_CMD(CMD_Halt); + +#endif diff --git a/src/pOS/include/kernel/shell.h b/src/pOS/include/kernel/shell/shell.h index cb1cc4b..ced7ca6 100644 --- a/src/pOS/include/kernel/shell.h +++ b/src/pOS/include/kernel/shell/shell.h @@ -3,6 +3,7 @@ #include <stdio.h> #include <assert.h> +#include <kernel/shell/cmd.h> class Shell { |