summaryrefslogtreecommitdiff
path: root/Kernel/CommandLine.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-05-21 20:42:33 +0300
committerLinus Groh <mail@linusgroh.de>2021-05-21 22:38:26 +0100
commit5e81464245768b54a68a0d805b67355df58a646d (patch)
tree9f3820b6236abe93b1737d9c220a46c008abf4df /Kernel/CommandLine.cpp
parentb8f0a9c974360ebcb74af73e700d44f8506f8cb2 (diff)
downloadserenity-5e81464245768b54a68a0d805b67355df58a646d.zip
Kernel/Commandline: Allow the user to specify an embedded string
This is by default left empty, so people won't run the kernel in a mode which they didn't want to. The embedded string will override the supplied commandline from the bootloader, which is good for debugging sessions. This change seemed important for me, because I debug the kernel on bare metal with iPXE, and every change to the commandline meant that I needed rewrite a new iPXE USB image with a modified iPXE script.
Diffstat (limited to 'Kernel/CommandLine.cpp')
-rw-r--r--Kernel/CommandLine.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp
index 2fdad516a1..98684058e7 100644
--- a/Kernel/CommandLine.cpp
+++ b/Kernel/CommandLine.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/StringBuilder.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Panic.h>
#include <Kernel/StdLib.h>
@@ -11,6 +12,7 @@
namespace Kernel {
static char s_cmd_line[1024];
+static constexpr StringView s_embedded_cmd_line = "";
static CommandLine* s_the;
UNMAP_AFTER_INIT void CommandLine::early_initialize(const char* cmd_line)
@@ -37,13 +39,19 @@ UNMAP_AFTER_INIT void CommandLine::initialize()
dmesgln("Kernel Commandline: {}", kernel_command_line().string());
}
-UNMAP_AFTER_INIT CommandLine::CommandLine(const String& string)
- : m_string(string)
+UNMAP_AFTER_INIT void CommandLine::build_commandline(const String& cmdline_from_bootloader)
{
- s_the = this;
+ StringBuilder builder;
+ builder.append(cmdline_from_bootloader);
+ if (!s_embedded_cmd_line.is_empty()) {
+ builder.append(" ");
+ builder.append(s_embedded_cmd_line);
+ }
+ m_string = builder.to_string();
+}
- const auto& args = m_string.split(' ');
- m_params.ensure_capacity(args.size());
+UNMAP_AFTER_INIT void CommandLine::add_arguments(const Vector<String>& args)
+{
for (auto&& str : args) {
if (str == "") {
continue;
@@ -59,6 +67,15 @@ UNMAP_AFTER_INIT CommandLine::CommandLine(const String& string)
}
}
+UNMAP_AFTER_INIT CommandLine::CommandLine(const String& cmdline_from_bootloader)
+{
+ s_the = this;
+ build_commandline(cmdline_from_bootloader);
+ const auto& args = m_string.split(' ');
+ m_params.ensure_capacity(args.size());
+ add_arguments(args);
+}
+
Optional<String> CommandLine::lookup(const String& key) const
{
return m_params.get(key);