1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <panic.h>
#include <string.h>
#include <arch/i686/mboot.h>
#include <arch/i686/memory.h>
#include <arch/i686/acpi.h>
static struct BootInfo info;
static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) {
if (len >= CMDLINE_MAX)
panic("multiboot2 cmd line to long\nmax is %d but was provided %d\n",
CMDLINE_MAX, len);
memcpy(tag->data.cmdline, data, len);
info.tags[ID_CMDLINE] = *tag;
}
static void read_memorymap(struct BootTag *tag, uint32_t *data) {
tag->data.memory_map = (struct MemoryMap *) data;
info.tags[iD_MEMORYMAP] = *tag;
}
static void read_rsdp(struct BootTag *tag, char *data) {
tag->data.rsdp = (struct RootSystemDescriptionPointer *) data;
info.tags[ID_RSDP] = *tag;
}
static uint32_t *read_tag(uint32_t *data) {
struct BootTag tag;
tag.type = ((uint16_t*)data)[0];
tag.size = data[1];
tag.valid = 1;
uint8_t data_len = tag.size - 2 * sizeof(uint32_t);
switch (tag.type) {
case ID_CMDLINE:
read_cmdline(&tag, (char *)(data + 2), data_len);
break;
case iD_MEMORYMAP:
read_memorymap(&tag, data + 2);
break;
case ID_RSDP:
read_rsdp(&tag, (char *) (data + 2));
break;
default:
break;
}
if(tag.size % 8 != 0) {
tag.size += 8 - (tag.size % 8);
}
return data + tag.size / sizeof(uint32_t);
}
void load_boot_info(void* boot_info) {
memset(&info, 0, sizeof(boot_info));
uint32_t* data = (uint32_t*) boot_info;
info.total_size = *data++;
info.reserved = *data++;
while((uint8_t*) data < (uint8_t*) boot_info + info.total_size) {
data = read_tag(data);
}
}
bool get_boot_tag(enum BootTagID id, struct BootTag **tag) {
*tag = &info.tags[id];
return (*tag)->valid;
}
|