summaryrefslogblamecommitdiffstats
path: root/boot/cmdline.c
blob: aa6aa05a86a60553c89238e5bc5ea32b5710b180 (plain) (tree)

















































                                                                            
#include "cmdline.h"
#include "boot.h"
#include "mem/memory.h"
#include "lib/string.h"
#include "io/log.h"

static struct HashTable s_cmdline_kernel;

const char*
cmdline_get(const char *key)
{
    const char** value = hashtable_get(&s_cmdline_kernel, key, const char*);
    if(value == NULL) return NULL;
    return *value;
}

void
cmdline_kernel_setup(void)
{
    hashtable_news(&s_cmdline_kernel, const char*);
    size_t cmdi = 0;
    
    const char *cmdline = boot_kernel_cmdline;
    if(cmdline == 0) return;

    while(cmdline[cmdi] != 0)
    {
        size_t keyi = cmdi;
        while(cmdline[keyi] != '=' && cmdline[keyi] != 0) keyi++;
        if(cmdline[keyi] == 0 || keyi == 0) {
            klogf("kernel cmdline is empty or malformed; skipping.\n");
            break;
        }

        size_t keylen = keyi - cmdi;
        char *key = mem_alloc(keylen);
        memcpy(key, &cmdline[cmdi], keylen);

        size_t valuei = keyi + 1;
        while(cmdline[valuei] != ' ' && cmdline[valuei] != 0) valuei++;

        size_t valuelen = (valuei - keyi) - 1;
        char *value = mem_alloc(valuelen);
        if(valuelen != 0) memcpy(value, &cmdline[keyi + 1], valuelen);

        klogf("%s = %s\n", key, value);
        hashtable_insert(&s_cmdline_kernel, key, &value);
        cmdi = valuei + 1;
    }
}