Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
31:88590c42320f | 32:3a6a9b929db0 |
---|---|
13 printf("Got b at %x\n", b); | 13 printf("Got b at %x\n", b); |
14 b[0] = 'B'; | 14 b[0] = 'B'; |
15 kfree(a); | 15 kfree(a); |
16 } | 16 } |
17 | 17 |
18 multiboot_info_t *multiboot_info = 0; // Set by startup code. | |
19 | |
18 /* This routine initializes the kernel. | 20 /* This routine initializes the kernel. |
19 * We are left here in 64-bit long mode with the first 6 MB identity mapped. | 21 * We are left here in 64-bit long mode with the first 6 MB identity mapped. |
20 * */ | 22 * */ |
21 void kmain() | 23 void kmain() |
22 { | 24 { |
23 init_screen(); | 25 init_screen(); |
24 setupIDT(); | 26 setupIDT(); |
25 // init_heap(); | 27 |
28 uint64_t available_memory = 0; | |
29 | |
30 /* Display memory information from multiboot header */ | |
31 if ((multiboot_info->flags & (1<<6)) == (1<<6)) | |
32 { | |
33 multiboot_memory_map_t *mmap; | |
34 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; | |
35 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; | |
36 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) ) | |
37 { | |
38 printf("size: %d, start: 0x%x, length=0x%x, type=%d\n", mmap->size, mmap->base, mmap->length, mmap->type); | |
39 | |
40 if ( (mmap->type == 1) && (mmap->base == 0x100000) ) | |
41 { | |
42 available_memory = mmap->length; | |
43 } | |
44 } | |
45 } | |
46 | |
47 printf("Running with %d MB ram\n", available_memory / 1000000); | |
48 | |
49 fs_node_t *fs_root = 0; | |
50 | |
51 if ( (multiboot_info->flags & (1<<3)) == (1<<3)) | |
52 { | |
53 printf("Mod count: %d\n", multiboot_info->mods_count); | |
54 uint64_t i; | |
55 multiboot_module_t *mod; | |
56 for (i=0, mod=(multiboot_module_t*)(uint64_t)multiboot_info->mods_addr; i<multiboot_info->mods_count; i++, mod++) | |
57 { | |
58 printf("Mod start: %x, end: %x\n", mod->mod_start, mod->mod_end); | |
59 if (i == 0) | |
60 { | |
61 uint64_t ramdisk_location = ((uint32_t*)((uint64_t)multiboot_info->mods_addr))[0]; | |
62 fs_root = initialize_initrd(ramdisk_location); | |
63 } | |
64 } | |
65 } | |
66 | |
67 if (fs_root != 0) | |
68 { | |
69 fs_dirent_t *node = 0; | |
70 int i = 0; | |
71 while ( (node = readdir_fs(fs_root, i)) != 0) | |
72 { | |
73 | |
74 } | |
75 } | |
76 | |
77 // TODO: Make sure that placement malloc does not overwrite the ramdisk. | |
78 printf("Mod size: "); | |
26 | 79 |
27 // Assume first 16MB: | 80 // Assume first 16MB: |
28 // TODO: get size from grub | 81 // TODO: get size from grub |
29 init_memory(0x1000000); | 82 init_memory(0x1000000); |
30 | 83 |
31 // TODO: make below a user space program! | 84 // TODO: make below a user space program! |
32 printf("Welcome!\n"); | 85 printf("Welcome!\n"); |
86 | |
33 | 87 |
34 while (1==1) | 88 while (1==1) |
35 { | 89 { |
36 char buffer[70]; | 90 char buffer[70]; |
37 printf(">"); | 91 printf(">"); |