Add CPIO initial ramdisk with build infrastructure and parser (AI)
Build system changes: - scripts/gen_initrd.sh packs all files from apps/ into a newc-format CPIO archive at build/isodir/boot/initrd.cpio. - CMakeLists.txt adds 'initrd' target as ISO dependency. GRUB loads the archive as a Multiboot2 module via 'module2 /boot/initrd.cpio'. - apps/README added as placeholder file for initial ramdisk content. Kernel changes: - kernel.c scans Multiboot2 tags for MULTIBOOT_TAG_TYPE_MODULE to find the initrd's physical address range, then passes it to cpio_init(). - cpio.c/h implements a parser for the SVR4/newc CPIO format: - cpio_init(): lists archive contents on startup - cpio_find(): look up a file by name (handles ./ prefix) - cpio_next(): iterate through all entries - cpio_count(): count files in archive - The initrd lives in identity-mapped physical memory, so no additional mapping is needed to access it. Verified in QEMU: GRUB loads the module at 0x0014A000, CPIO parser finds the README file (38 bytes). All existing functionality (Ring 3 processes, syscalls) continues to work.
This commit is contained in:
29
src/kernel.c
29
src/kernel.c
@@ -13,6 +13,7 @@
|
||||
#include "tss.h"
|
||||
#include "syscall.h"
|
||||
#include "process.h"
|
||||
#include "cpio.h"
|
||||
|
||||
void offset_print(const char *str)
|
||||
{
|
||||
@@ -54,6 +55,26 @@ void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
init_pmm(addr);
|
||||
offset_print("PMM initialized\n");
|
||||
|
||||
/* Scan Multiboot2 tags for the initrd module */
|
||||
uint32_t initrd_start = 0, initrd_end = 0;
|
||||
{
|
||||
struct multiboot_tag *tag;
|
||||
for (tag = (struct multiboot_tag *)(addr + 8);
|
||||
tag->type != MULTIBOOT_TAG_TYPE_END;
|
||||
tag = (struct multiboot_tag *)((uint8_t *)tag + ((tag->size + 7) & ~7u))) {
|
||||
if (tag->type == MULTIBOOT_TAG_TYPE_MODULE) {
|
||||
struct multiboot_tag_module *mod = (struct multiboot_tag_module *)tag;
|
||||
initrd_start = mod->mod_start;
|
||||
initrd_end = mod->mod_end;
|
||||
offset_print("Initrd module at ");
|
||||
print_hex(initrd_start);
|
||||
offset_print(" to ");
|
||||
print_hex(initrd_end);
|
||||
break; /* Use first module */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_paging();
|
||||
offset_print("Paging initialized\n");
|
||||
|
||||
@@ -72,6 +93,14 @@ void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
init_kmalloc();
|
||||
offset_print("Memory allocator initialized\n");
|
||||
|
||||
/* Initialize CPIO ramdisk if module was loaded */
|
||||
if (initrd_start != 0) {
|
||||
cpio_init((const void *)initrd_start, initrd_end - initrd_start);
|
||||
offset_print("CPIO ramdisk initialized\n");
|
||||
} else {
|
||||
offset_print("No initrd module found\n");
|
||||
}
|
||||
|
||||
init_tss();
|
||||
offset_print("TSS initialized\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user