diff --git a/build.sh b/build.sh index 1235497..3e23d2f 100755 --- a/build.sh +++ b/build.sh @@ -32,6 +32,11 @@ limine_install() { echo "" } +generate_initial_ramdisk() { + echo " --> Generating initrd" + tar -C ramdisk -cvf build/initrd.tar . +} + generate_image() { echo " --> Generating Image" cd build @@ -43,6 +48,7 @@ generate_image() { cp limine/limine-cd-efi.bin iso cp limine/limine.sys iso cp ../limine.cfg iso + cp initrd.tar iso cp cmake/kernel/kernel iso/kernel.elf xorriso -as mkisofs -b limine-cd.bin \ @@ -64,6 +70,7 @@ echo "!=====[ NoxOS build script ]=====!" workspace_setup kernel_build [ ! -d "build/limine" ] && limine_install +generate_initial_ramdisk generate_image echo "!=====[ Finished ]=====!" diff --git a/kernel/inc/boot/boot_info.h b/kernel/inc/boot/boot_info.h index fbe5257..b837322 100644 --- a/kernel/inc/boot/boot_info.h +++ b/kernel/inc/boot/boot_info.h @@ -20,11 +20,12 @@ #include "limine.h" typedef struct { - struct limine_framebuffer_response* framebuffer; - struct limine_terminal_response* terminal; - struct limine_memmap_response* memory_map; - struct limine_kernel_file_response* kernel_file; - void* rsdp; + struct limine_framebuffer_response* framebuffer; + struct limine_terminal_response* terminal; + struct limine_memmap_response* memory_map; + struct limine_file* kernel_file; + struct limine_file* ramdisk_file; + void* rsdp; } boot_info_T; #endif //NOX_BOOT_INFO_H diff --git a/kernel/src/boot/limine.c b/kernel/src/boot/limine.c index b455331..33aa44e 100644 --- a/kernel/src/boot/limine.c +++ b/kernel/src/boot/limine.c @@ -16,6 +16,7 @@ #include "boot/boot_info.h" #include "utils/logger.h" #include "utils/core.h" +#include "utils/memory.h" extern void kmain(boot_info_T boot_info); @@ -39,6 +40,11 @@ static volatile struct limine_kernel_file_request kernel_file_request = { .revision = 3 }; +static volatile struct limine_module_request module_request = { + .id = LIMINE_MODULE_REQUEST, + .revision = 4 +}; + void _start() { boot_info_T boot_info; @@ -69,7 +75,28 @@ void _start() { CORE_HALT_FOREVER } log(LOG_INFO, "( LimineEntry ) Found Kernel File"); - boot_info.kernel_file = kernel_file_request.response; + boot_info.kernel_file = kernel_file_request.response->kernel_file; + + if (module_request.response == NULL) { + log(LOG_ERROR, "( LimineEntry ) no module response!"); + CORE_HALT_FOREVER + } + struct limine_file* ramdisk_file = NULL; + for (int i = 0; i < module_request.response->module_count; i++) { + struct limine_file* file = module_request.response->modules[i]; + log(LOG_INFO, "( LimineEntry ) MODULE: %s", file->path); + + if (memory_compare(file->path, "/initrd.tar", string_length(file->path))) { + ramdisk_file = file; + } + } + + if (ramdisk_file == NULL) { + log(LOG_ERROR, "( LimineEntry ) no ramdisk module!"); + CORE_HALT_FOREVER + } + log(LOG_INFO, "( LimineEntry ) Found Ramdisk File"); + boot_info.ramdisk_file = ramdisk_file; kmain(boot_info); } \ No newline at end of file diff --git a/limine.cfg b/limine.cfg index 6f5f22f..1672d35 100644 --- a/limine.cfg +++ b/limine.cfg @@ -3,3 +3,4 @@ TIMEOUT=2 :NoxOS PROTOCOL=limine KERNEL_PATH=boot:///kernel.elf + MODULE_PATH=boot:///initrd.tar diff --git a/ramdisk/test.txt b/ramdisk/test.txt new file mode 100644 index 0000000..6c3059e --- /dev/null +++ b/ramdisk/test.txt @@ -0,0 +1,11 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Proin molestie porta erat eu interdum. +Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. +Cras semper porta ligula quis condimentum. +Aliquam sed bibendum diam, sit amet gravida orci. +Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. +Proin vitae urna vel magna luctus pulvinar. +Etiam diam diam, vulputate nec eros a, bibendum tristique velit. +Donec interdum consectetur vehicula. +Vestibulum gravida varius nisi non fringilla. +Nam eu accumsan erat, ac condimentum massa.