From 46e94578765d3d2f03b83421d752e5dfc3e56d34 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 2 Mar 2015 21:37:09 -0500 Subject: initrd support, not used yet --- docs/INITRD | 6 ++++++ include/kernel/initrd.h | 4 ++++ initrd | Bin 0 -> 7154 bytes kernel/initrd.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/mkinitrd.c | 34 +++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 docs/INITRD create mode 100644 include/kernel/initrd.h create mode 100644 initrd create mode 100644 kernel/initrd.c create mode 100644 tools/mkinitrd.c diff --git a/docs/INITRD b/docs/INITRD new file mode 100644 index 0000000..228c717 --- /dev/null +++ b/docs/INITRD @@ -0,0 +1,6 @@ +struct file_t +{ +char name[32]; +int size; +char data[size]; +}; diff --git a/include/kernel/initrd.h b/include/kernel/initrd.h new file mode 100644 index 0000000..c7a368c --- /dev/null +++ b/include/kernel/initrd.h @@ -0,0 +1,4 @@ +#include "multiboot.h" + +void initrd_init(struct multiboot_info_t*); +void initrd_read(void); diff --git a/initrd b/initrd new file mode 100644 index 0000000..55eda05 Binary files /dev/null and b/initrd differ diff --git a/kernel/initrd.c b/kernel/initrd.c new file mode 100644 index 0000000..c34bcfa --- /dev/null +++ b/kernel/initrd.c @@ -0,0 +1,53 @@ +#include +#include +#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; + } +} diff --git a/tools/mkinitrd.c b/tools/mkinitrd.c new file mode 100644 index 0000000..d61bbba --- /dev/null +++ b/tools/mkinitrd.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +void write_le32(int fd, uint32_t n) +{ + write(fd, &n, 4); +} + +#define MIN(x,y) (x