view cos/kernel/shell.c @ 337:b00219172a42

Added cool lm3s811 qemu project
author Windel Bouwman
date Thu, 20 Feb 2014 20:04:52 +0100
parents 24ce177e01e8
children
line wrap: on
line source

#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 memory_status(void);

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());
         memory_status();
      }
    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
      }
   }
}