From 300916479fd4f230c8e5bb4f9d81b09c3f02feb5 Mon Sep 17 00:00:00 2001 From: Jakub Jermar Date: Fri, 21 Jul 2017 22:00:53 +0200 Subject: [PATCH] Deduplicate multiboot cmdline parsing code --- kernel/genarch/Makefile.inc | 1 + .../genarch/include/genarch/multiboot/multiboot.h | 2 + .../multiboot.h => src/multiboot/common.c} | 71 ++++++++-------------- kernel/genarch/src/multiboot/multiboot.c | 21 ------- kernel/genarch/src/multiboot/multiboot2.c | 18 +----- 5 files changed, 29 insertions(+), 84 deletions(-) copy kernel/genarch/{include/genarch/multiboot/multiboot.h => src/multiboot/common.c} (54%) diff --git a/kernel/genarch/Makefile.inc b/kernel/genarch/Makefile.inc index f55f3fd07..ac01d35ad 100644 --- a/kernel/genarch/Makefile.inc +++ b/kernel/genarch/Makefile.inc @@ -168,6 +168,7 @@ endif ifeq ($(CONFIG_MULTIBOOT), y) GENARCH_SOURCES += \ + genarch/src/multiboot/common.c \ genarch/src/multiboot/multiboot.c \ genarch/src/multiboot/multiboot2.c GENARCH_AUTOGENS_AG += \ diff --git a/kernel/genarch/include/genarch/multiboot/multiboot.h b/kernel/genarch/include/genarch/multiboot/multiboot.h index 35a5f468f..2d70c6a9b 100644 --- a/kernel/genarch/include/genarch/multiboot/multiboot.h +++ b/kernel/genarch/include/genarch/multiboot/multiboot.h @@ -70,6 +70,8 @@ typedef struct { uint32_t reserved; } __attribute__((packed)) multiboot_module_t; +extern void multiboot_cmdline(const char *); + extern void multiboot_extract_command(char *, size_t, const char *); extern void multiboot_extract_argument(char *, size_t, const char *); extern void multiboot_info_parse(uint32_t, const multiboot_info_t *); diff --git a/kernel/genarch/include/genarch/multiboot/multiboot.h b/kernel/genarch/src/multiboot/common.c similarity index 54% copy from kernel/genarch/include/genarch/multiboot/multiboot.h copy to kernel/genarch/src/multiboot/common.c index 35a5f468f..6166a2c71 100644 --- a/kernel/genarch/include/genarch/multiboot/multiboot.h +++ b/kernel/genarch/src/multiboot/common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Jiri Svoboda + * Copyright (c) 2017 Jakub Jermar * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,51 +32,30 @@ /** @file */ -#ifndef KERN_MULTIBOOT_H_ -#define KERN_MULTIBOOT_H_ - -#include -#include - -#define MULTIBOOT_HEADER_MAGIC 0x1badb002 -#define MULTIBOOT_HEADER_FLAGS 0x00010003 - -#define MULTIBOOT_LOADER_MAGIC 0x2badb002 - -#define MULTIBOOT_INFO_FLAGS_MEM 0x01 -#define MULTIBOOT_INFO_FLAGS_BOOT 0x02 -#define MULTIBOOT_INFO_FLAGS_CMDLINE 0x04 -#define MULTIBOOT_INFO_FLAGS_MODS 0x08 -#define MULTIBOOT_INFO_FLAGS_SYMS1 0x10 -#define MULTIBOOT_INFO_FLAGS_SYMS2 0x20 -#define MULTIBOOT_INFO_FLAGS_MMAP 0x40 - -#ifndef __ASM__ - -#include -#include - -/** Convert 32-bit multiboot address to a pointer. */ -#define MULTIBOOT_PTR(mba) ((void *) (uintptr_t) (mba)) - -/** Multiboot 32-bit address. */ -typedef uint32_t mbaddr_t; - -/** Multiboot module structure */ -typedef struct { - mbaddr_t start; - mbaddr_t end; - mbaddr_t string; - uint32_t reserved; -} __attribute__((packed)) multiboot_module_t; - -extern void multiboot_extract_command(char *, size_t, const char *); -extern void multiboot_extract_argument(char *, size_t, const char *); -extern void multiboot_info_parse(uint32_t, const multiboot_info_t *); - -#endif /* __ASM__ */ - -#endif +#include +#include +#include + +void multiboot_cmdline(const char *cmdline) +{ + /* + * GRUB passes the command line in an escaped form. + */ + for (size_t i = 0, j = 0; + cmdline[i] && j < CONFIG_BOOT_ARGUMENTS_BUFLEN; + i++, j++) { + if (cmdline[i] == '\\') { + switch (cmdline[i + 1]) { + case '\\': + case '\'': + case '\"': + i++; + break; + } + } + bargs[j] = cmdline[i]; + } +} /** @} */ diff --git a/kernel/genarch/src/multiboot/multiboot.c b/kernel/genarch/src/multiboot/multiboot.c index ee4adf8f6..7a80d841c 100644 --- a/kernel/genarch/src/multiboot/multiboot.c +++ b/kernel/genarch/src/multiboot/multiboot.c @@ -100,27 +100,6 @@ void multiboot_extract_argument(char *buf, size_t size, const char *cmd_line) str_ncpy(buf, size, start, (size_t) (end - start)); } -static void multiboot_cmdline(char *cmdline) -{ - /* - * GRUB passes the command line in an escaped form. - */ - for (size_t i = 0, j = 0; - cmdline[i] && j < CONFIG_BOOT_ARGUMENTS_BUFLEN; - i++, j++) { - if (cmdline[i] == '\\') { - switch (cmdline[i + 1]) { - case '\\': - case '\'': - case '\"': - i++; - break; - } - } - bargs[j] = cmdline[i]; - } -} - static void multiboot_modules(uint32_t count, multiboot_module_t *mods) { for (uint32_t i = 0; i < count; i++) { diff --git a/kernel/genarch/src/multiboot/multiboot2.c b/kernel/genarch/src/multiboot/multiboot2.c index f7ce6003b..13c389bea 100644 --- a/kernel/genarch/src/multiboot/multiboot2.c +++ b/kernel/genarch/src/multiboot/multiboot2.c @@ -43,23 +43,7 @@ static void multiboot2_cmdline(const multiboot2_cmdline_t *module) { - /* - * GRUB passes the command line in an escaped form. - */ - for (size_t i = 0, j = 0; - module->string[i] && j < CONFIG_BOOT_ARGUMENTS_BUFLEN; - i++, j++) { - if (module->string[i] == '\\') { - switch (module->string[i + 1]) { - case '\\': - case '\'': - case '\"': - i++; - break; - } - } - bargs[j] = module->string[i]; - } + multiboot_cmdline(module->string); } static void multiboot2_module(const multiboot2_module_t *module) -- 2.11.4.GIT