blob: bf15eca3c19c3401a603ace86cd6c41667e9e9a5 (
plain)
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
|
#include "comus/memory.h"
#include <comus/mboot.h>
#include "mboot.h"
#define MULTIBOOT_TAG_TYPE_MODULE 3
struct multiboot_tag_module {
uint32_t type;
uint32_t size;
uint32_t mod_start;
uint32_t mod_end;
char cmdline[];
};
static void *mapped_addr = NULL;
size_t initrd_len;
void *mboot_get_initrd(size_t *len)
{
struct multiboot_tag_module *mod;
void *tag, *phys;
// if already loaded, return
if (mapped_addr) {
*len = initrd_len;
return mapped_addr;
}
// locate
tag = locate_mboot_table(MULTIBOOT_TAG_TYPE_MODULE);
if (tag == NULL)
return NULL;
mod = (struct multiboot_tag_module *)tag;
phys = (void *)(uintptr_t)mod->mod_start;
initrd_len = mod->mod_end - mod->mod_start;
// map addr
mapped_addr = kmapaddr(phys, NULL, initrd_len, F_PRESENT | F_WRITEABLE);
if (mapped_addr == NULL)
return NULL;
*len = initrd_len;
return mapped_addr;
}
|