diff --git a/arch/Kconfig b/arch/Kconfig index ca407e7c7237c..e440ef566b45d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -230,6 +230,16 @@ config SRAM_BASE_ADDRESS /chosen/zephyr,sram in devicetree. The user should generally avoid changing it via menuconfig or in configuration files. +config XIP + bool "Execute in place" + help + This option allows zephyr to operate with its text and read-only + sections residing in ROM (or similar read-only memory). Not all boards + support this option so it must be used with care; you must also + supply a linker command file when building your image. Enabling this + option increases both the code and data footprint of the image. + + if ARC || ARM || ARM64 || X86 || RISCV || RX # Workaround for not being able to have commas in macro arguments diff --git a/arch/arc/core/prep_c.c b/arch/arc/core/prep_c.c index 113ac5029736c..6e8e51e050010 100644 --- a/arch/arc/core/prep_c.c +++ b/arch/arc/core/prep_c.c @@ -22,7 +22,8 @@ #include #include #include -#include +#include +#include #include #include @@ -67,7 +68,7 @@ extern char __device_states_end[]; */ static void dev_state_zero(void) { - z_early_memset(__device_states_start, 0, __device_states_end - __device_states_start); + arch_early_memset(__device_states_start, 0, __device_states_end - __device_states_start); } #endif @@ -81,7 +82,7 @@ extern void arc_secureshield_init(void); * This routine prepares for the execution of and runs C code. */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); @@ -91,11 +92,11 @@ void z_prep_c(void) arc_cluster_scm_enable(); #endif - z_bss_zero(); + arch_bss_zero(); #ifdef __CCAC__ dev_state_zero(); #endif - z_data_copy(); + arch_data_copy(); #if CONFIG_ARCH_CACHE arch_cache_init(); #endif diff --git a/arch/arm/core/cortex_a_r/prep_c.c b/arch/arm/core/cortex_a_r/prep_c.c index a10588a49275f..d2cd695fb134c 100644 --- a/arch/arm/core/cortex_a_r/prep_c.c +++ b/arch/arm/core/cortex_a_r/prep_c.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #if defined(CONFIG_ARMV7_R) || defined(CONFIG_ARMV7_A) #include @@ -96,7 +98,7 @@ extern FUNC_NORETURN void z_cstart(void); * This routine prepares for the execution of and runs C code. * */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); @@ -107,8 +109,8 @@ void z_prep_c(void) #if defined(CONFIG_CPU_HAS_FPU) z_arm_floating_point_init(); #endif - z_bss_zero(); - z_data_copy(); + arch_bss_zero(); + arch_data_copy(); #if ((defined(CONFIG_ARMV7_R) || defined(CONFIG_ARMV7_A)) && defined(CONFIG_INIT_STACKS)) z_arm_init_stacks(); #endif diff --git a/arch/arm/core/cortex_m/prep_c.c b/arch/arm/core/cortex_m/prep_c.c index bc317f8ddec07..2ead97a1e6dff 100644 --- a/arch/arm/core/cortex_m/prep_c.c +++ b/arch/arm/core/cortex_m/prep_c.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include /* * GCC can detect if memcpy is passed a NULL argument, however one of @@ -59,7 +61,7 @@ void __weak relocate_vector_table(void) /* Copy vector table to its location in SRAM */ size_t vector_size = (size_t)_vector_end - (size_t)_vector_start; - z_early_memcpy(_sram_vector_start, _vector_start, vector_size); + arch_early_memcpy(_sram_vector_start, _vector_start, vector_size); #endif SCB->VTOR = VECTOR_ADDRESS & VTOR_MASK; barrier_dsync_fence_full(); @@ -193,7 +195,7 @@ extern FUNC_NORETURN void z_cstart(void); * This routine prepares for the execution of and runs C code. * */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); @@ -203,8 +205,8 @@ void z_prep_c(void) #if defined(CONFIG_CPU_HAS_FPU) z_arm_floating_point_init(); #endif - z_bss_zero(); - z_data_copy(); + arch_bss_zero(); + arch_data_copy(); #if defined(CONFIG_ARM_CUSTOM_INTERRUPT_CONTROLLER) /* Invoke SoC-specific interrupt controller initialization */ z_soc_irq_init(); diff --git a/arch/arm/core/cortex_m/reset.S b/arch/arm/core/cortex_m/reset.S index c3f9362eca85d..784626d8013b3 100644 --- a/arch/arm/core/cortex_m/reset.S +++ b/arch/arm/core/cortex_m/reset.S @@ -19,7 +19,7 @@ _ASM_FILE_PROLOGUE GTEXT(z_arm_reset) -GTEXT(z_early_memset) +GTEXT(arch_early_memset) GDATA(z_interrupt_stacks) GDATA(z_main_stack) #if defined(CONFIG_DEBUG_THREAD_INFO) @@ -177,7 +177,7 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start) ldr r0, =z_interrupt_stacks ldr r1, =0xaa ldr r2, =CONFIG_ISR_STACK_SIZE + MPU_GUARD_ALIGN_AND_SIZE - bl z_early_memset + bl arch_early_memset #endif /* diff --git a/arch/arm64/core/early_mem_funcs.S b/arch/arm64/core/early_mem_funcs.S index 383cdec790195..51c7a450633a8 100644 --- a/arch/arm64/core/early_mem_funcs.S +++ b/arch/arm64/core/early_mem_funcs.S @@ -18,9 +18,9 @@ _ASM_FILE_PROLOGUE * to memset or memcpy on its own. */ -/* void z_early_memset(void *dst, int c, size_t n) */ -GTEXT(z_early_memset) -SECTION_FUNC(TEXT, z_early_memset) +/* void arch_early_memset(void *dst, int c, size_t n) */ +GTEXT(arch_early_memset) +SECTION_FUNC(TEXT, arch_early_memset) /* is dst pointer 8-bytes aligned? */ tst x0, #0x7 @@ -51,9 +51,9 @@ SECTION_FUNC(TEXT, z_early_memset) 4: ret -/* void z_early_memcpy(void *dst, const void *src, size_t n) */ -GTEXT(z_early_memcpy) -SECTION_FUNC(TEXT, z_early_memcpy) +/* void arch_early_memcpy(void *dst, const void *src, size_t n) */ +GTEXT(arch_early_memcpy) +SECTION_FUNC(TEXT, arch_early_memcpy) /* are dst and src pointers 8-bytes aligned? */ orr x8, x1, x0 diff --git a/arch/arm64/core/prep_c.c b/arch/arm64/core/prep_c.c index 11c7d2b112bab..19787e844e616 100644 --- a/arch/arm64/core/prep_c.c +++ b/arch/arm64/core/prep_c.c @@ -14,10 +14,11 @@ * initialization is performed. */ -#include #include #include #include +#include +#include extern void z_arm64_mm_init(bool is_primary_core); @@ -30,7 +31,7 @@ __weak void z_arm64_mm_init(bool is_primary_core) { } * This routine prepares for the execution of and runs C code. * */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); @@ -39,8 +40,8 @@ void z_prep_c(void) /* Initialize tpidrro_el0 with our struct _cpu instance address */ write_tpidrro_el0((uintptr_t)&_kernel.cpus[0]); - z_bss_zero(); - z_data_copy(); + arch_bss_zero(); + arch_data_copy(); #ifdef CONFIG_ARM64_SAFE_EXCEPTION_STACK /* After bss clean, _kernel.cpus is in bss section */ z_arm64_safe_exception_stack_init(); diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index 6f1042b0050ff..d817afa3d7fe0 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -17,6 +17,9 @@ if(CONFIG_GEN_ISR_TABLES) ) endif() +zephyr_library_sources(init.c) +zephyr_library_sources_ifdef(CONFIG_XIP xip.c) + zephyr_library_sources_ifdef( CONFIG_ISR_TABLE_SHELL isr_tables_shell.c diff --git a/arch/common/init.c b/arch/common/init.c new file mode 100644 index 0000000000000..b5e83a0b8dc19 --- /dev/null +++ b/arch/common/init.c @@ -0,0 +1,128 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright The Zephyr Project Contributors + */ + +#include +#include +#include +#include +#include + +/* LCOV_EXCL_START + * + * This code is called so early in the boot process that code coverage + * doesn't work properly. In addition, not all arches call this code, + * some like x86 do this with optimized assembly + */ + +/** + * @brief equivalent of memset() for early boot usage + * + * Architectures that can't safely use the regular (optimized) memset very + * early during boot because e.g. hardware isn't yet sufficiently initialized + * may override this with their own safe implementation. + */ +__boot_func +void __weak arch_early_memset(void *dst, int c, size_t n) +{ + (void) memset(dst, c, n); +} + +/** + * @brief equivalent of memcpy() for early boot usage + * + * Architectures that can't safely use the regular (optimized) memcpy very + * early during boot because e.g. hardware isn't yet sufficiently initialized + * may override this with their own safe implementation. + */ +__boot_func +void __weak arch_early_memcpy(void *dst, const void *src, size_t n) +{ + (void) memcpy(dst, src, n); +} + +/** + * @brief Clear BSS + * + * This routine clears the BSS region, so all bytes are 0. + */ +__boot_func +void arch_bss_zero(void) +{ + if (IS_ENABLED(CONFIG_SKIP_BSS_CLEAR)) { + return; + } + + arch_early_memset(__bss_start, 0, __bss_end - __bss_start); +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)) + arch_early_memset(&__ccm_bss_start, 0, + (uintptr_t) &__ccm_bss_end + - (uintptr_t) &__ccm_bss_start); +#endif +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) + arch_early_memset(&__dtcm_bss_start, 0, + (uintptr_t) &__dtcm_bss_end + - (uintptr_t) &__dtcm_bss_start); +#endif +#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)) + arch_early_memset(&__ocm_bss_start, 0, + (uintptr_t) &__ocm_bss_end + - (uintptr_t) &__ocm_bss_start); +#endif +#ifdef CONFIG_CODE_DATA_RELOCATION + extern void bss_zeroing_relocation(void); + + bss_zeroing_relocation(); +#endif /* CONFIG_CODE_DATA_RELOCATION */ +#ifdef CONFIG_COVERAGE_GCOV + arch_early_memset(&__gcov_bss_start, 0, + ((uintptr_t) &__gcov_bss_end - (uintptr_t) &__gcov_bss_start)); +#endif /* CONFIG_COVERAGE_GCOV */ +#ifdef CONFIG_NOCACHE_MEMORY + arch_early_memset(&_nocache_ram_start, 0, + (uintptr_t) &_nocache_ram_end - (uintptr_t) &_nocache_ram_start); +#endif +} + +#ifdef CONFIG_LINKER_USE_BOOT_SECTION +/** + * @brief Clear BSS within the boot region + * + * This routine clears the BSS within the boot region. + * This is separate from arch_bss_zero() as boot region may + * contain symbols required for the boot process before + * paging is initialized. + */ +__boot_func +void arch_bss_zero_boot(void) +{ + arch_early_memset(&lnkr_boot_bss_start, 0, + (uintptr_t)&lnkr_boot_bss_end + - (uintptr_t)&lnkr_boot_bss_start); +} +#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ + +#ifdef CONFIG_LINKER_USE_PINNED_SECTION +/** + * @brief Clear BSS within the pinned region + * + * This routine clears the BSS within the pinned region. + * This is separate from arch_bss_zero() as pinned region may + * contain symbols required for the boot process before + * paging is initialized. + */ +#ifdef CONFIG_LINKER_USE_BOOT_SECTION +__boot_func +#else +__pinned_func +#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ +void arch_bss_zero_pinned(void) +{ + arch_early_memset(&lnkr_pinned_bss_start, 0, + (uintptr_t)&lnkr_pinned_bss_end + - (uintptr_t)&lnkr_pinned_bss_start); +} +#endif /* CONFIG_LINKER_USE_PINNED_SECTION */ + +/* LCOV_EXCL_STOP */ diff --git a/kernel/xip.c b/arch/common/xip.c similarity index 81% rename from kernel/xip.c rename to arch/common/xip.c index 1f41d93ee280c..234d323118b54 100644 --- a/kernel/xip.c +++ b/arch/common/xip.c @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef CONFIG_REQUIRES_STACK_CANARIES #ifdef CONFIG_STACK_CANARIES_TLS @@ -23,30 +24,30 @@ extern volatile uintptr_t __stack_chk_guard; * * This routine copies the data section from ROM to RAM. */ -void z_data_copy(void) +void arch_data_copy(void) { - z_early_memcpy(&__data_region_start, &__data_region_load_start, + arch_early_memcpy(&__data_region_start, &__data_region_load_start, __data_region_end - __data_region_start); #ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT - z_early_memcpy(&__ramfunc_region_start, &__ramfunc_load_start, + arch_early_memcpy(&__ramfunc_region_start, &__ramfunc_load_start, __ramfunc_end - __ramfunc_region_start); #endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */ #ifdef CONFIG_ARCH_HAS_NOCACHE_MEMORY_SUPPORT #if CONFIG_NOCACHE_MEMORY - z_early_memcpy(&_nocache_load_ram_start, &_nocache_load_rom_start, + arch_early_memcpy(&_nocache_load_ram_start, &_nocache_load_rom_start, (uintptr_t) &_nocache_load_ram_size); #endif /* CONFIG_NOCACHE_MEMORY */ #endif /* CONFIG_ARCH_HAS_NOCACHE_MEMORY_SUPPORT */ #if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)) - z_early_memcpy(&__ccm_data_start, &__ccm_data_load_start, + arch_early_memcpy(&__ccm_data_start, &__ccm_data_load_start, __ccm_data_end - __ccm_data_start); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_itcm)) - z_early_memcpy(&__itcm_start, &__itcm_load_start, + arch_early_memcpy(&__itcm_start, &__itcm_load_start, (uintptr_t) &__itcm_size); #endif #if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) - z_early_memcpy(&__dtcm_data_start, &__dtcm_data_load_start, + arch_early_memcpy(&__dtcm_data_start, &__dtcm_data_load_start, __dtcm_data_end - __dtcm_data_start); #endif #ifdef CONFIG_CODE_DATA_RELOCATION @@ -74,7 +75,7 @@ void z_data_copy(void) } __stack_chk_guard = guard_copy; #else - z_early_memcpy(&_app_smem_start, &_app_smem_rom_start, + arch_early_memcpy(&_app_smem_start, &_app_smem_rom_start, _app_smem_end - _app_smem_start); #endif /* CONFIG_REQUIRES_STACK_CANARIES */ #endif /* CONFIG_USERSPACE */ diff --git a/arch/mips/core/prep_c.c b/arch/mips/core/prep_c.c index 0247f90df6249..823ea58b6dee7 100644 --- a/arch/mips/core/prep_c.c +++ b/arch/mips/core/prep_c.c @@ -9,10 +9,11 @@ * @brief Full C support initialization */ -#include #include #include #include +#include +#include static void interrupt_init(void) { @@ -44,12 +45,12 @@ static void interrupt_init(void) * @return N/A */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); #endif - z_bss_zero(); + arch_bss_zero(); interrupt_init(); #if CONFIG_ARCH_CACHE diff --git a/arch/riscv/core/prep_c.c b/arch/riscv/core/prep_c.c index e74a570cb6661..49cbd1dfb866b 100644 --- a/arch/riscv/core/prep_c.c +++ b/arch/riscv/core/prep_c.c @@ -18,9 +18,10 @@ #include #include #include -#include #include #include +#include +#include #if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT) void soc_interrupt_init(void); @@ -33,14 +34,14 @@ void soc_interrupt_init(void); * This routine prepares for the execution of and runs C code. */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); #endif - z_bss_zero(); - z_data_copy(); + arch_bss_zero(); + arch_data_copy(); #if defined(CONFIG_RISCV_SOC_INTERRUPT_INIT) soc_interrupt_init(); #endif diff --git a/arch/rx/core/prep_c.c b/arch/rx/core/prep_c.c index 09d86d10d3634..ab96af5855521 100644 --- a/arch/rx/core/prep_c.c +++ b/arch/rx/core/prep_c.c @@ -15,11 +15,12 @@ * initialization is performed. */ -#include #include #include #include #include +#include +#include K_KERNEL_PINNED_STACK_ARRAY_DEFINE(z_initialization_process_stacks, CONFIG_MP_MAX_NUM_CPUS, CONFIG_INITIALIZATION_STACK_SIZE); @@ -30,11 +31,11 @@ K_KERNEL_PINNED_STACK_ARRAY_DEFINE(z_initialization_process_stacks, CONFIG_MP_MA * * @return N/A */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { - z_bss_zero(); + arch_bss_zero(); - z_data_copy(); + arch_data_copy(); z_cstart(); CODE_UNREACHABLE; diff --git a/arch/sparc/core/prep_c.c b/arch/sparc/core/prep_c.c index 5b4a440a63cd3..129ca4a6c2748 100644 --- a/arch/sparc/core/prep_c.c +++ b/arch/sparc/core/prep_c.c @@ -8,10 +8,11 @@ * @file * @brief Full C support initialization */ - -#include +#include #include #include +#include +#include /** * @brief Prepare to and run C code @@ -19,12 +20,12 @@ * This routine prepares for the execution of and runs C code. */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); #endif - z_data_copy(); + arch_data_copy(); #if CONFIG_ARCH_CACHE arch_cache_init(); #endif diff --git a/arch/sparc/core/reset_trap.S b/arch/sparc/core/reset_trap.S index 6f1f6c037e3c1..dcea15a2a3b1f 100644 --- a/arch/sparc/core/reset_trap.S +++ b/arch/sparc/core/reset_trap.S @@ -57,7 +57,7 @@ SECTION_FUNC(TEXT, __sparc_trap_reset) nop #endif - call z_bss_zero + call arch_bss_zero nop call z_prep_c diff --git a/arch/x86/core/ia32/crt0.S b/arch/x86/core/ia32/crt0.S index 59c4a587a714c..3806a6f7fb890 100644 --- a/arch/x86/core/ia32/crt0.S +++ b/arch/x86/core/ia32/crt0.S @@ -22,6 +22,7 @@ #include #include #include +#include /* exports (private APIs) */ @@ -29,8 +30,8 @@ /* externs */ GTEXT(z_prep_c) - GTEXT(z_bss_zero) - GTEXT(z_data_copy) + GTEXT(arch_bss_zero) + GTEXT(arch_data_copy) GDATA(_idt_base_address) GDATA(z_interrupt_stacks) @@ -225,11 +226,11 @@ __csSet: * This is a must is CONFIG_GDT_DYNAMIC is enabled, * as _gdt needs to be in RAM. */ - call z_data_copy + call arch_data_copy #endif /* Note that installing page tables must be done after - * z_data_copy() as the page tables are being copied into + * arch_data_copy() as the page tables are being copied into * RAM there. */ install_page_tables @@ -264,10 +265,10 @@ __csSet: #endif /* Clear BSS */ #ifdef CONFIG_LINKER_USE_BOOT_SECTION - call z_bss_zero_boot + call arch_bss_zero_boot #endif #ifdef CONFIG_LINKER_USE_PINNED_SECTION - call z_bss_zero_pinned + call arch_bss_zero_pinned #endif #ifdef CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT /* Don't clear BSS if the section is not present @@ -275,7 +276,7 @@ __csSet: * faults. Zeroing BSS will be done later once the * paging mechanism has been initialized. */ - call z_bss_zero + call arch_bss_zero #endif #ifdef CONFIG_X86_CET diff --git a/arch/x86/core/intel64/cpu.c b/arch/x86/core/intel64/cpu.c index 69bbb91466fbb..325e4d8f294e8 100644 --- a/arch/x86/core/intel64/cpu.c +++ b/arch/x86/core/intel64/cpu.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #ifdef CONFIG_ACPI #include #include @@ -116,8 +118,8 @@ FUNC_NORETURN void z_x86_cpu_init(struct x86_cpuboot *cpuboot) if (cpuboot->cpu_id == 0U) { /* Only need to do these once per boot */ - z_bss_zero(); - z_data_copy(); + arch_bss_zero(); + arch_data_copy(); } z_loapic_enable(cpuboot->cpu_id); diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index 2b371d8bfb134..0239c602fb0fe 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -5,14 +5,19 @@ */ #include -#include +#include +#include #include #include #include #include -#include +#include +#include + +K_KERNEL_PINNED_STACK_ARRAY_DECLARE(z_interrupt_stacks, + CONFIG_MP_MAX_NUM_CPUS, + CONFIG_ISR_STACK_SIZE); -extern FUNC_NORETURN void z_cstart(void); extern void x86_64_irq_init(void); #if !defined(CONFIG_X86_64) diff --git a/arch/xtensa/core/prep_c.c b/arch/xtensa/core/prep_c.c index 771ad7e423077..8a399196d1bb0 100644 --- a/arch/xtensa/core/prep_c.c +++ b/arch/xtensa/core/prep_c.c @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ #include -#include +#include +#include #include -#include +#include +#include extern FUNC_NORETURN void z_cstart(void); @@ -27,7 +29,7 @@ BUILD_ASSERT(CONFIG_DCACHE_LINE_SIZE == XCHAL_DCACHE_LINESIZE); * This routine prepares for the execution of and runs C code. * */ -void z_prep_c(void) +FUNC_NORETURN void z_prep_c(void) { #if defined(CONFIG_SOC_PREP_HOOK) soc_prep_hook(); diff --git a/cmake/linker/iar/linker_flags.cmake b/cmake/linker/iar/linker_flags.cmake index 4d4fc42a44943..12d44ca24cd20 100644 --- a/cmake/linker/iar/linker_flags.cmake +++ b/cmake/linker/iar/linker_flags.cmake @@ -27,7 +27,7 @@ set_property(TARGET linker PROPERTY optimization_size_aggressive --entry_list_in string(APPEND CMAKE_C_LINK_FLAGS --no-wrap-diagnostics) if(CONFIG_IAR_DATA_INIT) - string(APPEND CMAKE_C_LINK_FLAGS " --redirect z_data_copy=__iar_data_init3") + string(APPEND CMAKE_C_LINK_FLAGS " --redirect arch_data_copy=__iar_data_init3") endif() foreach(lang C CXX ASM) set(commands "--log modules,libraries,initialization,redirects,sections") diff --git a/cmake/linker_script/arm/linker.cmake b/cmake/linker_script/arm/linker.cmake index 43ace74142e5e..196648fc8c985 100644 --- a/cmake/linker_script/arm/linker.cmake +++ b/cmake/linker_script/arm/linker.cmake @@ -149,7 +149,7 @@ zephyr_linker_section(NAME .ramfunc GROUP RAM_REGION SUBALIGN 8) if(CONFIG_USERSPACE) # This is where the app_mem_partition stuff is going to be placed, once it # is generated by gen_app_partitions.py. _app_smem has its own init-copy - # handling in z_data_copy, so put it in RAM_REGIOM rather than DATA_REGION + # handling in arch_data_copy, so put it in RAM_REGIOM rather than DATA_REGION zephyr_linker_group(NAME APP_SMEM_GROUP GROUP RAM_REGION SYMBOL SECTION) zephyr_linker_symbol(SYMBOL "_app_smem_size" EXPR "@__app_smem_group_size@") zephyr_linker_symbol(SYMBOL "_app_smem_rom_start" EXPR "@__app_smem_group_load_start@") diff --git a/cmake/toolchain/iar/Kconfig b/cmake/toolchain/iar/Kconfig index 4e994e6fc38a3..5733b881eef8c 100644 --- a/cmake/toolchain/iar/Kconfig +++ b/cmake/toolchain/iar/Kconfig @@ -21,7 +21,7 @@ config IAR_DATA_INIT select SKIP_BSS_CLEAR # IAR handles zeroing. help IAR handles initialization of static variables. - Instead of `z_prep_c` calling Zephyrs `z_data_copy` + Instead of `z_prep_c` calling Zephyrs `arch_data_copy` we call IARs own proprietary initialization method which can save time and space. @@ -29,7 +29,7 @@ config IAR_ZEPHYR_INIT bool "Zephyr" help Zephyr handles initialization of static variables. - This is the regular `z_data_copy`. + This is the regular `arch_data_copy`. endchoice diff --git a/include/zephyr/arch/common/init.h b/include/zephyr/arch/common/init.h new file mode 100644 index 0000000000000..ed1d05069dc63 --- /dev/null +++ b/include/zephyr/arch/common/init.h @@ -0,0 +1,35 @@ +/** + * SPDX-License-Identifier: Apache-2.0 + * Copyright The Zephyr Project Contributors + */ + +#ifndef ZEPHYR_ARCH_COMMON_INIT_H_ +#define ZEPHYR_ARCH_COMMON_INIT_H_ + +FUNC_NORETURN void z_cstart(void); + +/* Early boot functions */ +void arch_early_memset(void *dst, int c, size_t n); +void arch_early_memcpy(void *dst, const void *src, size_t n); + +void arch_bss_zero(void); + +#ifdef CONFIG_LINKER_USE_BOOT_SECTION +void arch_bss_zero_boot(void); +#else +static inline void arch_bss_zero_boot(void) +{ + /* Do nothing */ +} +#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ + +#ifdef CONFIG_LINKER_USE_PINNED_SECTION +void arch_bss_zero_pinned(void); +#else +static inline void arch_bss_zero_pinned(void) +{ + /* Do nothing */ +} +#endif /* CONFIG_LINKER_USE_PINNED_SECTION */ + +#endif /* ZEPHYR_ARCH_COMMON_INIT_H_ */ diff --git a/include/zephyr/arch/common/xip.h b/include/zephyr/arch/common/xip.h new file mode 100644 index 0000000000000..7d945f1531ecc --- /dev/null +++ b/include/zephyr/arch/common/xip.h @@ -0,0 +1,24 @@ +/* + * Copyright The Zephyr Project Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_ARCH_INCLUDE_XIP_H_ +#define ZEPHYR_ARCH_INCLUDE_XIP_H_ + +#ifndef _ASMLANGUAGE +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef CONFIG_XIP +void arch_data_copy(void); +#else +static inline void arch_data_copy(void) +{ + /* Do nothing */ +} +#endif /* CONFIG_XIP */ + +#endif /* _ASMLANGUAGE */ +#endif /* ZEPHYR_ARCH_INCLUDE_XIP_H_ */ diff --git a/include/zephyr/linker/linker-defs.h b/include/zephyr/linker/linker-defs.h index 976d02ed256be..635b418897c83 100644 --- a/include/zephyr/linker/linker-defs.h +++ b/include/zephyr/linker/linker-defs.h @@ -131,11 +131,11 @@ extern char __kernel_ram_start[]; extern char __kernel_ram_end[]; extern char __kernel_ram_size[]; -/* Used by z_bss_zero or arch-specific implementation */ +/* Used by arch_bss_zero or arch-specific implementation */ extern char __bss_start[]; extern char __bss_end[]; -/* Used by z_data_copy() or arch-specific implementation */ +/* Used by arch_data_copy() or arch-specific implementation */ #ifdef CONFIG_XIP extern char __data_region_load_start[]; extern char __data_region_start[]; diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 075e091cbb62d..5812ae0aac6fd 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -10,6 +10,17 @@ zephyr_syscall_header( ${ZEPHYR_BASE}/include/zephyr/sys/time_units.h ) +# Helper macro to append files to the kernel_files list +macro(kernel_sources_ifdef feature_toggle) + if(${${feature_toggle}}) + list(APPEND kernel_files ${ARGN}) + endif() +endmacro() + +macro(kernel_sources) + list(APPEND kernel_files ${ARGN}) +endmacro() + if(NOT CONFIG_ERRNO_IN_TLS AND NOT CONFIG_LIBC_ERRNO) zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/sys/errno_private.h) endif() @@ -47,7 +58,7 @@ else() # FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. add_compile_options($) -list(APPEND kernel_files +kernel_sources( main_weak.c banner.c busy_wait.c @@ -61,14 +72,11 @@ list(APPEND kernel_files version.c ) -if(CONFIG_SCHED_CPU_MASK) -list(APPEND kernel_files +kernel_sources_ifdef(CONFIG_SCHED_CPU_MASK cpu_mask.c ) -endif() -if(CONFIG_MULTITHREADING) -list(APPEND kernel_files +kernel_sources_ifdef(CONFIG_MULTITHREADING idle.c mailbox.c msg_q.c @@ -83,57 +91,29 @@ list(APPEND kernel_files sched.c ) +if(CONFIG_MULTITHREADING) if (CONFIG_SCHED_SCALABLE OR CONFIG_WAITQ_SCALABLE) -list(APPEND kernel_files priority_queues.c) +kernel_sources(priority_queues.c) endif() # FIXME: Once the prior pipe implementation is removed, this should be included in the above list if(NOT CONFIG_PIPES) -list(APPEND kernel_files pipe.c) +kernel_sources(pipe.c) endif() # NOT CONFIG_PIPES -if(CONFIG_SMP) -list(APPEND kernel_files + +kernel_sources_ifdef(CONFIG_SMP smp.c ipi.c) -endif() else() # CONFIG_MULTITHREADING -list(APPEND kernel_files - nothread.c - ) +kernel_sources(nothread.c) endif() # CONFIG_MULTITHREADING -if(CONFIG_TIMESLICING) -list(APPEND kernel_files - timeslicing.c) -endif() - -if(CONFIG_SPIN_VALIDATE) -list(APPEND kernel_files - spinlock_validate.c) -endif() - -if(CONFIG_IRQ_OFFLOAD) -list(APPEND kernel_files - irq_offload.c - ) -endif() - - -if(CONFIG_THREAD_MONITOR) -list(APPEND kernel_files - thread_monitor.c) -endif() - - -if(CONFIG_XIP) -list(APPEND kernel_files - xip.c) -endif() - -if(CONFIG_DEMAND_PAGING_STATS) -list(APPEND kernel_files - paging/statistics.c) -endif() +kernel_sources_ifdef(CONFIG_TIMESLICING timeslicing.c) +kernel_sources_ifdef(CONFIG_SPIN_VALIDATE spinlock_validate.c) +kernel_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c) +kernel_sources_ifdef(CONFIG_BOOTARGS boot_args.c) +kernel_sources_ifdef(CONFIG_THREAD_MONITOR thread_monitor.c) +kernel_sources_ifdef(CONFIG_DEMAND_PAGING_STATS paging/statistics.c) add_library(kernel ${kernel_files}) diff --git a/kernel/Kconfig b/kernel/Kconfig index e28b580fb50b9..a4e5aa5d18c1f 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -894,16 +894,6 @@ config BUSYWAIT_CPU_LOOPS_PER_USEC system timer support. If accuracy is very important then implementing arch_busy_wait() should be considered. -config XIP - bool "Execute in place" - help - This option allows the kernel to operate with its text and read-only - sections residing in ROM (or similar read-only memory). Not all boards - support this option so it must be used with care; you must also - supply a linker command file when building your image. Enabling this - option increases both the code and data footprint of the image. - - menu "Security Options" config REQUIRES_STACK_CANARIES @@ -1133,20 +1123,20 @@ config STATIC_INIT_GNU will emit an error if constructors are needed and this option has been disabled. -config BOOTARGS +menuconfig BOOTARGS bool "Support bootargs" help Enables bootargs support and passing them to main(). +if BOOTARGS config DYNAMIC_BOOTARGS bool "Support dynamic bootargs" - depends on BOOTARGS help Enables dynamic bootargs support. config BOOTARGS_STRING string "static bootargs string" - depends on BOOTARGS && !DYNAMIC_BOOTARGS + depends on !DYNAMIC_BOOTARGS help Static bootargs string. It includes argv[0], so if its expected that it contains executable name it should be put at the beginning of this string. @@ -1154,10 +1144,11 @@ config BOOTARGS_STRING config BOOTARGS_ARGS_BUFFER_SIZE int "Size of buffer containing main arguments in bytes" default 1024 - depends on BOOTARGS help Configures size of buffer containing all arguments passed to main. +endif # BOOTARGS + endmenu rsource "Kconfig.device" diff --git a/kernel/boot_args.c b/kernel/boot_args.c new file mode 100644 index 0000000000000..0aaf4f74414fa --- /dev/null +++ b/kernel/boot_args.c @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright The Zephyr Project contributors + */ + +#include +#include +#include +LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); + +extern const char *get_bootargs(void); +char **prepare_main_args(int *argc) +{ +#ifdef CONFIG_DYNAMIC_BOOTARGS + const char *bootargs = get_bootargs(); +#else + const char bootargs[] = CONFIG_BOOTARGS_STRING; +#endif + + /* beginning of the buffer contains argument's strings, end of it contains argvs */ + static char args_buf[CONFIG_BOOTARGS_ARGS_BUFFER_SIZE]; + char *strings_end = (char *)args_buf; + char **argv_begin = (char **)WB_DN( + args_buf + CONFIG_BOOTARGS_ARGS_BUFFER_SIZE - sizeof(char *)); + int i = 0; + + *argc = 0; + *argv_begin = NULL; + +#ifdef CONFIG_DYNAMIC_BOOTARGS + if (!bootargs) { + return argv_begin; + } +#endif + + while (1) { + while (isspace(bootargs[i])) { + i++; + } + + if (bootargs[i] == '\0') { + return argv_begin; + } + + if (strings_end + sizeof(char *) >= (char *)argv_begin) { + LOG_WRN("not enough space in args buffer to accommodate all bootargs" + " - bootargs truncated"); + return argv_begin; + } + + argv_begin--; + memmove(argv_begin, argv_begin + 1, *argc * sizeof(char *)); + argv_begin[*argc] = strings_end; + + bool quoted = false; + + if (bootargs[i] == '\"' || bootargs[i] == '\'') { + char delimiter = bootargs[i]; + + for (int j = i + 1; bootargs[j] != '\0'; j++) { + if (bootargs[j] == delimiter) { + quoted = true; + break; + } + } + } + + if (quoted) { + char delimiter = bootargs[i]; + + i++; /* strip quotes */ + while (bootargs[i] != delimiter + && strings_end < (char *)argv_begin) { + *strings_end++ = bootargs[i++]; + } + i++; /* strip quotes */ + } else { + while (!isspace(bootargs[i]) + && bootargs[i] != '\0' + && strings_end < (char *)argv_begin) { + *strings_end++ = bootargs[i++]; + } + } + + if (strings_end < (char *)argv_begin) { + *strings_end++ = '\0'; + } else { + LOG_WRN("not enough space in args buffer to accommodate all bootargs" + " - bootargs truncated"); + argv_begin[*argc] = NULL; + return argv_begin; + } + (*argc)++; + } +} diff --git a/kernel/device.c b/kernel/device.c index 88e1d074ab189..dc70163014a45 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -13,6 +13,7 @@ #include #include #include +#include /** * @brief Initialize state for all static devices. @@ -27,6 +28,58 @@ void z_device_state_init(void) } } + +int do_device_init(const struct device *dev) +{ + int rc = 0; + + if (dev->ops.init != NULL) { + rc = dev->ops.init(dev); + /* Mark device initialized. If initialization + * failed, record the error condition. + */ + if (rc != 0) { + if (rc < 0) { + rc = -rc; + } + if (rc > UINT8_MAX) { + rc = UINT8_MAX; + } + dev->state->init_res = rc; + } + } + + dev->state->initialized = true; + + if (rc == 0) { + /* Run automatic device runtime enablement */ + (void)pm_device_runtime_auto_enable(dev); + } + + return rc; +} + + +int z_impl_device_init(const struct device *dev) +{ + if (dev->state->initialized) { + return -EALREADY; + } + + return do_device_init(dev); +} + +#ifdef CONFIG_USERSPACE +static inline int z_vrfy_device_init(const struct device *dev) +{ + K_OOPS(K_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY)); + + return z_impl_device_init(dev); +} +#include +#endif + + const struct device *z_impl_device_get_binding(const char *name) { /* A null string identifies no device. So does an empty diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index eadacf936c964..ae50e36789854 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -31,42 +31,9 @@ void z_init_cpu(int id); void z_init_thread_base(struct _thread_base *thread_base, int priority, uint32_t initial_state, unsigned int options); -/* Early boot functions */ -void z_early_memset(void *dst, int c, size_t n); -void z_early_memcpy(void *dst, const void *src, size_t n); - -void z_bss_zero(void); -#ifdef CONFIG_XIP -void z_data_copy(void); -#else -static inline void z_data_copy(void) -{ - /* Do nothing */ -} -#endif /* CONFIG_XIP */ - -#ifdef CONFIG_LINKER_USE_BOOT_SECTION -void z_bss_zero_boot(void); -#else -static inline void z_bss_zero_boot(void) -{ - /* Do nothing */ -} -#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ - -#ifdef CONFIG_LINKER_USE_PINNED_SECTION -void z_bss_zero_pinned(void); -#else -static inline void z_bss_zero_pinned(void) -{ - /* Do nothing */ -} -#endif /* CONFIG_LINKER_USE_PINNED_SECTION */ FUNC_NORETURN void z_cstart(void); -void z_device_state_init(void); - extern FUNC_NORETURN void z_thread_entry(k_thread_entry_t entry, void *p1, void *p2, void *p3); diff --git a/kernel/init.c b/kernel/init.c index 3c8b11d2bd487..1ce417276d60b 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -38,8 +38,9 @@ #include #include #include -#include #include +#include + LOG_MODULE_REGISTER(os, CONFIG_KERNEL_LOG_LEVEL); /* the only struct z_kernel instance */ @@ -178,122 +179,6 @@ static struct k_obj_core_stats_desc kernel_stats_desc = { #endif /* CONFIG_OBJ_CORE_STATS_SYSTEM */ #endif /* CONFIG_OBJ_CORE_SYSTEM */ -/* LCOV_EXCL_START - * - * This code is called so early in the boot process that code coverage - * doesn't work properly. In addition, not all arches call this code, - * some like x86 do this with optimized assembly - */ - -/** - * @brief equivalent of memset() for early boot usage - * - * Architectures that can't safely use the regular (optimized) memset very - * early during boot because e.g. hardware isn't yet sufficiently initialized - * may override this with their own safe implementation. - */ -__boot_func -void __weak z_early_memset(void *dst, int c, size_t n) -{ - (void) memset(dst, c, n); -} - -/** - * @brief equivalent of memcpy() for early boot usage - * - * Architectures that can't safely use the regular (optimized) memcpy very - * early during boot because e.g. hardware isn't yet sufficiently initialized - * may override this with their own safe implementation. - */ -__boot_func -void __weak z_early_memcpy(void *dst, const void *src, size_t n) -{ - (void) memcpy(dst, src, n); -} - -/** - * @brief Clear BSS - * - * This routine clears the BSS region, so all bytes are 0. - */ -__boot_func -void z_bss_zero(void) -{ - if (IS_ENABLED(CONFIG_SKIP_BSS_CLEAR)) { - return; - } - - z_early_memset(__bss_start, 0, __bss_end - __bss_start); -#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm)) - z_early_memset(&__ccm_bss_start, 0, - (uintptr_t) &__ccm_bss_end - - (uintptr_t) &__ccm_bss_start); -#endif -#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) - z_early_memset(&__dtcm_bss_start, 0, - (uintptr_t) &__dtcm_bss_end - - (uintptr_t) &__dtcm_bss_start); -#endif -#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ocm)) - z_early_memset(&__ocm_bss_start, 0, - (uintptr_t) &__ocm_bss_end - - (uintptr_t) &__ocm_bss_start); -#endif -#ifdef CONFIG_CODE_DATA_RELOCATION - extern void bss_zeroing_relocation(void); - - bss_zeroing_relocation(); -#endif /* CONFIG_CODE_DATA_RELOCATION */ -#ifdef CONFIG_COVERAGE_GCOV - z_early_memset(&__gcov_bss_start, 0, - ((uintptr_t) &__gcov_bss_end - (uintptr_t) &__gcov_bss_start)); -#endif /* CONFIG_COVERAGE_GCOV */ -#ifdef CONFIG_NOCACHE_MEMORY - z_early_memset(&_nocache_ram_start, 0, - (uintptr_t)&_nocache_ram_end - (uintptr_t)&_nocache_ram_start); -#endif -} - -#ifdef CONFIG_LINKER_USE_BOOT_SECTION -/** - * @brief Clear BSS within the boot region - * - * This routine clears the BSS within the boot region. - * This is separate from z_bss_zero() as boot region may - * contain symbols required for the boot process before - * paging is initialized. - */ -__boot_func -void z_bss_zero_boot(void) -{ - z_early_memset(&lnkr_boot_bss_start, 0, - (uintptr_t)&lnkr_boot_bss_end - - (uintptr_t)&lnkr_boot_bss_start); -} -#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ - -#ifdef CONFIG_LINKER_USE_PINNED_SECTION -/** - * @brief Clear BSS within the pinned region - * - * This routine clears the BSS within the pinned region. - * This is separate from z_bss_zero() as pinned region may - * contain symbols required for the boot process before - * paging is initialized. - */ -#ifdef CONFIG_LINKER_USE_BOOT_SECTION -__boot_func -#else -__pinned_func -#endif /* CONFIG_LINKER_USE_BOOT_SECTION */ -void z_bss_zero_pinned(void) -{ - z_early_memset(&lnkr_pinned_bss_start, 0, - (uintptr_t)&lnkr_pinned_bss_end - - (uintptr_t)&lnkr_pinned_bss_start); -} -#endif /* CONFIG_LINKER_USE_PINNED_SECTION */ - #ifdef CONFIG_REQUIRES_STACK_CANARIES #ifdef CONFIG_STACK_CANARIES_TLS extern Z_THREAD_LOCAL volatile uintptr_t __stack_chk_guard; @@ -307,34 +192,20 @@ extern volatile uintptr_t __stack_chk_guard; __pinned_bss bool z_sys_post_kernel; -static int do_device_init(const struct device *dev) -{ - int rc = 0; - - if (dev->ops.init != NULL) { - rc = dev->ops.init(dev); - /* Mark device initialized. If initialization - * failed, record the error condition. - */ - if (rc != 0) { - if (rc < 0) { - rc = -rc; - } - if (rc > UINT8_MAX) { - rc = UINT8_MAX; - } - dev->state->init_res = rc; - } - } - - dev->state->initialized = true; +/* defined in device.c */ +extern int do_device_init(const struct device *dev); - if (rc == 0) { - /* Run automatic device runtime enablement */ - (void)pm_device_runtime_auto_enable(dev); +/** + * @brief Initialize state for all static devices. + * + * The state object is always zero-initialized, but this may not be + * sufficient. + */ +static void z_device_state_init(void) +{ + STRUCT_SECTION_FOREACH(device, dev) { + k_object_init(dev); } - - return rc; } /** @@ -380,116 +251,9 @@ static void z_sys_init_run_level(enum init_level level) } } - -int z_impl_device_init(const struct device *dev) -{ - if (dev->state->initialized) { - return -EALREADY; - } - - return do_device_init(dev); -} - -#ifdef CONFIG_USERSPACE -static inline int z_vrfy_device_init(const struct device *dev) -{ - K_OOPS(K_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY)); - - return z_impl_device_init(dev); -} -#include -#endif - +/* defined in banner.c */ extern void boot_banner(void); -#ifdef CONFIG_BOOTARGS -extern const char *get_bootargs(void); -static char **prepare_main_args(int *argc) -{ -#ifdef CONFIG_DYNAMIC_BOOTARGS - const char *bootargs = get_bootargs(); -#else - const char bootargs[] = CONFIG_BOOTARGS_STRING; -#endif - - /* beginning of the buffer contains argument's strings, end of it contains argvs */ - static char args_buf[CONFIG_BOOTARGS_ARGS_BUFFER_SIZE]; - char *strings_end = (char *)args_buf; - char **argv_begin = (char **)WB_DN( - args_buf + CONFIG_BOOTARGS_ARGS_BUFFER_SIZE - sizeof(char *)); - int i = 0; - - *argc = 0; - *argv_begin = NULL; - -#ifdef CONFIG_DYNAMIC_BOOTARGS - if (!bootargs) { - return argv_begin; - } -#endif - - while (1) { - while (isspace(bootargs[i])) { - i++; - } - - if (bootargs[i] == '\0') { - return argv_begin; - } - - if (strings_end + sizeof(char *) >= (char *)argv_begin) { - LOG_WRN("not enough space in args buffer to accommodate all bootargs" - " - bootargs truncated"); - return argv_begin; - } - - argv_begin--; - memmove(argv_begin, argv_begin + 1, *argc * sizeof(char *)); - argv_begin[*argc] = strings_end; - - bool quoted = false; - - if (bootargs[i] == '\"' || bootargs[i] == '\'') { - char delimiter = bootargs[i]; - - for (int j = i + 1; bootargs[j] != '\0'; j++) { - if (bootargs[j] == delimiter) { - quoted = true; - break; - } - } - } - - if (quoted) { - char delimiter = bootargs[i]; - - i++; /* strip quotes */ - while (bootargs[i] != delimiter - && strings_end < (char *)argv_begin) { - *strings_end++ = bootargs[i++]; - } - i++; /* strip quotes */ - } else { - while (!isspace(bootargs[i]) - && bootargs[i] != '\0' - && strings_end < (char *)argv_begin) { - *strings_end++ = bootargs[i++]; - } - } - - if (strings_end < (char *)argv_begin) { - *strings_end++ = '\0'; - } else { - LOG_WRN("not enough space in args buffer to accommodate all bootargs" - " - bootargs truncated"); - argv_begin[*argc] = NULL; - return argv_begin; - } - (*argc)++; - } -} - -#endif #ifdef CONFIG_STATIC_INIT_GNU @@ -576,6 +340,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3) #ifdef CONFIG_BOOTARGS extern int main(int, char **); + extern char **prepare_main_args(int *argc); int argc = 0; char **argv = prepare_main_args(&argc); @@ -753,7 +518,7 @@ void __weak z_early_rand_get(uint8_t *buf, size_t length) state = state * 2862933555777941757ULL + 3037000493ULL; val = (uint32_t)(state >> 32); rc = MIN(length, sizeof(val)); - z_early_memcpy((void *)buf, &val, rc); + arch_early_memcpy((void *)buf, &val, rc); length -= rc; buf += rc; diff --git a/kernel/mmu.c b/kernel/mmu.c index cb83b2f117618..322fc61c5c0b0 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -19,6 +19,7 @@ #include #include #include +#include #include LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL); @@ -1176,7 +1177,7 @@ void z_mem_manage_init(void) * and the BSS pages can be brought into physical * memory to be cleared. */ - z_bss_zero(); + arch_bss_zero(); #endif /* CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT */ } diff --git a/scripts/build/gen_relocate_app.py b/scripts/build/gen_relocate_app.py index 2f071ea3efc2f..49b91edec4c96 100755 --- a/scripts/build/gen_relocate_app.py +++ b/scripts/build/gen_relocate_app.py @@ -180,6 +180,7 @@ class OutputSection(NamedTuple): #include #include #include +#include """ EXTERN_LINKER_VAR_DECLARATION = """ @@ -204,13 +205,13 @@ class OutputSection(NamedTuple): """ MEMCPY_TEMPLATE = """ - z_early_memcpy(&__{mem}_{kind}_reloc_start, &__{mem}_{kind}_rom_start, + arch_early_memcpy(&__{mem}_{kind}_reloc_start, &__{mem}_{kind}_rom_start, (size_t) &__{mem}_{kind}_reloc_size); """ MEMSET_TEMPLATE = """ - z_early_memset(&__{mem}_bss_reloc_start, 0, + arch_early_memset(&__{mem}_bss_reloc_start, 0, (size_t) &__{mem}_bss_reloc_size); """ diff --git a/soc/espressif/common/loader.c b/soc/espressif/common/loader.c index 625bfb3cc0ae9..d4a907ceda9a0 100644 --- a/soc/espressif/common/loader.c +++ b/soc/espressif/common/loader.c @@ -24,7 +24,7 @@ #include #include -#include +#include #if CONFIG_SOC_SERIES_ESP32C6 #include @@ -270,7 +270,7 @@ void __start(void) "la gp, __global_pointer$\n" ".option pop"); - z_bss_zero(); + arch_bss_zero(); #else /* xtensa */ @@ -279,7 +279,7 @@ void __start(void) /* Move the exception vector table to IRAM. */ __asm__ __volatile__("wsr %0, vecbase" : : "r"(&_init_start)); - z_bss_zero(); + arch_bss_zero(); __asm__ __volatile__("" : : "g"(&__bss_start) : "memory"); diff --git a/soc/espressif/esp32/soc.c b/soc/espressif/esp32/soc.c index 6aacc61b0e1c6..11ced8dc95924 100644 --- a/soc/espressif/esp32/soc.c +++ b/soc/espressif/esp32/soc.c @@ -16,7 +16,7 @@ #include #include -extern void z_prep_c(void); +extern FUNC_NORETURN void z_prep_c(void); extern void esp_reset_reason_init(void); void IRAM_ATTR __esp_platform_app_start(void) diff --git a/soc/espressif/esp32/soc_appcpu.c b/soc/espressif/esp32/soc_appcpu.c index 32305009336fd..a682a87753c67 100644 --- a/soc/espressif/esp32/soc_appcpu.c +++ b/soc/espressif/esp32/soc_appcpu.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ void __appcpu_start(void); static HDR_ATTR void (*_entry_point)(void) = &__appcpu_start; -extern void z_prep_c(void); +extern FUNC_NORETURN void z_prep_c(void); static void core_intr_matrix_clear(void) { @@ -65,7 +65,7 @@ void IRAM_ATTR __appcpu_start(void) : "r"(&_init_start)); /* Zero out BSS. Clobber _bss_start to avoid memset() elision. */ - z_bss_zero(); + arch_bss_zero(); __asm__ __volatile__ ( "" diff --git a/soc/espressif/esp32c2/soc.c b/soc/espressif/esp32c2/soc.c index c20f02f3734bb..c552ae2169578 100644 --- a/soc/espressif/esp32c2/soc.c +++ b/soc/espressif/esp32c2/soc.c @@ -13,9 +13,10 @@ #include #include #include -#include +#include extern void esp_reset_reason_init(void); +extern FUNC_NORETURN void z_cstart(void); void IRAM_ATTR __esp_platform_app_start(void) { diff --git a/soc/espressif/esp32c3/soc.c b/soc/espressif/esp32c3/soc.c index ee6227338a953..7e2546c243ba1 100644 --- a/soc/espressif/esp32c3/soc.c +++ b/soc/espressif/esp32c3/soc.c @@ -14,9 +14,10 @@ #include #include #include -#include +#include extern void esp_reset_reason_init(void); +extern FUNC_NORETURN void z_cstart(void); void IRAM_ATTR __esp_platform_app_start(void) { diff --git a/soc/espressif/esp32c6/soc.c b/soc/espressif/esp32c6/soc.c index 4fc7c10c0fa9d..f709351d6f0fb 100644 --- a/soc/espressif/esp32c6/soc.c +++ b/soc/espressif/esp32c6/soc.c @@ -13,9 +13,10 @@ #include #include #include -#include +#include extern void esp_reset_reason_init(void); +extern FUNC_NORETURN void z_cstart(void); void IRAM_ATTR __esp_platform_app_start(void) { diff --git a/soc/espressif/esp32c6/soc_lpcore.c b/soc/espressif/esp32c6/soc_lpcore.c index e2e5a5d2b53cf..a687d4af35d5f 100644 --- a/soc/espressif/esp32c6/soc_lpcore.c +++ b/soc/espressif/esp32c6/soc_lpcore.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include "soc/soc_caps.h" #include "esp_rom_caps.h" #include "rom/ets_sys.h" @@ -12,9 +13,9 @@ #include "ulp_lp_core_memory_shared.h" #include "ulp_lp_core_print.h" #include -#include extern void main(void); +extern FUNC_NORETURN void z_cstart(void); /* Initialize lp core related system functions before calling user's main*/ void lp_core_startup(void) diff --git a/soc/espressif/esp32s2/soc.c b/soc/espressif/esp32s2/soc.c index 8f673a13096e8..3666d695dccb7 100644 --- a/soc/espressif/esp32s2/soc.c +++ b/soc/espressif/esp32s2/soc.c @@ -15,7 +15,7 @@ #include #include -extern void z_prep_c(void); +extern FUNC_NORETURN void z_prep_c(void); extern void esp_reset_reason_init(void); void IRAM_ATTR __esp_platform_app_start(void) diff --git a/soc/espressif/esp32s3/soc.c b/soc/espressif/esp32s3/soc.c index 7aef841382d33..e01b4f8b04fd7 100644 --- a/soc/espressif/esp32s3/soc.c +++ b/soc/espressif/esp32s3/soc.c @@ -16,7 +16,7 @@ #include #include -extern void z_prep_c(void); +extern FUNC_NORETURN void z_prep_c(void); extern void esp_reset_reason_init(void); static void IRAM_ATTR esp_errata(void) diff --git a/soc/espressif/esp32s3/soc_appcpu.c b/soc/espressif/esp32s3/soc_appcpu.c index 517b1e187d753..4cb0e404857ef 100644 --- a/soc/espressif/esp32s3/soc_appcpu.c +++ b/soc/espressif/esp32s3/soc_appcpu.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ void __appcpu_start(void); static HDR_ATTR void (*_entry_point)(void) = &__appcpu_start; -extern void z_prep_c(void); +extern FUNC_NORETURN void z_prep_c(void); static void core_intr_matrix_clear(void) { @@ -57,7 +57,7 @@ void IRAM_ATTR __appcpu_start(void) __asm__ __volatile__("wsr %0, vecbase" : : "r"(&_init_start)); /* Zero out BSS. Clobber _bss_start to avoid memset() elision. */ - z_bss_zero(); + arch_bss_zero(); __asm__ __volatile__("" : : "g"(&__bss_start) : "memory"); diff --git a/tests/application_development/code_relocation/src/main.c b/tests/application_development/code_relocation/src/main.c index e8554c4354c0e..e9cd592401e82 100644 --- a/tests/application_development/code_relocation/src/main.c +++ b/tests/application_development/code_relocation/src/main.c @@ -42,7 +42,7 @@ void disable_mpu_rasr_xn(void) /* override the default memcpy as zephyr will call this before relocation happens */ __boot_func -void z_early_memcpy(void *dst, const void *src, size_t n) +void arch_early_memcpy(void *dst, const void *src, size_t n) { /* attempt word-sized copying only if buffers have identical alignment */ unsigned char *d_byte = (unsigned char *)dst; @@ -56,7 +56,7 @@ void z_early_memcpy(void *dst, const void *src, size_t n) } __boot_func -void z_early_memset(void *dst, int c, size_t n) +void arch_early_memset(void *dst, int c, size_t n) { /* do byte-sized initialization until word-aligned or finished */ diff --git a/tests/kernel/gen_isr_table/CMakeLists.txt b/tests/arch/common/gen_isr_table/CMakeLists.txt similarity index 100% rename from tests/kernel/gen_isr_table/CMakeLists.txt rename to tests/arch/common/gen_isr_table/CMakeLists.txt diff --git a/tests/kernel/gen_isr_table/boards/lpcxpresso54114_lpc54114_m4.conf b/tests/arch/common/gen_isr_table/boards/lpcxpresso54114_lpc54114_m4.conf similarity index 100% rename from tests/kernel/gen_isr_table/boards/lpcxpresso54114_lpc54114_m4.conf rename to tests/arch/common/gen_isr_table/boards/lpcxpresso54114_lpc54114_m4.conf diff --git a/tests/kernel/gen_isr_table/prj.conf b/tests/arch/common/gen_isr_table/prj.conf similarity index 100% rename from tests/kernel/gen_isr_table/prj.conf rename to tests/arch/common/gen_isr_table/prj.conf diff --git a/tests/kernel/gen_isr_table/src/main.c b/tests/arch/common/gen_isr_table/src/main.c similarity index 100% rename from tests/kernel/gen_isr_table/src/main.c rename to tests/arch/common/gen_isr_table/src/main.c diff --git a/tests/kernel/gen_isr_table/src/multilevel_irq.c b/tests/arch/common/gen_isr_table/src/multilevel_irq.c similarity index 100% rename from tests/kernel/gen_isr_table/src/multilevel_irq.c rename to tests/arch/common/gen_isr_table/src/multilevel_irq.c diff --git a/tests/kernel/gen_isr_table/testcase.yaml b/tests/arch/common/gen_isr_table/testcase.yaml similarity index 100% rename from tests/kernel/gen_isr_table/testcase.yaml rename to tests/arch/common/gen_isr_table/testcase.yaml diff --git a/tests/kernel/interrupt/CMakeLists.txt b/tests/arch/common/interrupt/CMakeLists.txt similarity index 100% rename from tests/kernel/interrupt/CMakeLists.txt rename to tests/arch/common/interrupt/CMakeLists.txt diff --git a/tests/kernel/interrupt/Kconfig b/tests/arch/common/interrupt/Kconfig similarity index 100% rename from tests/kernel/interrupt/Kconfig rename to tests/arch/common/interrupt/Kconfig diff --git a/tests/kernel/interrupt/multilevel_irq.overlay b/tests/arch/common/interrupt/multilevel_irq.overlay similarity index 100% rename from tests/kernel/interrupt/multilevel_irq.overlay rename to tests/arch/common/interrupt/multilevel_irq.overlay diff --git a/tests/kernel/interrupt/prj.conf b/tests/arch/common/interrupt/prj.conf similarity index 100% rename from tests/kernel/interrupt/prj.conf rename to tests/arch/common/interrupt/prj.conf diff --git a/tests/kernel/interrupt/src/dynamic_isr.c b/tests/arch/common/interrupt/src/dynamic_isr.c similarity index 100% rename from tests/kernel/interrupt/src/dynamic_isr.c rename to tests/arch/common/interrupt/src/dynamic_isr.c diff --git a/tests/kernel/interrupt/src/dynamic_shared_irq.c b/tests/arch/common/interrupt/src/dynamic_shared_irq.c similarity index 100% rename from tests/kernel/interrupt/src/dynamic_shared_irq.c rename to tests/arch/common/interrupt/src/dynamic_shared_irq.c diff --git a/tests/kernel/interrupt/src/interrupt_offload.c b/tests/arch/common/interrupt/src/interrupt_offload.c similarity index 100% rename from tests/kernel/interrupt/src/interrupt_offload.c rename to tests/arch/common/interrupt/src/interrupt_offload.c diff --git a/tests/kernel/interrupt/src/multilevel_irq.c b/tests/arch/common/interrupt/src/multilevel_irq.c similarity index 100% rename from tests/kernel/interrupt/src/multilevel_irq.c rename to tests/arch/common/interrupt/src/multilevel_irq.c diff --git a/tests/kernel/interrupt/src/nested_irq.c b/tests/arch/common/interrupt/src/nested_irq.c similarity index 100% rename from tests/kernel/interrupt/src/nested_irq.c rename to tests/arch/common/interrupt/src/nested_irq.c diff --git a/tests/kernel/interrupt/src/prevent_irq.c b/tests/arch/common/interrupt/src/prevent_irq.c similarity index 100% rename from tests/kernel/interrupt/src/prevent_irq.c rename to tests/arch/common/interrupt/src/prevent_irq.c diff --git a/tests/kernel/interrupt/src/regular_isr.c b/tests/arch/common/interrupt/src/regular_isr.c similarity index 100% rename from tests/kernel/interrupt/src/regular_isr.c rename to tests/arch/common/interrupt/src/regular_isr.c diff --git a/tests/kernel/interrupt/src/static_shared_irq.c b/tests/arch/common/interrupt/src/static_shared_irq.c similarity index 100% rename from tests/kernel/interrupt/src/static_shared_irq.c rename to tests/arch/common/interrupt/src/static_shared_irq.c diff --git a/tests/kernel/interrupt/src/sw_isr_table.c b/tests/arch/common/interrupt/src/sw_isr_table.c similarity index 100% rename from tests/kernel/interrupt/src/sw_isr_table.c rename to tests/arch/common/interrupt/src/sw_isr_table.c diff --git a/tests/kernel/interrupt/src/test_shared_irq.h b/tests/arch/common/interrupt/src/test_shared_irq.h similarity index 100% rename from tests/kernel/interrupt/src/test_shared_irq.h rename to tests/arch/common/interrupt/src/test_shared_irq.h diff --git a/tests/kernel/interrupt/testcase.yaml b/tests/arch/common/interrupt/testcase.yaml similarity index 100% rename from tests/kernel/interrupt/testcase.yaml rename to tests/arch/common/interrupt/testcase.yaml diff --git a/tests/kernel/xip/CMakeLists.txt b/tests/arch/common/xip/CMakeLists.txt similarity index 100% rename from tests/kernel/xip/CMakeLists.txt rename to tests/arch/common/xip/CMakeLists.txt diff --git a/tests/kernel/xip/README.txt b/tests/arch/common/xip/README.txt similarity index 100% rename from tests/kernel/xip/README.txt rename to tests/arch/common/xip/README.txt diff --git a/tests/kernel/xip/prj.conf b/tests/arch/common/xip/prj.conf similarity index 100% rename from tests/kernel/xip/prj.conf rename to tests/arch/common/xip/prj.conf diff --git a/tests/kernel/xip/src/main.c b/tests/arch/common/xip/src/main.c similarity index 100% rename from tests/kernel/xip/src/main.c rename to tests/arch/common/xip/src/main.c diff --git a/tests/kernel/xip/testcase.yaml b/tests/arch/common/xip/testcase.yaml similarity index 100% rename from tests/kernel/xip/testcase.yaml rename to tests/arch/common/xip/testcase.yaml