Mercurial > lcfOS
diff cos/kernel/kernel.c @ 37:5c20bd53cccd
Cleanup
author | windel |
---|---|
date | Mon, 16 Jan 2012 21:38:55 +0100 |
parents | 91f91ff07ea8 |
children | 35cc54e078dd |
line wrap: on
line diff
--- a/cos/kernel/kernel.c Mon Jan 16 20:47:05 2012 +0100 +++ b/cos/kernel/kernel.c Mon Jan 16 21:38:55 2012 +0100 @@ -1,21 +1,5 @@ #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); -} - -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. * */ @@ -24,60 +8,18 @@ // No kmalloc required here yet: init_screen(); setupIDT(); - - /* Retrieve memory information from multiboot header */ - uint64_t available_memory = 0; - 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; - } - } - } - - if (available_memory == 0) - { - panic("Found no usable memory in grub's memory map\n"); - } - - printf("Running with %d MB ram\n", available_memory / 1000000); - - init_memory(available_memory); // Setup paging and memory manager - + read_multiboot_info(); // Parse the GRUB multiboot header. + init_memory(available_memory); // Setup a new paging scheme and memory manager + // From here kmalloc can be used. keyboard_init(); timer_init(); + printf("Ramdisk location: %p\n", ramdisk_location); /* 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); - } - // TODO: Make sure that placement malloc does not overwrite the ramdisk. - printf("Mod size: %d", mod->mod_end - mod->mod_start); - } - } + fs_root = initialize_initrd(ramdisk_location); + if (fs_root != 0) { fs_dirent_t *node = 0; @@ -89,49 +31,7 @@ } */ - - // TODO: make below a user space program! - 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 - } - } + // TODO: make shell a user space program! + shell(); // Start user shell } -