1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-12 10:40:39 +09:00

Kernel: Move Kernel CommandLine parsing to strongly typed API.

Previously all of the CommandLine parsing was spread out around the
Kernel. Instead move it all into the Kernel CommandLine class, and
expose a strongly typed API for querying the state of options.
This commit is contained in:
Brian Gianforcaro 2021-03-03 00:51:55 -08:00 committed by Andreas Kling
parent 74881ac649
commit 84a399de5d
Notes: sideshowbarker 2024-07-18 21:45:29 +09:00
9 changed files with 143 additions and 45 deletions

View file

@ -25,6 +25,7 @@
*/
#include <Kernel/CommandLine.h>
#include <Kernel/Panic.h>
#include <Kernel/StdLib.h>
namespace Kernel {
@ -87,4 +88,92 @@ bool CommandLine::contains(const String& key) const
return m_params.contains(key);
}
UNMAP_AFTER_INIT bool CommandLine::is_ide_enabled() const
{
return !contains("disable_ide");
}
UNMAP_AFTER_INIT bool CommandLine::is_smp_enabled() const
{
return lookup("smp").value_or("off") == "on";
}
UNMAP_AFTER_INIT bool CommandLine::is_vmmouse_enabled() const
{
return lookup("vmmouse").value_or("on") == "on";
}
UNMAP_AFTER_INIT bool CommandLine::is_mmio_enabled() const
{
return lookup("pci_mmio").value_or("off") == "on";
}
UNMAP_AFTER_INIT bool CommandLine::is_legacy_time_enabled() const
{
return lookup("time").value_or("modern") == "legacy";
}
UNMAP_AFTER_INIT bool CommandLine::is_force_pio() const
{
return contains("force_pio");
}
UNMAP_AFTER_INIT String CommandLine::root_device() const
{
return lookup("root").value_or("/dev/hda");
}
UNMAP_AFTER_INIT AcpiFeatureLevel CommandLine::acpi_feature_level() const
{
auto value = kernel_command_line().lookup("acpi").value_or("on");
if (value == "limited")
return AcpiFeatureLevel::Limited;
if (value == "off")
return AcpiFeatureLevel::Disabled;
return AcpiFeatureLevel::Enabled;
}
UNMAP_AFTER_INIT HPETMode CommandLine::hpet_mode() const
{
auto hpet_mode = lookup("hpet").value_or("periodic");
if (hpet_mode == "periodic")
return HPETMode::Periodic;
if (hpet_mode == "nonperiodic")
return HPETMode::NonPeriodic;
PANIC("Unknown HPETMode: {}", hpet_mode);
}
UNMAP_AFTER_INIT BootMode CommandLine::boot_mode() const
{
const auto boot_mode = lookup("boot_mode").value_or("graphical");
if (boot_mode == "text") {
return BootMode::Text;
} else if (boot_mode == "self-test") {
return BootMode::SelfTest;
} else if (boot_mode == "graphical") {
return BootMode::Graphical;
}
PANIC("Unknown BootMode: {}", boot_mode);
}
UNMAP_AFTER_INIT bool CommandLine::is_text_mode() const
{
const auto mode = boot_mode();
return mode == BootMode::Text || mode == BootMode::SelfTest;
}
String CommandLine::userspace_init() const
{
return lookup("init").value_or("/bin/SystemServer");
}
Vector<String> CommandLine::userspace_init_args() const
{
auto init_args = lookup("init_args").value_or("").split(',');
if (!init_args.is_empty())
init_args.prepend(userspace_init());
return init_args;
}
}