mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 17:07:35 +00:00
Kernel: Add KParams class for accessing kernel cmdline parameters (#188)
This commit is contained in:
parent
042895317d
commit
738f9de9a9
5 changed files with 59 additions and 3 deletions
34
Kernel/KParams.cpp
Normal file
34
Kernel/KParams.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <Kernel/KParams.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
19
Kernel/KParams.h
Normal file
19
Kernel/KParams.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/AKString.h>
|
||||||
|
#include <AK/HashMap.h>
|
||||||
|
|
||||||
|
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<String, String> m_params;
|
||||||
|
};
|
|
@ -32,6 +32,7 @@ KERNEL_OBJS = \
|
||||||
Scheduler.o \
|
Scheduler.o \
|
||||||
DoubleBuffer.o \
|
DoubleBuffer.o \
|
||||||
KSyms.o \
|
KSyms.o \
|
||||||
|
KParams.o \
|
||||||
SharedMemory.o \
|
SharedMemory.o \
|
||||||
FileSystem/DevPtsFS.o \
|
FileSystem/DevPtsFS.o \
|
||||||
Devices/BXVGADevice.o \
|
Devices/BXVGADevice.o \
|
||||||
|
|
|
@ -2,5 +2,5 @@ timeout=0
|
||||||
|
|
||||||
menuentry 'Serenity' {
|
menuentry 'Serenity' {
|
||||||
root=hd0,1
|
root=hd0,1
|
||||||
multiboot /boot/kernel Hello from grub!
|
multiboot /boot/kernel root=hd0,1
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <Kernel/Net/NetworkTask.h>
|
#include <Kernel/Net/NetworkTask.h>
|
||||||
#include <Kernel/Devices/DebugLogDevice.h>
|
#include <Kernel/Devices/DebugLogDevice.h>
|
||||||
#include <Kernel/Multiboot.h>
|
#include <Kernel/Multiboot.h>
|
||||||
|
#include <Kernel/KParams.h>
|
||||||
|
|
||||||
//#define STRESS_TEST_SPAWNING
|
//#define STRESS_TEST_SPAWNING
|
||||||
|
|
||||||
|
@ -123,13 +124,14 @@ multiboot_info_t* multiboot_info_ptr;
|
||||||
|
|
||||||
extern "C" [[noreturn]] void init()
|
extern "C" [[noreturn]] void init()
|
||||||
{
|
{
|
||||||
kprintf("Kernel command line: '%s'\n", multiboot_info_ptr->cmdline);
|
|
||||||
|
|
||||||
sse_init();
|
sse_init();
|
||||||
|
|
||||||
kmalloc_init();
|
kmalloc_init();
|
||||||
init_ksyms();
|
init_ksyms();
|
||||||
|
|
||||||
|
// must come after kmalloc_init because we use AK_MAKE_ETERNAL in KParams
|
||||||
|
new KParams(String(reinterpret_cast<const char*>(multiboot_info_ptr->cmdline)));
|
||||||
|
|
||||||
vfs = new VFS;
|
vfs = new VFS;
|
||||||
dev_debuglog = new DebugLogDevice;
|
dev_debuglog = new DebugLogDevice;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue