mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 17:37:35 +00:00
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.
This commit is contained in:
parent
b8f0a9c974
commit
5e81464245
2 changed files with 25 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <Kernel/CommandLine.h>
|
#include <Kernel/CommandLine.h>
|
||||||
#include <Kernel/Panic.h>
|
#include <Kernel/Panic.h>
|
||||||
#include <Kernel/StdLib.h>
|
#include <Kernel/StdLib.h>
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
static char s_cmd_line[1024];
|
static char s_cmd_line[1024];
|
||||||
|
static constexpr StringView s_embedded_cmd_line = "";
|
||||||
static CommandLine* s_the;
|
static CommandLine* s_the;
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void CommandLine::early_initialize(const char* cmd_line)
|
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());
|
dmesgln("Kernel Commandline: {}", kernel_command_line().string());
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT CommandLine::CommandLine(const String& string)
|
UNMAP_AFTER_INIT void CommandLine::build_commandline(const String& cmdline_from_bootloader)
|
||||||
: m_string(string)
|
|
||||||
{
|
{
|
||||||
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(' ');
|
UNMAP_AFTER_INIT void CommandLine::add_arguments(const Vector<String>& args)
|
||||||
m_params.ensure_capacity(args.size());
|
{
|
||||||
for (auto&& str : args) {
|
for (auto&& str : args) {
|
||||||
if (str == "") {
|
if (str == "") {
|
||||||
continue;
|
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
|
Optional<String> CommandLine::lookup(const String& key) const
|
||||||
{
|
{
|
||||||
return m_params.get(key);
|
return m_params.get(key);
|
||||||
|
|
|
@ -77,6 +77,9 @@ public:
|
||||||
private:
|
private:
|
||||||
CommandLine(const String&);
|
CommandLine(const String&);
|
||||||
|
|
||||||
|
void add_arguments(const Vector<String>& args);
|
||||||
|
void build_commandline(const String& cmdline_from_bootloader);
|
||||||
|
|
||||||
String m_string;
|
String m_string;
|
||||||
HashMap<String, String> m_params;
|
HashMap<String, String> m_params;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue