view cos/kernel/kernel.c @ 31:88590c42320f

Changed interrupt handler
author windel
date Tue, 10 Jan 2012 20:40:35 +0100
parents 7e3bdcb391dc
children 3a6a9b929db0
line wrap: on
line source


#include "kernel.h"

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

/* This routine initializes the kernel.
 * We are left here in 64-bit long mode with the first 6 MB identity mapped.
 * */
void kmain()
{
   init_screen();
   setupIDT();
   // init_heap();

   // Assume first 16MB:
   // TODO: get size from grub
   init_memory(0x1000000);

  // TODO: make below a user space program!
  printf("Welcome!\n");

  while (1==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();
    }
  }
}