diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 9cf0febf..66637a77 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -15,6 +15,7 @@ set(SOURCES src/thread/Spinlock.cpp src/thread/Thread.cpp src/thread/Scheduler.cpp + src/InitRD.cpp ) if("${ARCH}" MATCHES "x86_64") diff --git a/kernel/src/InitRD.cpp b/kernel/src/InitRD.cpp new file mode 100644 index 00000000..c8d7d957 --- /dev/null +++ b/kernel/src/InitRD.cpp @@ -0,0 +1,18 @@ +#include "InitRD.h" +#include "arch/MMU.h" +#include "boot/bootboot.h" +#include "memory/MemoryManager.h" +#include + +TarStream g_initrd; +extern const BOOTBOOT bootboot; + +void InitRD::initialize() +{ + u64 virtual_initrd_address = + MemoryManager::get_kernel_mapping_for_frames( + bootboot.initrd_ptr, get_blocks_from_size(bootboot.initrd_size, ARCH_PAGE_SIZE), MMU::NoExecute) + .expect_value("Unable to map the initial ramdisk into virtual memory"); + + g_initrd.initialize((void*)virtual_initrd_address, bootboot.initrd_size); +} \ No newline at end of file diff --git a/kernel/src/InitRD.h b/kernel/src/InitRD.h new file mode 100644 index 00000000..632a8e54 --- /dev/null +++ b/kernel/src/InitRD.h @@ -0,0 +1,9 @@ +#pragma once +#include + +extern TarStream g_initrd; + +namespace InitRD +{ + void initialize(); +} \ No newline at end of file diff --git a/kernel/src/boot/Init.cpp b/kernel/src/boot/Init.cpp index 0aba173e..e28471ab 100644 --- a/kernel/src/boot/Init.cpp +++ b/kernel/src/boot/Init.cpp @@ -1,4 +1,5 @@ #include "boot/Init.h" +#include "InitRD.h" #include "Log.h" #include "arch/CPU.h" #include "boot/bootboot.h" @@ -28,6 +29,7 @@ void Init::early_init() setup_log(log_debug_enabled(), log_serial_enabled(), true); MemoryManager::init(); + InitRD::initialize(); CPU::platform_init(); diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index a8e8622d..cfd37243 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -1,3 +1,4 @@ +#include "InitRD.h" #include "Log.h" #include "arch/CPU.h" #include "arch/MMU.h" @@ -11,7 +12,6 @@ #include "thread/Scheduler.h" #include #include -#include #include extern const BOOTBOOT bootboot; @@ -67,9 +67,8 @@ Result init() kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars()); kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars()); - TarStream stream((void*)bootboot.initrd_ptr, bootboot.initrd_size); TarStream::Entry entry; - while (TRY(stream.read_next_entry().try_set_value_with_specific_error(entry, 0))) + while (TRY(g_initrd.read_next_entry().try_set_value_with_specific_error(entry, 0))) { if (entry.type == TarStream::EntryType::RegularFile) { @@ -78,7 +77,7 @@ Result init() if (!strcmp(entry.name, "sys/config")) { - auto contents = TRY(stream.read_contents_as_string(entry, 0, entry.size)); + auto contents = TRY(g_initrd.read_contents_as_string(entry, 0, entry.size)); kinfoln("%s", contents.chars()); } diff --git a/luna/include/luna/TarStream.h b/luna/include/luna/TarStream.h index fede39dd..29506dbe 100644 --- a/luna/include/luna/TarStream.h +++ b/luna/include/luna/TarStream.h @@ -24,6 +24,7 @@ class TarStream friend class TarStream; }; + TarStream() = default; TarStream(void* base, usize size); void initialize(void* base, usize size);