diff cos/kernel/kernel.c @ 32:3a6a9b929db0

Added initial ramdisk and some virtual file system functions
author windel
date Fri, 13 Jan 2012 18:18:17 +0100
parents 88590c42320f
children d8185ddb6c7b
line wrap: on
line diff
--- a/cos/kernel/kernel.c	Tue Jan 10 20:40:35 2012 +0100
+++ b/cos/kernel/kernel.c	Fri Jan 13 18:18:17 2012 +0100
@@ -15,6 +15,8 @@
    kfree(a);
 }
 
+multiboot_info_t *multiboot_info = 0; // Set by startup code.
+
 /* This routine initializes the kernel.
  * We are left here in 64-bit long mode with the first 6 MB identity mapped.
  * */
@@ -22,14 +24,66 @@
 {
    init_screen();
    setupIDT();
-   // init_heap();
+
+   uint64_t available_memory = 0;
+
+   /* Display memory information from multiboot header */
+   if ((multiboot_info->flags & (1<<6)) == (1<<6))
+   {
+      multiboot_memory_map_t *mmap;
+      for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; 
+            (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; 
+            mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) )
+      {
+         printf("size: %d, start: 0x%x, length=0x%x, type=%d\n", mmap->size, mmap->base, mmap->length, mmap->type);
+
+         if ( (mmap->type == 1) && (mmap->base == 0x100000) )
+         {
+            available_memory = mmap->length;
+         }
+      }
+   }
+
+   printf("Running with %d MB ram\n", available_memory / 1000000);
+
+   fs_node_t *fs_root = 0;
+
+   if ( (multiboot_info->flags & (1<<3)) == (1<<3))
+   {
+      printf("Mod count: %d\n", multiboot_info->mods_count);
+      uint64_t i;
+      multiboot_module_t *mod;
+      for (i=0, mod=(multiboot_module_t*)(uint64_t)multiboot_info->mods_addr; i<multiboot_info->mods_count; i++, mod++)
+      {
+         printf("Mod start: %x, end: %x\n", mod->mod_start, mod->mod_end);
+         if (i == 0)
+         {
+            uint64_t ramdisk_location = ((uint32_t*)((uint64_t)multiboot_info->mods_addr))[0];
+            fs_root = initialize_initrd(ramdisk_location);
+         }
+      }
+   }
+   
+   if (fs_root != 0)
+   {
+      fs_dirent_t *node = 0;
+      int i = 0;
+      while ( (node = readdir_fs(fs_root, i)) != 0)
+      {
+
+      }
+   }
+
+   // TODO: Make sure that placement malloc does not overwrite the ramdisk.
+   printf("Mod size: ");
 
    // Assume first 16MB:
    // TODO: get size from grub
    init_memory(0x1000000);
 
-  // TODO: make below a user space program!
-  printf("Welcome!\n");
+   // TODO: make below a user space program!
+   printf("Welcome!\n");
+
 
   while (1==1) 
   {