aboutsummaryrefslogtreecommitdiff
path: root/kernel/initrd.c
blob: c34bcfa5e9b31dc33589cce7aa293a45b06c10b6 (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
47
48
49
50
51
52
53
#include <stddef.h>
#include <stdio.h>
#include "heap.h"
#include "multiboot.h"
#include "panic.h"

static struct multiboot_mod_t *modlist;
static unsigned int mods_count;

void initrd_read(void)
{
    if(modlist && mods_count)
    {
        printf("Number of modules: %d\n", mods_count);
        char *ptr = (char*)modlist[0].mod_start;
        while(ptr < (char*)modlist[0].mod_end)
        {
            char *name = ptr;
            ptr += 32;
            uint32_t sz = *(uint32_t*)ptr;
            ptr += 4;
            printf("File name: \"%s\"\n", name);
            printf("File length: %x\n", sz);
            char *end = ptr + sz;
            printf("Contents:\n");
            while(ptr < end)
            {
                putchar(*ptr++);
            }
        }
    }
    else
    {
        printf("No initrd loaded!\n");
    }
}

void initrd_init(struct multiboot_info_t *hdr)
{
    if(hdr->flags & (1<<3))
    {
        modlist = (struct multiboot_mod_t*)hdr->mods_addr;
        mods_count = hdr->mods_count;
        printf("Number of modules: %d\n", mods_count);
        /* prevent kmalloc from overwriting the modules */
        kmalloc_set_addr(modlist[mods_count-1].mod_end);
    }
    else
    {
        modlist = NULL;
        mods_count = 0;
    }
}