Add a global initrd TarStream to make the initial ramdisk accessible everywhere
All checks were successful
continuous-integration/drone/push Build is passing

It's also mapped into virtual memory instead of directly going into the physical location!!
This commit is contained in:
apio 2022-12-23 11:33:23 +01:00
parent 6ff92b1714
commit ad0f6546d7
Signed by: apio
GPG Key ID: B8A7D06E42258954
6 changed files with 34 additions and 4 deletions

View File

@ -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")

18
kernel/src/InitRD.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "InitRD.h"
#include "arch/MMU.h"
#include "boot/bootboot.h"
#include "memory/MemoryManager.h"
#include <luna/Alignment.h>
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);
}

9
kernel/src/InitRD.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <luna/TarStream.h>
extern TarStream g_initrd;
namespace InitRD
{
void initialize();
}

View File

@ -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();

View File

@ -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 <luna/CString.h>
#include <luna/Result.h>
#include <luna/TarStream.h>
#include <luna/Units.h>
extern const BOOTBOOT bootboot;
@ -67,9 +67,8 @@ Result<void> 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<void> 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());
}

View File

@ -24,6 +24,7 @@ class TarStream
friend class TarStream;
};
TarStream() = default;
TarStream(void* base, usize size);
void initialize(void* base, usize size);