summaryrefslogtreecommitdiff
path: root/Kernel/CommandLine.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2021-03-03 00:51:55 -0800
committerAndreas Kling <kling@serenityos.org>2021-03-03 11:05:16 +0100
commit84a399de5d977009b07652bf2dfefaff163693f8 (patch)
tree1ec685482477ecf8177dcf68ac0190e8a7ff3fbe /Kernel/CommandLine.cpp
parent74881ac649742ea5b1b34c78ee365440e04ef046 (diff)
downloadserenity-84a399de5d977009b07652bf2dfefaff163693f8.zip
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.
Diffstat (limited to 'Kernel/CommandLine.cpp')
-rw-r--r--Kernel/CommandLine.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/Kernel/CommandLine.cpp b/Kernel/CommandLine.cpp
index 2bc0679646..005cd6080f 100644
--- a/Kernel/CommandLine.cpp
+++ b/Kernel/CommandLine.cpp
@@ -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;
+}
+
}