From 738f9de9a9e30032183f59416af5695b15ed39fc Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Tue, 4 Jun 2019 20:54:27 +1000 Subject: [PATCH] Kernel: Add KParams class for accessing kernel cmdline parameters (#188) --- Kernel/KParams.cpp | 34 ++++++++++++++++++++++++++++++++++ Kernel/KParams.h | 19 +++++++++++++++++++ Kernel/Makefile | 1 + Kernel/grub.cfg | 2 +- Kernel/init.cpp | 6 ++++-- 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Kernel/KParams.cpp create mode 100644 Kernel/KParams.h diff --git a/Kernel/KParams.cpp b/Kernel/KParams.cpp new file mode 100644 index 00000000000..37e3ee72751 --- /dev/null +++ b/Kernel/KParams.cpp @@ -0,0 +1,34 @@ +#include + +static KParams* s_the; + +KParams& KParams::the() +{ + return *s_the; +} + +KParams::KParams(const String& cmdline) + : m_cmdline(cmdline) +{ + s_the = this; + + for (auto str : m_cmdline.split(' ')) { + auto pair = str.split_limit('=', 2); + + if (pair.size() == 1) { + m_params.set(pair[0], ""); + } else { + m_params.set(pair[0], pair[1]); + } + } +} + +String KParams::get(const String& key) const +{ + return m_params.get(key); +} + +bool KParams::has(const String& key) const +{ + return m_params.contains(key); +} diff --git a/Kernel/KParams.h b/Kernel/KParams.h new file mode 100644 index 00000000000..51da17006a7 --- /dev/null +++ b/Kernel/KParams.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +class KParams { + AK_MAKE_ETERNAL +public: + static KParams& the(); + + KParams(const String& cmdline); + + const String& cmdline() const { return m_cmdline; } + String get(const String& key) const; + bool has(const String& key) const; +private: + String m_cmdline; + HashMap m_params; +}; diff --git a/Kernel/Makefile b/Kernel/Makefile index ac124001d73..3479d8eed2e 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -32,6 +32,7 @@ KERNEL_OBJS = \ Scheduler.o \ DoubleBuffer.o \ KSyms.o \ + KParams.o \ SharedMemory.o \ FileSystem/DevPtsFS.o \ Devices/BXVGADevice.o \ diff --git a/Kernel/grub.cfg b/Kernel/grub.cfg index be638e928e8..31a55e9aff1 100644 --- a/Kernel/grub.cfg +++ b/Kernel/grub.cfg @@ -2,5 +2,5 @@ timeout=0 menuentry 'Serenity' { root=hd0,1 - multiboot /boot/kernel Hello from grub! + multiboot /boot/kernel root=hd0,1 } diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 098e81c9d1a..7939bd86700 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -28,6 +28,7 @@ #include #include #include +#include //#define STRESS_TEST_SPAWNING @@ -123,13 +124,14 @@ multiboot_info_t* multiboot_info_ptr; extern "C" [[noreturn]] void init() { - kprintf("Kernel command line: '%s'\n", multiboot_info_ptr->cmdline); - sse_init(); kmalloc_init(); init_ksyms(); + // must come after kmalloc_init because we use AK_MAKE_ETERNAL in KParams + new KParams(String(reinterpret_cast(multiboot_info_ptr->cmdline))); + vfs = new VFS; dev_debuglog = new DebugLogDevice;