1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:15:07 +00:00

Kernel: Copy the kernel command line to a good location at boot

When building the kernel with -O2, we somehow ended up with the kernel
command line outside of the lower 8MB of physical memory. Since we don't
map that area in our initial page table setup, we would triple fault
when trying to parse the command line.

This patch sidesteps the issue by copying the (first 4KB of) the kernel
command line to a buffer in a known safe location at boot.
This commit is contained in:
Andreas Kling 2021-02-23 19:25:58 +01:00
parent 4172a46fb5
commit 5100dabb96
2 changed files with 22 additions and 3 deletions

View file

@ -91,6 +91,8 @@ extern "C" u8* end_of_safemem_atomic_text;
multiboot_module_entry_t multiboot_copy_boot_modules_array[16];
size_t multiboot_copy_boot_modules_count;
extern "C" const char kernel_cmdline[4096];
namespace Kernel {
[[noreturn]] static void init_stage2(void*);
@ -122,7 +124,7 @@ extern "C" UNMAP_AFTER_INIT [[noreturn]] void init()
// We need to copy the command line before kmalloc is initialized,
// as it may overwrite parts of multiboot!
CommandLine::early_initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
CommandLine::early_initialize(kernel_cmdline);
memcpy(multiboot_copy_boot_modules_array, (u8*)low_physical_to_virtual(multiboot_info_ptr->mods_addr), multiboot_info_ptr->mods_count * sizeof(multiboot_module_entry_t));
multiboot_copy_boot_modules_count = multiboot_info_ptr->mods_count;
s_bsp_processor.early_initialize(0);
@ -328,9 +330,9 @@ UNMAP_AFTER_INIT void setup_serial_debug()
// serial_debug will output all the klog() and dbgln() data to COM1 at
// 8-N-1 57600 baud. this is particularly useful for debugging the boot
// process on live hardware.
u32 cmdline = low_physical_to_virtual(multiboot_info_ptr->cmdline);
if (cmdline && StringView(reinterpret_cast<const char*>(cmdline)).contains("serial_debug"))
if (StringView(kernel_cmdline).contains("serial_debug")) {
set_serial_debug(true);
}
}
extern "C" {