view cos/kernel/kernel.c @ 30:0148f55bfe24

Added static asserts and fixed pages
author windel
date Thu, 29 Dec 2011 23:51:35 +0100
parents 7e3bdcb391dc
children 88590c42320f
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);
}

// A test program that prints 'Hoi' to the screen:
unsigned char hello_program[] = {0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xec, 0x10, 0x48, 0xc7, 0x45, 0xf8, 0x0, 0x80, 0xb, 0x0, 0x48, 0x8b, 0x45, 0xf8, 0xc6, 0x0, 0x48, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x2, 0xc6, 0x0, 0x6f, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x4, 0xc6, 0x0, 0x69, 0xeb, 0xfe, 0x0, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x7a, 0x52, 0x0, 0x1, 0x78, 0x10, 0x1, 0x1b, 0xc, 0x7, 0x8, 0x90, 0x1, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0xb0, 0xff, 0xff, 0xff, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x41, 0xe, 0x10, 0x86, 0x2, 0x43, 0xd, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};

/* 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);

  //new_task(hello_program);

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