about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-06-25 03:20:10 +0200
committerYour Name <you@example.com>2020-06-25 03:20:10 +0200
commit93037bdf0434afb24b338fb9ac3843af4959abd3 (patch)
tree8ce57e1dd3f72d0c84ac2839aee496dbdb77b417
parentBase: added timer (diff)
downloadpOS-93037bdf0434afb24b338fb9ac3843af4959abd3.tar.gz
pOS-93037bdf0434afb24b338fb9ac3843af4959abd3.tar.bz2
pOS-93037bdf0434afb24b338fb9ac3843af4959abd3.zip
Shell: added support for command exit codes
-rw-r--r--src/pOS/arch/x86/kernel/shell/cmd.cpp4
-rw-r--r--src/pOS/arch/x86/kernel/shell/cmds/test.cpp9
-rw-r--r--src/pOS/arch/x86/kernel/shell/shell.cpp13
-rw-r--r--src/pOS/arch/x86/kernel/system.cpp12
-rw-r--r--src/pOS/arch/x86/kernel/time.cpp2
-rw-r--r--src/pOS/include/kernel/shell/cmd.h1
-rw-r--r--src/pOS/include/kernel/shell/shell.h1
7 files changed, 31 insertions, 11 deletions
diff --git a/src/pOS/arch/x86/kernel/shell/cmd.cpp b/src/pOS/arch/x86/kernel/shell/cmd.cpp
index cc34f6e..3453df1 100644
--- a/src/pOS/arch/x86/kernel/shell/cmd.cpp
+++ b/src/pOS/arch/x86/kernel/shell/cmd.cpp
@@ -26,6 +26,10 @@ int CMD_MANAGER::execute(char* cmd)
 
         case str2int("reboot"):
             return CMD_Reboot().execute(cmd);
+
+        case str2int("test"):
+        case str2int("t"):
+            return CMD_Test().execute(cmd);
     }
 
     printf("Unknown cmd: %s\n", cmd);
diff --git a/src/pOS/arch/x86/kernel/shell/cmds/test.cpp b/src/pOS/arch/x86/kernel/shell/cmds/test.cpp
new file mode 100644
index 0000000..0c9a32c
--- /dev/null
+++ b/src/pOS/arch/x86/kernel/shell/cmds/test.cpp
@@ -0,0 +1,9 @@
+#include <kernel/shell/cmd.h>
+#include <stdio.h>
+
+int CMD_Test::execute(const char* args)
+{
+    UNUSED_VARIABLE(args);
+    printf("Test!\n");
+    return 0;
+}
diff --git a/src/pOS/arch/x86/kernel/shell/shell.cpp b/src/pOS/arch/x86/kernel/shell/shell.cpp
index bbaf182..16ca129 100644
--- a/src/pOS/arch/x86/kernel/shell/shell.cpp
+++ b/src/pOS/arch/x86/kernel/shell/shell.cpp
@@ -26,7 +26,7 @@ void signal_handler(Signal_Type signal)
 
 int Shell::init(void)
 {
-    Shell::set_prefix("pOS# ");
+    Shell::set_prefix("pOS#");
     Signals::register_recieve(signal_handler);
     return run();
 }
@@ -34,9 +34,10 @@ int Shell::init(void)
 int Shell::run(void)
 {
     char c;
+    int return_code = 0;
     int indx = 0;
     char cmd[20];        /* Mem management */
-    printf("pOS# ");
+    printf("%s ", Shell::prefix);
     while((c = getc()) && c != EOF)
     {
         putc(c);
@@ -48,9 +49,13 @@ int Shell::run(void)
             cmd[indx] = '\0';
             indx = 0;
 
-            CMD_MANAGER::execute(cmd);
+            return_code = CMD_MANAGER::execute(cmd);
 
-            printf(Shell::prefix);
+            char retstr[5];
+            sprintf(retstr, "(%d)", return_code);
+            if(!return_code)
+                retstr[0] = '\0';
+            printf("%s%s ", retstr, Shell::prefix);
         }
         else
             cmd[indx++] = c;
diff --git a/src/pOS/arch/x86/kernel/system.cpp b/src/pOS/arch/x86/kernel/system.cpp
index df1dc72..5f20fda 100644
--- a/src/pOS/arch/x86/kernel/system.cpp
+++ b/src/pOS/arch/x86/kernel/system.cpp
@@ -3,37 +3,37 @@
 uint8_t System::inb(uint16_t port)
 {
     uint8_t result;
-    asm volatile( "inb %1, %0" : "=a"(result) : "Nd"(port));
+    asm volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
         return result;
 }
 
 uint16_t System::inw(uint16_t port)
 {
     uint16_t result;
-    asm volatile( "inw %1, %0" : "=a"(result) : "Nd"(port));
+    asm volatile("inw %1, %0" : "=a"(result) : "Nd"(port));
         return result;
 }
 
 uint32_t System::inl(uint16_t port)
 {
     uint32_t result;
-    asm volatile( "inl %1, %0" : "=a"(result) : "Nd"(port));
+    asm volatile("inl %1, %0" : "=a"(result) : "Nd"(port));
         return result;
 }
 
 void System::outb(uint16_t port, uint8_t data)
 {
-   asm volatile( "outb %0, %1" : : "a"(data), "Nd"(port));
+   asm volatile("outb %0, %1" : : "a"(data), "Nd"(port));
 }
 
 void System::outw(uint16_t port, uint16_t data)
 {
-    asm volatile ("outw %0, %1" : : "a" (data), "Nd" (port));
+    asm volatile("outw %0, %1" : : "a" (data), "Nd" (port));
 }
 
 void System::outl(uint16_t port, uint32_t data)
 {
-    asm volatile ("outl %0, %1" : : "a" (data), "Nd" (port));
+    asm volatile("outl %0, %1" : : "a" (data), "Nd" (port));
 }
 
 int System::idle_loop(void)
diff --git a/src/pOS/arch/x86/kernel/time.cpp b/src/pOS/arch/x86/kernel/time.cpp
index a231940..b0e50b9 100644
--- a/src/pOS/arch/x86/kernel/time.cpp
+++ b/src/pOS/arch/x86/kernel/time.cpp
@@ -40,7 +40,7 @@ uint8_t Time::get_minute(void)
     return Time::get_date().minute;
 }
 
-uint8_t Time::get_hour(void) //define so it can be 24h
+uint8_t Time::get_hour(void)
 {
     return Time::get_date().hour;
 }
diff --git a/src/pOS/include/kernel/shell/cmd.h b/src/pOS/include/kernel/shell/cmd.h
index 48c3d58..147b62d 100644
--- a/src/pOS/include/kernel/shell/cmd.h
+++ b/src/pOS/include/kernel/shell/cmd.h
@@ -25,5 +25,6 @@ ADD_CMD(CMD_Clear);
 ADD_CMD(CMD_Shutdown);
 ADD_CMD(CMD_Reboot);
 ADD_CMD(CMD_Halt);
+ADD_CMD(CMD_Test);
 
 #endif
diff --git a/src/pOS/include/kernel/shell/shell.h b/src/pOS/include/kernel/shell/shell.h
index 32ab101..6b64139 100644
--- a/src/pOS/include/kernel/shell/shell.h
+++ b/src/pOS/include/kernel/shell/shell.h
@@ -2,6 +2,7 @@
 #define _SHELL_H_
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <assert.h>
 #include <kernel/signals.h>
 #include <kernel/shell/cmd.h>