aboutsummaryrefslogtreecommitdiff
path: root/kernel/initrd.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-03-02 21:37:09 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-03-02 21:37:09 -0500
commit46e94578765d3d2f03b83421d752e5dfc3e56d34 (patch)
tree0a7d4187e8e62e1fccdf0dc8ee89e4ffcdf7aac7 /kernel/initrd.c
parent35d98182c5b86c25eb4e7fd18fc68f240683960b (diff)
downloadkappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.zip
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.gz
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.bz2
kappa-46e94578765d3d2f03b83421d752e5dfc3e56d34.tar.xz
initrd support, not used yet
Diffstat (limited to 'kernel/initrd.c')
-rw-r--r--kernel/initrd.c53
1 files changed, 53 insertions, 0 deletions
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 <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;
+ }
+}