From 0cf726b8eff9823ed8fcc61a4a791d231610421a Mon Sep 17 00:00:00 2001 From: Jakub Michalski Date: Thu, 11 Jul 2024 15:11:34 +0200 Subject: [PATCH] arch/x86: multiboot: add bootargs support Add bootargs support for multiboot. This implements get_bootargs() when multiboot and bootargs are selected in config. Signed-off-by: Jakub Michalski Signed-off-by: Filip Kokosinski --- arch/x86/core/common.S | 26 +++++++++++++++ arch/x86/core/multiboot.c | 9 ++++++ arch/x86/core/offsets/offsets.c | 9 ++++++ include/zephyr/arch/x86/multiboot.h | 34 +++----------------- include/zephyr/arch/x86/multiboot_info.h | 40 ++++++++++++++++++++++++ kernel/Kconfig | 2 +- 6 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 include/zephyr/arch/x86/multiboot_info.h diff --git a/arch/x86/core/common.S b/arch/x86/core/common.S index 1f390df42fb..07c0de8c8dc 100644 --- a/arch/x86/core/common.S +++ b/arch/x86/core/common.S @@ -22,9 +22,35 @@ */ cmpl $MULTIBOOT_EAX_MAGIC, %eax + +#ifndef CONFIG_DYNAMIC_BOOTARGS je 1f xorl %ebx, %ebx 1: +#else + movl $multiboot_cmdline, %edi + je setup_copy_cmdline + xorl %ebx, %ebx + jmp end_cmdline + +setup_copy_cmdline: + testl $MULTIBOOT_INFO_FLAGS_CMDLINE, __multiboot_info_t_flags_OFFSET(%ebx) + jz end_cmdline + + movl $multiboot_cmdline + CONFIG_BOOTARGS_ARGS_BUFFER_SIZE - 1, %edx + movl __multiboot_info_t_cmdline_OFFSET(%ebx), %esi +copy_cmdline: + cmpl %esi, %edx + je end_cmdline + cmpb $0, (%esi) + je end_cmdline + + movsb + jmp copy_cmdline +end_cmdline: + movb $0, (%edi) +#endif + #endif #ifdef CONFIG_PIC_DISABLE diff --git a/arch/x86/core/multiboot.c b/arch/x86/core/multiboot.c index 06d03c7b807..b6112b75f82 100644 --- a/arch/x86/core/multiboot.c +++ b/arch/x86/core/multiboot.c @@ -11,6 +11,15 @@ struct multiboot_info multiboot_info; +#ifdef CONFIG_DYNAMIC_BOOTARGS +__pinned_noinit char multiboot_cmdline[CONFIG_BOOTARGS_ARGS_BUFFER_SIZE]; + +const char *get_bootargs(void) +{ + return multiboot_cmdline; +} +#endif /* CONFIG_DYNAMIC_BOOTARGS */ + /* * called very early in the boot process to fetch data out of the multiboot * info struct. we need to grab the relevant data before any dynamic memory diff --git a/arch/x86/core/offsets/offsets.c b/arch/x86/core/offsets/offsets.c index 53b432e74cb..2e6b323fa7c 100644 --- a/arch/x86/core/offsets/offsets.c +++ b/arch/x86/core/offsets/offsets.c @@ -14,9 +14,18 @@ #include "ia32_offsets.c" #endif +#ifdef CONFIG_MULTIBOOT_INFO +#include +#endif + GEN_OFFSET_SYM(x86_boot_arg_t, boot_type); GEN_OFFSET_SYM(x86_boot_arg_t, arg); GEN_OFFSET_SYM(_thread_arch_t, flags); +#ifdef CONFIG_MULTIBOOT_INFO +GEN_OFFSET_SYM(multiboot_info_t, flags); +GEN_OFFSET_SYM(multiboot_info_t, cmdline); +#endif + GEN_ABS_SYM_END diff --git a/include/zephyr/arch/x86/multiboot.h b/include/zephyr/arch/x86/multiboot.h index 66c312e48e2..379f03dd3a5 100644 --- a/include/zephyr/arch/x86/multiboot.h +++ b/include/zephyr/arch/x86/multiboot.h @@ -9,32 +9,7 @@ #ifndef _ASMLANGUAGE -#include - -/* - * Multiboot (version 1) boot information structure. - * - * Only fields/values of interest to Zephyr are enumerated: at - * present, that means only those pertaining to the framebuffer. - */ - -struct multiboot_info { - uint32_t flags; - uint32_t mem_lower; - uint32_t mem_upper; - uint32_t unused0[8]; - uint32_t mmap_length; - uint32_t mmap_addr; - uint32_t unused1[9]; - uint32_t fb_addr_lo; - uint32_t fb_addr_hi; - uint32_t fb_pitch; - uint32_t fb_width; - uint32_t fb_height; - uint8_t fb_bpp; - uint8_t fb_type; - uint8_t fb_color_info[6]; -}; +#include "multiboot_info.h" extern struct multiboot_info multiboot_info; @@ -105,9 +80,10 @@ struct multiboot_mmap { /* The flags in the boot info structure tell us which fields are valid. */ -#define MULTIBOOT_INFO_FLAGS_MEM (1 << 0) /* mem_* valid */ -#define MULTIBOOT_INFO_FLAGS_MMAP (1 << 6) /* mmap_* valid */ -#define MULTIBOOT_INFO_FLAGS_FB (1 << 12) /* fb_* valid */ +#define MULTIBOOT_INFO_FLAGS_MEM BIT(0) /* mem_* valid */ +#define MULTIBOOT_INFO_FLAGS_CMDLINE BIT(2) /* cmdline* valid */ +#define MULTIBOOT_INFO_FLAGS_MMAP BIT(6) /* mmap_* valid */ +#define MULTIBOOT_INFO_FLAGS_FB BIT(12) /* fb_* valid */ /* The only fb_type we support is RGB. No text modes and no color palettes. */ diff --git a/include/zephyr/arch/x86/multiboot_info.h b/include/zephyr/arch/x86/multiboot_info.h new file mode 100644 index 00000000000..5ff7ca2ceea --- /dev/null +++ b/include/zephyr/arch/x86/multiboot_info.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_X86_MULTIBOOT_INFO_H_ +#define ZEPHYR_INCLUDE_ARCH_X86_MULTIBOOT_INFO_H_ + +#include + +/* + * Multiboot (version 1) boot information structure. + * + * Only fields/values of interest to Zephyr are enumerated + */ + +struct multiboot_info { + uint32_t flags; + uint32_t mem_lower; + uint32_t mem_upper; + uint32_t unused0; + uint32_t cmdline; + uint32_t unused1[6]; + uint32_t mmap_length; + uint32_t mmap_addr; + uint32_t unused2[9]; + uint32_t fb_addr_lo; + uint32_t fb_addr_hi; + uint32_t fb_pitch; + uint32_t fb_width; + uint32_t fb_height; + uint8_t fb_bpp; + uint8_t fb_type; + uint8_t fb_color_info[6]; +}; + +typedef struct multiboot_info multiboot_info_t; + +#endif diff --git a/kernel/Kconfig b/kernel/Kconfig index d0ce98b4e73..4370443fd4f 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -1005,7 +1005,7 @@ config BOOTARGS config DYNAMIC_BOOTARGS bool "Support dynamic bootargs" - depends on BOOTARGS + depends on BOOTARGS && MULTIBOOT_INFO help Enables dynamic bootargs support.