diff cos/kernel/shell.c @ 37:5c20bd53cccd

Cleanup
author windel
date Mon, 16 Jan 2012 21:38:55 +0100
parents
children 24ce177e01e8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cos/kernel/shell.c	Mon Jan 16 21:38:55 2012 +0100
@@ -0,0 +1,66 @@
+#include "kernel.h"
+
+/* Interactive shell, should be eventually a user space
+  program */
+
+static void testMalloc()
+{
+   char *a, *b;
+
+   printf("Testing malloc\n");
+   a = kmalloc(100);
+   printf("Got a at %x\n", a);
+   a[0] = 'A';
+   b = kmalloc(22);
+   printf("Got b at %x\n", b);
+   b[0] = 'B';
+   kfree(a);
+}
+
+void shell()
+{
+   printf("Welcome!\n");
+   while (1) 
+   {
+      char buffer[70];
+      printf(">");
+      getline(buffer, 70);
+      // TODO: interpret this line with python :)
+      printf("\n");
+      if (buffer[0] == 'x') 
+      {
+         printf("System time in ms: %d\n", getTimeMS());
+      }
+    if (buffer[0] == 't')
+    {
+        testMalloc();
+    }
+    if ( strncmp(buffer, "help", 4)) 
+    {
+      printf("Help\n Try one of these commands:\n");
+      printf(" x: print system time in ms\n");
+      printf(" r: reboot\n");
+      printf(" t: test\n");
+      printf(" b: break\n");
+    }
+
+      if (strncmp(buffer, "r", 1))
+      {
+         reboot();
+      }
+
+      if (strncmp(buffer, "b", 1))
+      {
+         magicBochsBreak();
+      }
+
+      if (strncmp(buffer, "pf", 2))
+      {
+         /* Test general protection exception */
+         uint64_t *x;
+         x = (uint64_t*)0x4000000; // Address that is not mapped
+         *x = 0x2; // trigger paging exception
+      }
+   }
+}
+