annotate cos/kernel/multiboot.c @ 75:ba11d99b1d4a

Added qformlayout..
author windel
date Sun, 11 Nov 2012 11:28:28 +0100
parents 5c20bd53cccd
children
rev   line source
37
5c20bd53cccd Cleanup
windel
parents:
diff changeset
1 #include "kernel.h"
5c20bd53cccd Cleanup
windel
parents:
diff changeset
2
5c20bd53cccd Cleanup
windel
parents:
diff changeset
3 multiboot_info_t *multiboot_info = 0; // Set by startup code.
5c20bd53cccd Cleanup
windel
parents:
diff changeset
4 uint64_t available_memory = 0;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
5 uint64_t ramdisk_location = 0;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
6
5c20bd53cccd Cleanup
windel
parents:
diff changeset
7 /* Retrieve memory information from multiboot header */
5c20bd53cccd Cleanup
windel
parents:
diff changeset
8 void read_multiboot_info()
5c20bd53cccd Cleanup
windel
parents:
diff changeset
9 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
10 if ((multiboot_info->flags & (1 << 6)) == (1 << 6))
5c20bd53cccd Cleanup
windel
parents:
diff changeset
11 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
12 multiboot_memory_map_t *mmap;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
13 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
14 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
15 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) )
5c20bd53cccd Cleanup
windel
parents:
diff changeset
16 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
17 /*
5c20bd53cccd Cleanup
windel
parents:
diff changeset
18 printf("size: %d, start: 0x%x, length=0x%x, type=%d\n", mmap->size,
5c20bd53cccd Cleanup
windel
parents:
diff changeset
19 mmap->base, mmap->length, mmap->type);
5c20bd53cccd Cleanup
windel
parents:
diff changeset
20 */
5c20bd53cccd Cleanup
windel
parents:
diff changeset
21
5c20bd53cccd Cleanup
windel
parents:
diff changeset
22 if ( (mmap->type == 1) && (mmap->base == 0x100000) )
5c20bd53cccd Cleanup
windel
parents:
diff changeset
23 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
24 available_memory = mmap->length;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
25 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
26 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
27 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
28
5c20bd53cccd Cleanup
windel
parents:
diff changeset
29 if (available_memory == 0)
5c20bd53cccd Cleanup
windel
parents:
diff changeset
30 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
31 panic("Found no usable memory in grub's memory map\n");
5c20bd53cccd Cleanup
windel
parents:
diff changeset
32 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
33
5c20bd53cccd Cleanup
windel
parents:
diff changeset
34 if ((multiboot_info->flags & (1 << 3)) == (1 << 3))
5c20bd53cccd Cleanup
windel
parents:
diff changeset
35 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
36 uint64_t i;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
37 multiboot_module_t *mod = (multiboot_module_t*)(uint64_t)multiboot_info->mods_addr;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
38 for (i=0; i<multiboot_info->mods_count; i++)
5c20bd53cccd Cleanup
windel
parents:
diff changeset
39 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
40 // TODO: determine better way of finding the initrd module.
5c20bd53cccd Cleanup
windel
parents:
diff changeset
41 if (i == 0)
5c20bd53cccd Cleanup
windel
parents:
diff changeset
42 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
43 ramdisk_location = mod->mod_start;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
44 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
45
5c20bd53cccd Cleanup
windel
parents:
diff changeset
46 // Make sure that placement malloc does not overwrite the ramdisk.
5c20bd53cccd Cleanup
windel
parents:
diff changeset
47 uint64_t new_placement = (uint64_t)mod->mod_end;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
48 if (new_placement > placement_address)
5c20bd53cccd Cleanup
windel
parents:
diff changeset
49 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
50 if ((new_placement & 0xFFF) != 0)
5c20bd53cccd Cleanup
windel
parents:
diff changeset
51 {
5c20bd53cccd Cleanup
windel
parents:
diff changeset
52 new_placement = (new_placement & (~0xFFF)) + 0x1000; // Align to 4 KiB page.
5c20bd53cccd Cleanup
windel
parents:
diff changeset
53 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
54 placement_address = new_placement;
5c20bd53cccd Cleanup
windel
parents:
diff changeset
55 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
56 mod++; // Go to next module.
5c20bd53cccd Cleanup
windel
parents:
diff changeset
57 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
58 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
59 }
5c20bd53cccd Cleanup
windel
parents:
diff changeset
60