Add multiboot module
diff --git a/boot/grub/grub.cfg b/boot/grub/grub.cfg
index 190f8ed..856a4ea 100644
--- a/boot/grub/grub.cfg
+++ b/boot/grub/grub.cfg
@@ -1,6 +1,6 @@
menuentry "Bluejay" {
multiboot /boot/kernel.elf
- module initrd.img
+ module /boot/initrd.img
}
set timeout=1
diff --git a/src/kernel/Makefile b/src/kernel/Makefile
index 60a95ab..0a95915 100644
--- a/src/kernel/Makefile
+++ b/src/kernel/Makefile
@@ -14,7 +14,8 @@
scan_codes.o \
kheap.o \
alloc.o \
- vfs.o
+ vfs.o \
+ multiboot.o
JAYROOT = ../../
CFLAGS = -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding \
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 9485def..5c04768 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -5,8 +5,9 @@
#include "paging.h"
#include "timer.h"
#include "vga.h"
+#include "multiboot.h"
-int kmain(void *mboot)
+int kmain(struct multiboot *mboot)
{
init_paging();
init_vga();
@@ -49,6 +50,17 @@
*four = 4;
kprintf("Allocated four = %d (%x)\n", *four, four);
+ // Load initrd
+ struct multiboot mb = make_multiboot_physical(mboot);
+
+ kassert(mb.mods_count, "No multiboot modules loaded!");
+ kprintf("mboot->mods_addr = %d (0x%x)\n", mb.mods_addr, mb.mods_addr);
+ uint *initrd_loc = mb.mods_addr[0],
+ *initrd_end = mboot->mods_addr[1];
+
+ kprintf("initrd is at 0x%x to 0x%x\n", initrd_loc, initrd_end);
+
+
asm volatile("sti");
while (true)
diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c
new file mode 100644
index 0000000..13e1f98
--- /dev/null
+++ b/src/kernel/multiboot.c
@@ -0,0 +1,25 @@
+#include "multiboot.h"
+#include "io.h"
+#include "log.h"
+
+#define TO_VIRT(val, t) val = (t)((size_t)val + 0xc0000000u)
+
+// old should be a VIRTUAL address
+struct multiboot make_multiboot_physical(struct multiboot *old)
+{
+ struct multiboot mb;
+ memcpy(&mb, old, sizeof(mb));
+
+ // Make modules physical
+ TO_VIRT(mb.mods_addr, uint **);
+ TO_VIRT(mb.cmdline, char *);
+
+ kprintf("mb.mods_addr = %d, 0x%x\n", mb.mods_addr, mb.mods_addr);
+ kassert((size_t)mb.mods_addr > 0xc0000000, "mb.mods_addr PHYSICAL");
+ for (int i = 0; i < mb.mods_count + 1; i++)
+ {
+ TO_VIRT(mb.mods_addr[i], uint *);
+ }
+
+ return mb;
+}
diff --git a/src/kernel/multiboot.h b/src/kernel/multiboot.h
new file mode 100644
index 0000000..3aaa0d0
--- /dev/null
+++ b/src/kernel/multiboot.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "kint.h"
+
+struct multiboot
+{
+ uint flags;
+ uint mem_lower;
+ uint mem_upper;
+ uint boot_device;
+ char *cmdline;
+ uint mods_count;
+ uint **mods_addr;
+ uint num;
+ uint size;
+ uint addr;
+ uint shndx;
+ uint mmap_length;
+ uint mmap_addr;
+ uint drives_length;
+ uint drives_addr;
+ uint config_table;
+ uint boot_loader_name;
+ uint apm_table;
+ uint vbe_control_info;
+ uint vbe_mode_info;
+ uint vbe_mode;
+ uint vbe_interface_seg;
+ uint vbe_interface_off;
+ uint vbe_interface_len;
+};
+
+struct multiboot make_multiboot_physical(struct multiboot *old);