Mercurial > lcfOS
comparison cos/kernel/kernel.c @ 34:8012221dd740
Fixes for uninitialized data. This causes problems on real machines
author | windel |
---|---|
date | Mon, 16 Jan 2012 13:46:06 +0100 |
parents | d8185ddb6c7b |
children | bcb3b68c8147 |
comparison
equal
deleted
inserted
replaced
33:d8185ddb6c7b | 34:8012221dd740 |
---|---|
19 /* This routine initializes the kernel. | 19 /* This routine initializes the kernel. |
20 * We are left here in 64-bit long mode with the first 6 MB identity mapped. | 20 * We are left here in 64-bit long mode with the first 6 MB identity mapped. |
21 * */ | 21 * */ |
22 void kmain() | 22 void kmain() |
23 { | 23 { |
24 // No kmalloc required here yet: | |
24 init_screen(); | 25 init_screen(); |
25 setupIDT(); | 26 setupIDT(); |
27 keyboard_init(); | |
28 timer_init(); | |
26 | 29 |
30 /* Retrieve memory information from multiboot header */ | |
27 uint64_t available_memory = 0; | 31 uint64_t available_memory = 0; |
28 | |
29 printf("Running with %d MB ram\n", available_memory / 1000000); | |
30 | |
31 printf("Detecting amount of memory\n"); | |
32 | |
33 printf("Grub multiboot header location: %x\n", multiboot_info); | |
34 // On real hardware, the retrieval of the flags fails into general protection fault?? | |
35 | |
36 printf("Grub lower mem: %d\n", multiboot_info->mem_lower); | |
37 printf("Grub multiboot header flags: %x\n", multiboot_info->flags); | |
38 | |
39 /* Display memory information from multiboot header */ | |
40 if ((multiboot_info->flags & (1<<6)) == (1<<6)) | 32 if ((multiboot_info->flags & (1<<6)) == (1<<6)) |
41 { | 33 { |
42 printf("Found GRUB memory map\n"); | |
43 multiboot_memory_map_t *mmap; | 34 multiboot_memory_map_t *mmap; |
44 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; | 35 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; |
45 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; | 36 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; |
46 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) ) | 37 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) ) |
47 { | 38 { |
48 printf("size: %d, start: 0x%x, length=0x%x, type=%d\n", mmap->size, mmap->base, mmap->length, mmap->type); | 39 /* |
40 printf("size: %d, start: 0x%x, length=0x%x, type=%d\n", mmap->size, | |
41 mmap->base, mmap->length, mmap->type); | |
42 */ | |
49 | 43 |
50 if ( (mmap->type == 1) && (mmap->base == 0x100000) ) | 44 if ( (mmap->type == 1) && (mmap->base == 0x100000) ) |
51 { | 45 { |
52 available_memory = mmap->length; | 46 available_memory = mmap->length; |
53 } | 47 } |
54 } | 48 } |
55 } | 49 } |
56 else | 50 else |
57 { | 51 { |
58 printf("Found no GRUB map\n"); | 52 panic("Found no GRUB memory map\n"); |
59 } | 53 } |
60 | 54 |
61 printf("Running with %d MB ram\n", available_memory / 1000000); | 55 printf("Running with %d MB ram\n", available_memory / 1000000); |
62 | 56 |
57 /* | |
63 fs_node_t *fs_root = 0; | 58 fs_node_t *fs_root = 0; |
64 | |
65 if ( (multiboot_info->flags & (1<<3)) == (1<<3)) | 59 if ( (multiboot_info->flags & (1<<3)) == (1<<3)) |
66 { | 60 { |
67 printf("Mod count: %d\n", multiboot_info->mods_count); | 61 printf("Mod count: %d\n", multiboot_info->mods_count); |
68 uint64_t i; | 62 uint64_t i; |
69 multiboot_module_t *mod; | 63 multiboot_module_t *mod; |
73 if (i == 0) | 67 if (i == 0) |
74 { | 68 { |
75 uint64_t ramdisk_location = ((uint32_t*)((uint64_t)multiboot_info->mods_addr))[0]; | 69 uint64_t ramdisk_location = ((uint32_t*)((uint64_t)multiboot_info->mods_addr))[0]; |
76 fs_root = initialize_initrd(ramdisk_location); | 70 fs_root = initialize_initrd(ramdisk_location); |
77 } | 71 } |
72 // TODO: Make sure that placement malloc does not overwrite the ramdisk. | |
73 printf("Mod size: %d", mod->mod_end - mod->mod_start); | |
78 } | 74 } |
79 } | 75 } |
80 | 76 |
81 if (fs_root != 0) | 77 if (fs_root != 0) |
82 { | 78 { |
85 while ( (node = readdir_fs(fs_root, i)) != 0) | 81 while ( (node = readdir_fs(fs_root, i)) != 0) |
86 { | 82 { |
87 | 83 |
88 } | 84 } |
89 } | 85 } |
90 | 86 */ |
91 // TODO: Make sure that placement malloc does not overwrite the ramdisk. | |
92 printf("Mod size: "); | |
93 | 87 |
94 // Assume first 16MB: | 88 // Assume first 16MB: |
95 // TODO: get size from grub | 89 // TODO: get size from grub |
96 init_memory(0x1000000); | 90 init_memory(0x1000000); |
97 | 91 |
98 // TODO: make below a user space program! | 92 // TODO: make below a user space program! |
99 printf("Welcome!\n"); | 93 printf("Welcome!\n"); |
100 | 94 |
101 | 95 while (1) |
102 while (1==1) | |
103 { | 96 { |
104 char buffer[70]; | 97 char buffer[70]; |
105 printf(">"); | 98 printf(">"); |
106 getline(buffer, 70); | 99 getline(buffer, 70); |
107 // TODO: interpret this line with python :) | 100 // TODO: interpret this line with python :) |