1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 14:45:08 +00:00

Kernel: Rename KParams => Kernel::CommandLine

Let's make this read more like English.
This commit is contained in:
Andreas Kling 2020-04-08 13:54:44 +02:00
parent dc7340332d
commit a7bbfda034
7 changed files with 59 additions and 42 deletions

View file

@ -24,21 +24,29 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <Kernel/KParams.h> #include <Kernel/CommandLine.h>
static KParams* s_the; namespace Kernel {
KParams& KParams::the() static CommandLine* s_the;
const CommandLine& kernel_command_line()
{ {
ASSERT(s_the);
return *s_the; return *s_the;
} }
KParams::KParams(const String& cmdline) void CommandLine::initialize(const String& string)
: m_cmdline(cmdline) {
s_the = new CommandLine(string);
}
CommandLine::CommandLine(const String& string)
: m_string(string)
{ {
s_the = this; s_the = this;
for (auto str : m_cmdline.split(' ')) { for (auto str : m_string.split(' ')) {
if (str == "") { if (str == "") {
continue; continue;
} }
@ -53,12 +61,14 @@ KParams::KParams(const String& cmdline)
} }
} }
String KParams::get(const String& key) const String CommandLine::get(const String& key) const
{ {
return m_params.get(key).value_or({}); return m_params.get(key).value_or({});
} }
bool KParams::has(const String& key) const bool CommandLine::contains(const String& key) const
{ {
return m_params.contains(key); return m_params.contains(key);
} }
}

View file

@ -29,18 +29,24 @@
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/String.h> #include <AK/String.h>
class KParams { namespace Kernel {
AK_MAKE_ETERNAL
class CommandLine {
AK_MAKE_ETERNAL;
public: public:
static KParams& the(); static void initialize(const String&);
KParams(const String& cmdline); const String& string() const { return m_string; }
const String& cmdline() const { return m_cmdline; }
String get(const String& key) const; String get(const String& key) const;
bool has(const String& key) const; bool contains(const String& key) const;
private: private:
String m_cmdline; CommandLine(const String&);
String m_string;
HashMap<String, String> m_params; HashMap<String, String> m_params;
}; };
const CommandLine& kernel_command_line();
}

View file

@ -33,6 +33,7 @@
#include <AK/JsonObjectSerializer.h> #include <AK/JsonObjectSerializer.h>
#include <AK/JsonValue.h> #include <AK/JsonValue.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Devices/BlockDevice.h> #include <Kernel/Devices/BlockDevice.h>
#include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileBackedFileSystem.h> #include <Kernel/FileSystem/FileBackedFileSystem.h>
@ -42,7 +43,6 @@
#include <Kernel/Interrupts/GenericInterruptHandler.h> #include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Interrupts/InterruptManagement.h> #include <Kernel/Interrupts/InterruptManagement.h>
#include <Kernel/KBufferBuilder.h> #include <Kernel/KBufferBuilder.h>
#include <Kernel/KParams.h>
#include <Kernel/Module.h> #include <Kernel/Module.h>
#include <Kernel/Net/LocalSocket.h> #include <Kernel/Net/LocalSocket.h>
#include <Kernel/Net/NetworkAdapter.h> #include <Kernel/Net/NetworkAdapter.h>
@ -404,7 +404,8 @@ Optional<KBuffer> procfs$uptime(InodeIdentifier)
Optional<KBuffer> procfs$cmdline(InodeIdentifier) Optional<KBuffer> procfs$cmdline(InodeIdentifier)
{ {
KBufferBuilder builder; KBufferBuilder builder;
builder.appendf("%s\n", KParams::the().cmdline().characters()); builder.append(kernel_command_line().string());
builder.append('\n');
return builder.build(); return builder.build();
} }

View file

@ -15,6 +15,7 @@ OBJS = \
../Libraries/LibBareMetal/Output/kprintf.o \ ../Libraries/LibBareMetal/Output/kprintf.o \
../Libraries/LibBareMetal/StdLib.o \ ../Libraries/LibBareMetal/StdLib.o \
Arch/i386/CPU.o \ Arch/i386/CPU.o \
CommandLine.o \
Interrupts/InterruptManagement.o \ Interrupts/InterruptManagement.o \
Interrupts/APIC.o \ Interrupts/APIC.o \
Interrupts/IOAPIC.o \ Interrupts/IOAPIC.o \
@ -71,7 +72,6 @@ OBJS = \
Heap/SlabAllocator.o \ Heap/SlabAllocator.o \
Heap/kmalloc.o \ Heap/kmalloc.o \
KBufferBuilder.o \ KBufferBuilder.o \
KParams.o \
KSyms.o \ KSyms.o \
Lock.o \ Lock.o \
Net/E1000NetworkAdapter.o \ Net/E1000NetworkAdapter.o \

View file

@ -25,7 +25,7 @@
*/ */
#include <Kernel/ACPI/ACPIParser.h> #include <Kernel/ACPI/ACPIParser.h>
#include <Kernel/KParams.h> #include <Kernel/CommandLine.h>
#include <Kernel/Net/E1000NetworkAdapter.h> #include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Net/RTL8139NetworkAdapter.h> #include <Kernel/Net/RTL8139NetworkAdapter.h>
#include <Kernel/PCI/IOAccess.h> #include <Kernel/PCI/IOAccess.h>
@ -100,7 +100,7 @@ PCI::Initializer::Initializer()
} }
bool PCI::Initializer::test_acpi() bool PCI::Initializer::test_acpi()
{ {
if ((KParams::the().has("noacpi")) || !ACPI::Parser::the().is_operable()) if ((kernel_command_line().contains("noacpi")) || !ACPI::Parser::the().is_operable())
return false; return false;
else else
return true; return true;

View file

@ -25,7 +25,7 @@
*/ */
#include <Kernel/ACPI/ACPIParser.h> #include <Kernel/ACPI/ACPIParser.h>
#include <Kernel/KParams.h> #include <Kernel/CommandLine.h>
#include <Kernel/Scheduler.h> #include <Kernel/Scheduler.h>
#include <Kernel/Time/HPET.h> #include <Kernel/Time/HPET.h>
#include <Kernel/Time/HPETComparator.h> #include <Kernel/Time/HPETComparator.h>
@ -148,10 +148,10 @@ Vector<size_t> TimeManagement::scan_for_non_periodic_timers()
bool TimeManagement::is_hpet_periodic_mode_allowed() bool TimeManagement::is_hpet_periodic_mode_allowed()
{ {
if (!KParams::the().has("hpet")) { if (!kernel_command_line().contains("hpet"))
return true; return true;
}
auto hpet_mode = KParams::the().get("hpet"); auto hpet_mode = kernel_command_line().get("hpet");
if (hpet_mode == "periodic") if (hpet_mode == "periodic")
return true; return true;
if (hpet_mode == "nonperiodic") if (hpet_mode == "nonperiodic")

View file

@ -36,6 +36,7 @@
#include <Kernel/ACPI/MultiProcessorParser.h> #include <Kernel/ACPI/MultiProcessorParser.h>
#include <Kernel/Arch/i386/CPU.h> #include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CMOS.h> #include <Kernel/CMOS.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Devices/BXVGADevice.h> #include <Kernel/Devices/BXVGADevice.h>
#include <Kernel/Devices/DebugLogDevice.h> #include <Kernel/Devices/DebugLogDevice.h>
#include <Kernel/Devices/DiskPartition.h> #include <Kernel/Devices/DiskPartition.h>
@ -60,7 +61,6 @@
#include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/APIC.h>
#include <Kernel/Interrupts/InterruptManagement.h> #include <Kernel/Interrupts/InterruptManagement.h>
#include <Kernel/Interrupts/PIC.h> #include <Kernel/Interrupts/PIC.h>
#include <Kernel/KParams.h>
#include <Kernel/Multiboot.h> #include <Kernel/Multiboot.h>
#include <Kernel/Net/LoopbackAdapter.h> #include <Kernel/Net/LoopbackAdapter.h>
#include <Kernel/Net/NetworkTask.h> #include <Kernel/Net/NetworkTask.h>
@ -101,11 +101,11 @@ extern "C" [[noreturn]] void init()
kmalloc_init(); kmalloc_init();
slab_alloc_init(); slab_alloc_init();
new KParams(String(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)))); CommandLine::initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline)));
MemoryManager::initialize(); MemoryManager::initialize();
bool text_debug = KParams::the().has("text_debug"); bool text_debug = kernel_command_line().contains("text_debug");
gdt_init(); gdt_init();
idt_init(); idt_init();
@ -210,17 +210,17 @@ void init_stage2()
new RandomDevice; new RandomDevice;
new PTYMultiplexer; new PTYMultiplexer;
bool dmi_unreliable = KParams::the().has("dmi_unreliable"); bool dmi_unreliable = kernel_command_line().contains("dmi_unreliable");
if (dmi_unreliable) { if (dmi_unreliable) {
DMIDecoder::initialize_untrusted(); DMIDecoder::initialize_untrusted();
} else { } else {
DMIDecoder::initialize(); DMIDecoder::initialize();
} }
bool text_debug = KParams::the().has("text_debug"); bool text_debug = kernel_command_line().contains("text_debug");
bool force_pio = KParams::the().has("force_pio"); bool force_pio = kernel_command_line().contains("force_pio");
auto root = KParams::the().get("root"); auto root = kernel_command_line().get("root");
if (root.is_empty()) { if (root.is_empty()) {
root = "/dev/hda"; root = "/dev/hda";
} }
@ -379,12 +379,12 @@ extern "C" int __cxa_atexit(void (*)(void*), void*, void*)
void setup_acpi() void setup_acpi()
{ {
if (!KParams::the().has("acpi")) { if (!kernel_command_line().contains("acpi")) {
ACPI::DynamicParser::initialize_without_rsdp(); ACPI::DynamicParser::initialize_without_rsdp();
return; return;
} }
auto acpi = KParams::the().get("acpi"); auto acpi = kernel_command_line().get("acpi");
if (acpi == "off") { if (acpi == "off") {
ACPI::Parser::initialize_limited(); ACPI::Parser::initialize_limited();
return; return;
@ -404,11 +404,11 @@ void setup_acpi()
void setup_vmmouse() void setup_vmmouse()
{ {
VMWareBackdoor::initialize(); VMWareBackdoor::initialize();
if (!KParams::the().has("vmmouse")) { if (!kernel_command_line().contains("vmmouse")) {
VMWareBackdoor::the().enable_absolute_vmmouse(); VMWareBackdoor::the().enable_absolute_vmmouse();
return; return;
} }
auto vmmouse = KParams::the().get("vmmouse"); auto vmmouse = kernel_command_line().get("vmmouse");
if (vmmouse == "off") if (vmmouse == "off")
return; return;
if (vmmouse == "on") { if (vmmouse == "on") {
@ -421,12 +421,12 @@ void setup_vmmouse()
void setup_pci() void setup_pci()
{ {
if (!KParams::the().has("pci_mmio")) { if (!kernel_command_line().contains("pci_mmio")) {
PCI::Initializer::the().test_and_initialize(false); PCI::Initializer::the().test_and_initialize(false);
PCI::Initializer::the().dismiss(); PCI::Initializer::the().dismiss();
return; return;
} }
auto pci_mmio = KParams::the().get("pci_mmio"); auto pci_mmio = kernel_command_line().get("pci_mmio");
if (pci_mmio == "on") { if (pci_mmio == "on") {
PCI::Initializer::the().test_and_initialize(false); PCI::Initializer::the().test_and_initialize(false);
} else if (pci_mmio == "off") { } else if (pci_mmio == "off") {
@ -442,11 +442,11 @@ void setup_interrupts()
{ {
InterruptManagement::initialize(); InterruptManagement::initialize();
if (!KParams::the().has("smp")) { if (!kernel_command_line().contains("smp")) {
InterruptManagement::the().switch_to_pic_mode(); InterruptManagement::the().switch_to_pic_mode();
return; return;
} }
auto smp = KParams::the().get("smp"); auto smp = kernel_command_line().get("smp");
if (smp == "off") { if (smp == "off") {
InterruptManagement::the().switch_to_pic_mode(); InterruptManagement::the().switch_to_pic_mode();
return; return;
@ -462,11 +462,11 @@ void setup_interrupts()
void setup_time_management() void setup_time_management()
{ {
if (!KParams::the().has("time")) { if (!kernel_command_line().contains("time")) {
TimeManagement::initialize(true); TimeManagement::initialize(true);
return; return;
} }
auto time = KParams::the().get("time"); auto time = kernel_command_line().get("time");
if (time == "legacy") { if (time == "legacy") {
TimeManagement::initialize(false); TimeManagement::initialize(false);
return; return;