From 2d7460482de9ee1aaaa05a48ac9f5db2fb9114a3 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Fri, 25 Oct 2019 00:08:21 +0900 Subject: [PATCH] headers: Refactor kernel and arch headers. This commit refactors kernel and arch headers to establish a boundary between private and public interface headers. The refactoring strategy used in this commit is detailed in the issue This commit introduces the following major changes: 1. Establish a clear boundary between private and public headers by removing "kernel/include" and "arch/*/include" from the global include paths. Ideally, only kernel/ and arch/*/ source files should reference the headers in these directories. If these headers must be used by a component, these include paths shall be manually added to the CMakeLists.txt file of the component. This is intended to discourage applications from including private kernel and arch headers either knowingly and unknowingly. - kernel/include/ (PRIVATE) This directory contains the private headers that provide private kernel definitions which should not be visible outside the kernel and arch source code. All public kernel definitions must be added to an appropriate header located under include/. - arch/*/include/ (PRIVATE) This directory contains the private headers that provide private architecture-specific definitions which should not be visible outside the arch and kernel source code. All public architecture- specific definitions must be added to an appropriate header located under include/arch/*/. - include/ AND include/sys/ (PUBLIC) This directory contains the public headers that provide public kernel definitions which can be referenced by both kernel and application code. - include/arch/*/ (PUBLIC) This directory contains the public headers that provide public architecture-specific definitions which can be referenced by both kernel and application code. 2. Split arch_interface.h into "kernel-to-arch interface" and "public arch interface" divisions. - kernel/include/kernel_arch_interface.h * provides private "kernel-to-arch interface" definition. * includes arch/*/include/kernel_arch_func.h to ensure that the interface function implementations are always available. * includes sys/arch_interface.h so that public arch interface definitions are automatically included when including this file. - arch/*/include/kernel_arch_func.h * provides architecture-specific "kernel-to-arch interface" implementation. * only the functions that will be used in kernel and arch source files are defined here. - include/sys/arch_interface.h * provides "public arch interface" definition. * includes include/arch/arch_inlines.h to ensure that the architecture-specific public inline interface function implementations are always available. - include/arch/arch_inlines.h * includes architecture-specific arch_inlines.h in include/arch/*/arch_inline.h. - include/arch/*/arch_inline.h * provides architecture-specific "public arch interface" inline function implementation. * supersedes include/sys/arch_inline.h. 3. Refactor kernel and the existing architecture implementations. - Remove circular dependency of kernel and arch headers. The following general rules should be observed: * Never include any private headers from public headers * Never include kernel_internal.h in kernel_arch_data.h * Always include kernel_arch_data.h from kernel_arch_func.h * Never include kernel.h from kernel_struct.h either directly or indirectly. Only add the kernel structures that must be referenced from public arch headers in this file. - Relocate syscall_handler.h to include/ so it can be used in the public code. This is necessary because many user-mode public codes reference the functions defined in this header. - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is necessary to provide architecture-specific thread definition for 'struct k_thread' in kernel.h. - Remove any private header dependencies from public headers using the following methods: * If dependency is not required, simply omit * If dependency is required, - Relocate a portion of the required dependencies from the private header to an appropriate public header OR - Relocate the required private header to make it public. This commit supersedes #20047, addresses #19666, and fixes #3056. Signed-off-by: Stephanos Ioannidis --- CMakeLists.txt | 6 +- arch/arc/core/CMakeLists.txt | 41 +- arch/arc/core/fast_irq.S | 1 + arch/arc/core/fatal.c | 3 +- arch/arc/core/fault.c | 1 + arch/arc/core/mpu/CMakeLists.txt | 5 + arch/arc/core/offsets/offsets.c | 3 +- arch/arc/core/regular_irq.S | 1 + arch/arc/core/secureshield/CMakeLists.txt | 13 +- arch/arc/core/switch.S | 1 + arch/arc/core/thread.c | 3 +- arch/arc/include/kernel_arch_data.h | 2 - arch/arc/include/kernel_arch_func.h | 15 +- arch/arm/core/CMakeLists.txt | 5 + arch/arm/core/cortex_m/CMakeLists.txt | 5 + arch/arm/core/cortex_m/fault.c | 5 +- arch/arm/core/cortex_m/thread_abort.c | 1 - arch/arm/core/cortex_r/CMakeLists.txt | 5 + arch/arm/core/cortex_r/fault.c | 1 + arch/arm/core/fatal.c | 5 - arch/arm/core/irq_manage.c | 1 - arch/arm/core/offsets/offsets.c | 3 +- arch/arm/core/prep_c.c | 10 +- arch/arm/core/swap.c | 3 +- arch/arm/core/thread.c | 3 +- arch/arm/include/kernel_arch_data.h | 2 - arch/arm/include/kernel_arch_func.h | 4 +- arch/common/CMakeLists.txt | 5 + arch/nios2/core/CMakeLists.txt | 33 +- arch/nios2/core/crt0.S | 3 +- arch/nios2/core/exception.S | 3 +- arch/nios2/core/offsets/offsets.c | 3 +- arch/nios2/core/reset.S | 4 +- arch/nios2/core/swap.S | 3 +- arch/nios2/core/thread.c | 5 +- arch/nios2/include/kernel_arch_data.h | 2 - arch/nios2/include/kernel_arch_func.h | 2 + arch/posix/core/cpuhalt.c | 2 +- arch/posix/core/fatal.c | 2 +- arch/posix/core/irq.c | 2 +- arch/posix/core/offsets/offsets.c | 11 +- arch/posix/core/posix_core.c | 2 +- arch/posix/core/thread.c | 3 +- arch/posix/include/kernel_arch_data.h | 2 - arch/posix/include/kernel_arch_func.h | 4 +- arch/riscv/core/CMakeLists.txt | 11 +- arch/riscv/core/irq_manage.c | 4 +- arch/riscv/core/isr.S | 2 +- arch/riscv/core/offsets/offsets.c | 3 +- arch/riscv/core/reset.S | 4 +- arch/riscv/core/swap.S | 5 +- arch/riscv/core/thread.c | 5 +- arch/riscv/include/kernel_arch_data.h | 2 - arch/riscv/include/kernel_arch_func.h | 2 +- arch/x86/core/CMakeLists.txt | 5 + arch/x86/core/ia32/excstub.S | 1 - arch/x86/core/ia32/fatal.c | 5 +- arch/x86/core/ia32/float.c | 4 +- arch/x86/core/ia32/intstub.S | 1 - arch/x86/core/ia32/swap.S | 4 +- arch/x86/core/ia32/thread.c | 7 +- arch/x86/core/ia32/userspace.S | 1 - arch/x86/core/offsets/ia32_offsets.c | 2 - arch/x86/core/offsets/intel64_offsets.c | 4 - arch/x86/core/offsets/offsets.c | 6 +- arch/x86/core/prep_c.c | 3 +- arch/x86/include/ia32/kernel_arch_data.h | 2 - arch/x86/include/intel64/kernel_arch_data.h | 66 -- arch/x86/include/intel64/kernel_arch_func.h | 10 - arch/x86/include/intel64/kernel_arch_thread.h | 56 -- arch/x86/include/kernel_arch_func.h | 2 + arch/x86/include/kernel_arch_thread.h | 15 - arch/xtensa/core/CMakeLists.txt | 33 +- arch/xtensa/core/atomic.S | 2 +- arch/xtensa/core/crt1.S | 2 +- arch/xtensa/core/irq_offload.c | 2 +- arch/xtensa/core/offsets/offsets.c | 9 +- arch/xtensa/core/startup/CMakeLists.txt | 11 +- arch/xtensa/core/window_vectors.S | 2 +- arch/xtensa/include/kernel_arch_data.h | 2 - arch/xtensa/include/kernel_arch_func.h | 22 +- boards/posix/native_posix/CMakeLists.txt | 7 + boards/posix/native_posix/cmdline.c | 2 +- boards/posix/native_posix/cmdline_common.c | 2 +- boards/posix/native_posix/hw_models_top.c | 2 +- boards/posix/native_posix/native_rtc.c | 2 +- boards/posix/native_posix/sdl_events.c | 2 +- boards/posix/native_posix/timer_model.c | 2 +- boards/posix/nrf52_bsim/CMakeLists.txt | 2 + boards/posix/nrf52_bsim/k_busy_wait.c | 2 +- cmake/extensions.cmake | 6 + drivers/entropy/fake_entropy_native_posix.c | 2 +- drivers/ethernet/eth_native_posix_adapt.c | 2 +- drivers/timer/native_posix_timer.c | 2 +- drivers/timer/xtensa_sys_timer.c | 2 +- include/arch/arc/arch.h | 1 + include/arch/arc/arch_inlines.h | 33 + .../arch/arc/thread.h | 6 +- include/arch/arch_inlines.h | 23 + include/arch/arm/arch.h | 1 + include/arch/arm/asm_inline.h | 6 +- include/arch/arm/asm_inline_gcc.h | 6 +- include/arch/arm/error.h | 6 +- include/arch/arm/exc.h | 6 +- include/arch/arm/irq.h | 6 +- include/arch/arm/misc.h | 6 +- include/arch/arm/nmi.h | 6 +- .../arch/arm/thread.h | 6 +- include/arch/cpu.h | 2 +- include/arch/nios2/arch.h | 4 +- .../arch/nios2/thread.h | 6 +- include/arch/posix/arch.h | 3 +- include/arch/posix/asm_inline_gcc.h | 2 +- .../arch/posix}/posix_soc_if.h | 8 +- .../arch/posix}/posix_trace.h | 6 +- .../arch/posix/thread.h | 6 +- include/arch/riscv/arch.h | 3 +- .../arch/riscv/thread.h | 6 +- include/arch/x86/arch_inlines.h | 33 + include/arch/x86/ia32/arch.h | 2 +- .../arch/x86/ia32/thread.h | 6 +- include/arch/x86/intel64/arch.h | 2 +- include/arch/x86/intel64/thread.h | 121 ++++ include/arch/xtensa/arch.h | 3 +- include/arch/xtensa/arch_inlines.h | 36 ++ include/arch/xtensa/irq.h | 2 +- .../arch/xtensa/thread.h | 8 +- .../arch/xtensa}/xtensa_api.h | 0 .../arch/xtensa}/xtensa_config.h | 0 .../arch/xtensa}/xtensa_context.h | 0 .../arch/xtensa}/xtensa_rtos.h | 0 .../arch/xtensa}/xtensa_timer.h | 0 include/kernel.h | 7 + include/kernel_includes.h | 2 +- {kernel/include => include}/kernel_structs.h | 94 +-- include/sys/arch_inlines.h | 468 -------------- include/sys/arch_interface.h | 581 ++++++++++++------ {kernel/include => include}/syscall_handler.h | 9 +- {kernel/include => include}/timeout_q.h | 0 include/toolchain/gcc.h | 2 +- {kernel/include => include}/wait_q.h | 1 - kernel/CMakeLists.txt | 4 + kernel/errno.c | 2 +- kernel/idle.c | 1 - kernel/include/kernel_arch_interface.h | 248 ++++++++ kernel/include/kernel_internal.h | 68 +- kernel/mailbox.c | 1 + kernel/msg_q.c | 1 + kernel/mutex.c | 1 + kernel/pipes.c | 1 + kernel/thread.c | 6 +- kernel/timeout.c | 8 +- kernel/timer.c | 1 + lib/cmsis_rtos_v1/CMakeLists.txt | 5 + lib/cmsis_rtos_v1/cmsis_kernel.c | 4 +- lib/cmsis_rtos_v1/cmsis_mailq.c | 3 +- lib/cmsis_rtos_v1/cmsis_mempool.c | 3 +- lib/cmsis_rtos_v1/cmsis_msgq.c | 2 +- lib/cmsis_rtos_v1/cmsis_mutex.c | 3 +- lib/cmsis_rtos_v1/cmsis_semaphore.c | 3 +- lib/cmsis_rtos_v1/cmsis_signal.c | 2 +- lib/cmsis_rtos_v1/cmsis_thread.c | 2 +- lib/cmsis_rtos_v1/cmsis_timer.c | 3 +- lib/cmsis_rtos_v1/cmsis_wait.c | 2 +- lib/cmsis_rtos_v2/CMakeLists.txt | 5 + lib/cmsis_rtos_v2/event_flags.c | 3 +- lib/cmsis_rtos_v2/kernel.c | 3 +- lib/cmsis_rtos_v2/mempool.c | 3 +- lib/cmsis_rtos_v2/msgq.c | 3 +- lib/cmsis_rtos_v2/mutex.c | 3 +- lib/cmsis_rtos_v2/semaphore.c | 3 +- lib/cmsis_rtos_v2/thread.c | 4 +- lib/cmsis_rtos_v2/timer.c | 3 +- lib/libc/newlib/libc-hooks.c | 1 - lib/posix/CMakeLists.txt | 5 + scripts/gen_relocate_app.py | 1 + soc/arm/atmel_sam/sam3x/soc.c | 2 +- soc/arm/atmel_sam/sam4s/soc.c | 2 +- soc/arm/atmel_sam/same70/soc.c | 2 +- soc/arm/atmel_sam0/common/soc_samd2x.c | 2 +- soc/arm/cypress/psoc6/soc.c | 2 +- soc/arm/microchip_mec/mec1501/soc.c | 2 +- soc/arm/nordic_nrf/nrf51/CMakeLists.txt | 11 +- soc/arm/nordic_nrf/nrf52/CMakeLists.txt | 13 +- soc/arm/nordic_nrf/nrf52/soc.c | 2 +- soc/arm/nordic_nrf/nrf91/soc.c | 2 +- soc/arm/nxp_imx/mcimx6x_m4/soc.c | 2 +- soc/arm/nxp_imx/rt/soc.c | 2 +- soc/arm/nxp_kinetis/k2x/soc.c | 2 +- soc/arm/nxp_kinetis/k6x/soc.c | 2 +- soc/arm/nxp_kinetis/ke1xf/soc.c | 2 +- soc/arm/nxp_kinetis/kwx/soc_kw2xd.c | 2 +- soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt | 5 + soc/arm/nxp_lpc/lpc55xxx/CMakeLists.txt | 5 + soc/arm/silabs_exx32/common/soc.c | 2 +- soc/arm/st_stm32/stm32f0/soc.c | 2 +- soc/arm/st_stm32/stm32f1/soc.c | 2 +- soc/arm/st_stm32/stm32f2/soc.c | 2 +- soc/arm/st_stm32/stm32f3/soc.c | 2 +- soc/arm/st_stm32/stm32f4/soc.c | 2 +- soc/arm/st_stm32/stm32f7/soc.c | 2 +- soc/arm/st_stm32/stm32g0/soc.c | 2 +- soc/arm/st_stm32/stm32g4/soc.c | 2 +- soc/arm/st_stm32/stm32h7/soc_m4.c | 2 +- soc/arm/st_stm32/stm32h7/soc_m7.c | 2 +- soc/arm/st_stm32/stm32l0/soc.c | 2 +- soc/arm/st_stm32/stm32l1/soc.c | 2 +- soc/arm/st_stm32/stm32l4/soc.c | 2 +- soc/arm/st_stm32/stm32mp1/soc.c | 2 +- soc/arm/st_stm32/stm32wb/soc.c | 2 +- soc/arm/ti_lm3s6965/CMakeLists.txt | 9 +- soc/arm/ti_lm3s6965/soc.h | 4 - soc/posix/inf_clock/CMakeLists.txt | 7 + soc/posix/inf_clock/posix_soc.h | 2 +- soc/posix/inf_clock/soc.c | 2 +- subsys/debug/openocd.c | 2 +- subsys/debug/tracing/CMakeLists.txt | 33 +- subsys/debug/tracing/ctf/CMakeLists.txt | 10 +- .../tracing/ctf/bottoms/posix/ctf_bottom.c | 2 +- .../debug/tracing/include/tracing_sysview.h | 1 - subsys/logging/log_backend_native_posix.c | 2 +- subsys/net/ip/CMakeLists.txt | 5 + subsys/testsuite/ztest/include/arch/cpu.h | 14 +- .../ztest/include/kernel_arch_thread.h | 38 -- subsys/testsuite/ztest/include/ztest.h | 1 + tests/arch/arm/arm_thread_swap/CMakeLists.txt | 5 + tests/arch/x86/static_idt/CMakeLists.txt | 5 + tests/arch/x86/static_idt/src/main.c | 2 +- .../x86/x86_mmu_api/src/userbuffer_validate.c | 1 - tests/benchmarks/boot_time/CMakeLists.txt | 5 + tests/benchmarks/sched/CMakeLists.txt | 5 + tests/benchmarks/timing_info/CMakeLists.txt | 5 + .../boards/altera_max10/msgdma/CMakeLists.txt | 5 + tests/boards/altera_max10/msgdma/src/dma.c | 2 +- tests/crypto/rand32/CMakeLists.txt | 5 + tests/kernel/fatal/CMakeLists.txt | 5 + tests/kernel/fifo/fifo_timeout/src/main.c | 1 - .../mem_pool/mem_pool_api/CMakeLists.txt | 5 + .../mem_pool_api/src/test_mpool_api.c | 2 +- .../mem_protect/obj_validation/CMakeLists.txt | 5 + .../kernel/sched/schedule_api/CMakeLists.txt | 5 + tests/kernel/smp/CMakeLists.txt | 5 + .../kernel/threads/thread_apis/CMakeLists.txt | 5 + tests/lib/mem_alloc/src/main.c | 1 - 244 files changed, 1542 insertions(+), 1297 deletions(-) delete mode 100644 arch/x86/include/intel64/kernel_arch_thread.h delete mode 100644 arch/x86/include/kernel_arch_thread.h create mode 100644 include/arch/arc/arch_inlines.h rename arch/arc/include/kernel_arch_thread.h => include/arch/arc/thread.h (87%) create mode 100644 include/arch/arch_inlines.h rename arch/arm/include/kernel_arch_thread.h => include/arch/arm/thread.h (92%) rename arch/nios2/include/kernel_arch_thread.h => include/arch/nios2/thread.h (85%) rename {arch/posix/include => include/arch/posix}/posix_soc_if.h (82%) rename {arch/posix/include => include/arch/posix}/posix_trace.h (88%) rename arch/posix/include/kernel_arch_thread.h => include/arch/posix/thread.h (81%) rename arch/riscv/include/kernel_arch_thread.h => include/arch/riscv/thread.h (87%) create mode 100644 include/arch/x86/arch_inlines.h rename arch/x86/include/ia32/kernel_arch_thread.h => include/arch/x86/ia32/thread.h (97%) create mode 100644 include/arch/x86/intel64/thread.h create mode 100644 include/arch/xtensa/arch_inlines.h rename arch/xtensa/include/kernel_arch_thread.h => include/arch/xtensa/thread.h (94%) rename {arch/xtensa/include => include/arch/xtensa}/xtensa_api.h (100%) rename {arch/xtensa/include => include/arch/xtensa}/xtensa_config.h (100%) rename {arch/xtensa/include => include/arch/xtensa}/xtensa_context.h (100%) rename {arch/xtensa/include => include/arch/xtensa}/xtensa_rtos.h (100%) rename {arch/xtensa/include => include/arch/xtensa}/xtensa_timer.h (100%) rename {kernel/include => include}/kernel_structs.h (66%) delete mode 100644 include/sys/arch_inlines.h rename {kernel/include => include}/syscall_handler.h (98%) rename {kernel/include => include}/timeout_q.h (100%) rename {kernel/include => include}/wait_q.h (98%) create mode 100644 kernel/include/kernel_arch_interface.h delete mode 100644 subsys/testsuite/ztest/include/kernel_arch_thread.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5773cb1784c..90e0d4f40b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,8 +73,6 @@ add_library(zephyr_interface INTERFACE) zephyr_library_named(zephyr) zephyr_include_directories( - kernel/include - ${ARCH_DIR}/${ARCH}/include include include/drivers ${PROJECT_BINARY_DIR}/include/generated @@ -632,6 +630,10 @@ set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c) set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h) add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH}) +target_include_directories(${OFFSETS_LIB} PRIVATE + kernel/include + ${ARCH_DIR}/${ARCH}/include + ) target_link_libraries(${OFFSETS_LIB} zephyr_interface) add_dependencies( ${OFFSETS_LIB} ${SYSCALL_LIST_H_TARGET} diff --git a/arch/arc/core/CMakeLists.txt b/arch/arc/core/CMakeLists.txt index da7f5e438b1..f3f4c721e79 100644 --- a/arch/arc/core/CMakeLists.txt +++ b/arch/arc/core/CMakeLists.txt @@ -3,28 +3,35 @@ zephyr_library() zephyr_library_sources( - thread.c - thread_entry_wrapper.S - cpu_idle.S - fatal.c - fault.c - fault_s.S - irq_manage.c - timestamp.c - isr_wrapper.S - regular_irq.S - switch.S - prep_c.c - reset.S - vector_table.c - ) + thread.c + thread_entry_wrapper.S + cpu_idle.S + fatal.c + fault.c + fault_s.S + irq_manage.c + timestamp.c + isr_wrapper.S + regular_irq.S + switch.S + prep_c.c + reset.S + vector_table.c + ) zephyr_library_sources_ifdef(CONFIG_CACHE_FLUSHING cache.c) zephyr_library_sources_ifdef(CONFIG_ARC_FIRQ fast_irq.S) zephyr_library_sources_if_kconfig(irq_offload.c) -add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu) -add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield) + zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S) zephyr_library_sources_ifdef(CONFIG_ARC_CONNECT arc_connect.c) zephyr_library_sources_ifdef(CONFIG_SMP arc_smp.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arc/include + ) + +add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu) +add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield) diff --git a/arch/arc/core/fast_irq.S b/arch/arc/core/fast_irq.S index 19c83e06bab..9a1db815279 100644 --- a/arch/arc/core/fast_irq.S +++ b/arch/arc/core/fast_irq.S @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/arch/arc/core/fatal.c b/arch/arc/core/fatal.c index c14a0e2c7fd..774b4291ed3 100644 --- a/arch/arc/core/fatal.c +++ b/arch/arc/core/fatal.c @@ -12,9 +12,8 @@ * ARCv2 CPUs. */ -#include +#include #include -#include #include #include LOG_MODULE_DECLARE(os); diff --git a/arch/arc/core/fault.c b/arch/arc/core/fault.c index 2604e83396a..8961b966382 100644 --- a/arch/arc/core/fault.c +++ b/arch/arc/core/fault.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/arch/arc/core/mpu/CMakeLists.txt b/arch/arc/core/mpu/CMakeLists.txt index a81e4ebdb2c..880c7d383a0 100644 --- a/arch/arc/core/mpu/CMakeLists.txt +++ b/arch/arc/core/mpu/CMakeLists.txt @@ -4,3 +4,8 @@ zephyr_library() zephyr_library_sources_if_kconfig(arc_core_mpu.c) zephyr_library_sources_if_kconfig(arc_mpu.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arc/include + ) diff --git a/arch/arc/core/offsets/offsets.c b/arch/arc/core/offsets/offsets.c index 6e9289ff907..18c07caad74 100644 --- a/arch/arc/core/offsets/offsets.c +++ b/arch/arc/core/offsets/offsets.c @@ -22,8 +22,9 @@ * completeness. */ +#include +#include #include -#include #include GEN_OFFSET_SYM(_thread_arch_t, relinquish_cause); diff --git a/arch/arc/core/regular_irq.S b/arch/arc/core/regular_irq.S index 42fe958a939..b7c594c75cc 100644 --- a/arch/arc/core/regular_irq.S +++ b/arch/arc/core/regular_irq.S @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/arch/arc/core/secureshield/CMakeLists.txt b/arch/arc/core/secureshield/CMakeLists.txt index c32133af71f..8b3cb345581 100644 --- a/arch/arc/core/secureshield/CMakeLists.txt +++ b/arch/arc/core/secureshield/CMakeLists.txt @@ -6,7 +6,12 @@ zephyr_library() zephyr_library_sources( - arc_sjli.c - arc_secure.S - secure_sys_services.c -) \ No newline at end of file + arc_sjli.c + arc_secure.S + secure_sys_services.c + ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arc/include + ) diff --git a/arch/arc/core/switch.S b/arch/arc/core/switch.S index 46fbddd0ac8..e312564e2e1 100644 --- a/arch/arc/core/switch.S +++ b/arch/arc/core/switch.S @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/arc/core/thread.c b/arch/arc/core/thread.c index 44052e487a2..e6758076628 100644 --- a/arch/arc/core/thread.c +++ b/arch/arc/core/thread.c @@ -12,8 +12,7 @@ */ #include -#include -#include +#include #include #include diff --git a/arch/arc/include/kernel_arch_data.h b/arch/arc/include/kernel_arch_data.h index 93667eb3255..a5fa4dc63b6 100644 --- a/arch/arc/include/kernel_arch_data.h +++ b/arch/arc/include/kernel_arch_data.h @@ -24,11 +24,9 @@ #include #include #include -#include #ifndef _ASMLANGUAGE #include -#include #include #include #include diff --git a/arch/arc/include/kernel_arch_func.h b/arch/arc/include/kernel_arch_func.h index 79c2f8fcb65..9883b538060 100644 --- a/arch/arc/include/kernel_arch_func.h +++ b/arch/arc/include/kernel_arch_func.h @@ -22,6 +22,8 @@ #if !defined(_ASMLANGUAGE) +#include + #ifdef CONFIG_CPU_ARCV2 #include #include @@ -31,19 +33,6 @@ extern "C" { #endif -static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void) -{ -#ifdef CONFIG_SMP - u32_t core; - - core = z_arc_v2_core_id(); - - return &_kernel.cpus[core]; -#else - return &_kernel.cpus[0]; -#endif -} - static ALWAYS_INLINE void z_arch_kernel_init(void) { z_irq_setup(); diff --git a/arch/arm/core/CMakeLists.txt b/arch/arm/core/CMakeLists.txt index cb090dace32..9428870be58 100644 --- a/arch/arm/core/CMakeLists.txt +++ b/arch/arm/core/CMakeLists.txt @@ -20,6 +20,11 @@ zephyr_library_sources( prep_c.c ) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include +) + zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S) zephyr_library_sources_ifdef(CONFIG_CPLUSPLUS __aeabi_atexit.c) zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c) diff --git a/arch/arm/core/cortex_m/CMakeLists.txt b/arch/arm/core/cortex_m/CMakeLists.txt index 556db5930b1..517143d3a2b 100644 --- a/arch/arm/core/cortex_m/CMakeLists.txt +++ b/arch/arm/core/cortex_m/CMakeLists.txt @@ -15,3 +15,8 @@ zephyr_linker_sources_ifdef(CONFIG_SW_VECTOR_RELAY RAM_SECTIONS vt_pointer_section.ld ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include +) diff --git a/arch/arm/core/cortex_m/fault.c b/arch/arm/core/cortex_m/fault.c index 00b95bc5769..21bfa04a3fe 100644 --- a/arch/arm/core/cortex_m/fault.c +++ b/arch/arm/core/cortex_m/fault.c @@ -11,11 +11,8 @@ * Common fault handler for ARM Cortex-M processors. */ -#include -#include - #include -#include +#include #include #include #include diff --git a/arch/arm/core/cortex_m/thread_abort.c b/arch/arm/core/cortex_m/thread_abort.c index 657d4fc21ee..2189bfb8b4a 100644 --- a/arch/arm/core/cortex_m/thread_abort.c +++ b/arch/arm/core/cortex_m/thread_abort.c @@ -17,7 +17,6 @@ */ #include -#include #include #include #include diff --git a/arch/arm/core/cortex_r/CMakeLists.txt b/arch/arm/core/cortex_r/CMakeLists.txt index a1154a3efb9..1b684470f87 100644 --- a/arch/arm/core/cortex_r/CMakeLists.txt +++ b/arch/arm/core/cortex_r/CMakeLists.txt @@ -9,3 +9,8 @@ zephyr_library_sources( reboot.c stacks.c ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include +) diff --git a/arch/arm/core/cortex_r/fault.c b/arch/arm/core/cortex_r/fault.c index 7b500b4a864..781c92b6f26 100644 --- a/arch/arm/core/cortex_r/fault.c +++ b/arch/arm/core/cortex_r/fault.c @@ -5,6 +5,7 @@ */ #include +#include #include /** diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c index ccbd3a359fb..256d5cebd61 100644 --- a/arch/arm/core/fatal.c +++ b/arch/arm/core/fatal.c @@ -12,12 +12,7 @@ * and Cortex-R CPUs. */ -#include -#include -#include - #include -#include #include LOG_MODULE_DECLARE(os); diff --git a/arch/arm/core/irq_manage.c b/arch/arm/core/irq_manage.c index 0724be773e1..6c9c8334302 100644 --- a/arch/arm/core/irq_manage.c +++ b/arch/arm/core/irq_manage.c @@ -27,7 +27,6 @@ #include #include #include -#include #include extern void z_arm_reserved(void); diff --git a/arch/arm/core/offsets/offsets.c b/arch/arm/core/offsets/offsets.c index b58945c07b6..6ef9ca50eea 100644 --- a/arch/arm/core/offsets/offsets.c +++ b/arch/arm/core/offsets/offsets.c @@ -22,8 +22,9 @@ * completeness. */ +#include +#include #include -#include #include GEN_OFFSET_SYM(_thread_arch_t, basepri); diff --git a/arch/arm/core/prep_c.c b/arch/arm/core/prep_c.c index a2e6eb84879..d62c14e7c99 100644 --- a/arch/arm/core/prep_c.c +++ b/arch/arm/core/prep_c.c @@ -17,14 +17,10 @@ */ #include -#include -#include -#include #include -#include -#if defined(CONFIG_CPU_CORTEX_M) -#include -#elif defined(CONFIG_ARMV7_R) +#include + +#if defined(CONFIG_ARMV7_R) #include #endif diff --git a/arch/arm/core/swap.c b/arch/arm/core/swap.c index 5afb8294ee8..79cdea2bbfb 100644 --- a/arch/arm/core/swap.c +++ b/arch/arm/core/swap.c @@ -5,8 +5,7 @@ */ #include -#include -#include +#include #ifdef CONFIG_EXECUTION_BENCHMARKING extern void read_timer_start_of_swap(void); diff --git a/arch/arm/core/thread.c b/arch/arm/core/thread.c index d06c8f875d6..42672f77eab 100644 --- a/arch/arm/core/thread.c +++ b/arch/arm/core/thread.c @@ -13,8 +13,7 @@ */ #include -#include -#include +#include #include #ifdef CONFIG_USERSPACE diff --git a/arch/arm/include/kernel_arch_data.h b/arch/arm/include/kernel_arch_data.h index 9932dc91011..4dbed96a722 100644 --- a/arch/arm/include/kernel_arch_data.h +++ b/arch/arm/include/kernel_arch_data.h @@ -23,7 +23,6 @@ #include #include #include -#include /* stacks */ @@ -40,7 +39,6 @@ #ifndef _ASMLANGUAGE #include -#include #include #include #include diff --git a/arch/arm/include/kernel_arch_func.h b/arch/arm/include/kernel_arch_func.h index f11204baf53..fc7476d13ab 100644 --- a/arch/arm/include/kernel_arch_func.h +++ b/arch/arm/include/kernel_arch_func.h @@ -17,11 +17,11 @@ * in the offsets.o module. */ -/* this file is only meant to be included by kernel_structs.h */ - #ifndef ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index edeb9c2c308..5b5d42d98c9 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -29,3 +29,8 @@ zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY RAM_SECTIONS nocache.ld ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include +) diff --git a/arch/nios2/core/CMakeLists.txt b/arch/nios2/core/CMakeLists.txt index 63ecaaffed4..925e2f64509 100644 --- a/arch/nios2/core/CMakeLists.txt +++ b/arch/nios2/core/CMakeLists.txt @@ -1,16 +1,23 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( - thread.c - cpu_idle.c - fatal.c - irq_manage.c - swap.S - prep_c.c - reset.S - cache.c - exception.S - crt0.S - ) +zephyr_library() -zephyr_sources_if_kconfig(irq_offload.c) +zephyr_library_sources( + thread.c + cpu_idle.c + fatal.c + irq_manage.c + swap.S + prep_c.c + reset.S + cache.c + exception.S + crt0.S + ) + +zephyr_library_sources_if_kconfig(irq_offload.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/nios2/include + ) diff --git a/arch/nios2/core/crt0.S b/arch/nios2/core/crt0.S index b9c483659fd..f698b882c49 100644 --- a/arch/nios2/core/crt0.S +++ b/arch/nios2/core/crt0.S @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include /* exports */ GTEXT(__start) diff --git a/arch/nios2/core/exception.S b/arch/nios2/core/exception.S index 5f67dc943ef..6090753ba6e 100644 --- a/arch/nios2/core/exception.S +++ b/arch/nios2/core/exception.S @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include /* exports */ diff --git a/arch/nios2/core/offsets/offsets.c b/arch/nios2/core/offsets/offsets.c index 80639af0770..1b735e79b1d 100644 --- a/arch/nios2/core/offsets/offsets.c +++ b/arch/nios2/core/offsets/offsets.c @@ -24,8 +24,9 @@ */ +#include +#include #include -#include #include /* struct coop member offsets */ diff --git a/arch/nios2/core/reset.S b/arch/nios2/core/reset.S index 8c2719cec22..716177da906 100644 --- a/arch/nios2/core/reset.S +++ b/arch/nios2/core/reset.S @@ -4,9 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include +#include GTEXT(__start) diff --git a/arch/nios2/core/swap.S b/arch/nios2/core/swap.S index 7d43520c1e8..c4f2ccf1171 100644 --- a/arch/nios2/core/swap.S +++ b/arch/nios2/core/swap.S @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include /* exports */ diff --git a/arch/nios2/core/thread.c b/arch/nios2/core/thread.c index 532107a3686..8ea1337ed4c 100644 --- a/arch/nios2/core/thread.c +++ b/arch/nios2/core/thread.c @@ -5,10 +5,7 @@ */ #include -#include -#include -#include -#include +#include /* forward declaration to asm function to adjust setup the arguments * to z_thread_entry() since this arch puts the first four arguments diff --git a/arch/nios2/include/kernel_arch_data.h b/arch/nios2/include/kernel_arch_data.h index 6643103f37f..5fa07baa2f1 100644 --- a/arch/nios2/include/kernel_arch_data.h +++ b/arch/nios2/include/kernel_arch_data.h @@ -24,7 +24,6 @@ #include #include #include -#include /* stacks */ @@ -36,7 +35,6 @@ #ifndef _ASMLANGUAGE #include -#include #include #include #include diff --git a/arch/nios2/include/kernel_arch_func.h b/arch/nios2/include/kernel_arch_func.h index 6ff1b38c17f..84ab183b5a0 100644 --- a/arch/nios2/include/kernel_arch_func.h +++ b/arch/nios2/include/kernel_arch_func.h @@ -20,6 +20,8 @@ #ifndef ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_FUNC_H_ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/arch/posix/core/cpuhalt.c b/arch/posix/core/cpuhalt.c index 219d7b7cb3d..57356ba97fb 100644 --- a/arch/posix/core/cpuhalt.c +++ b/arch/posix/core/cpuhalt.c @@ -21,7 +21,7 @@ */ #include "posix_core.h" -#include "posix_soc_if.h" +#include #include void z_arch_cpu_idle(void) diff --git a/arch/posix/core/fatal.c b/arch/posix/core/fatal.c index d5e09660f1a..6fa8df680dd 100644 --- a/arch/posix/core/fatal.c +++ b/arch/posix/core/fatal.c @@ -11,7 +11,7 @@ #include #include #include -#include "posix_soc_if.h" +#include FUNC_NORETURN void z_arch_system_halt(unsigned int reason) { diff --git a/arch/posix/core/irq.c b/arch/posix/core/irq.c index d0b16eba8ee..5fffad7a70d 100644 --- a/arch/posix/core/irq.c +++ b/arch/posix/core/irq.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "posix_soc_if.h" +#include #include "board_irq.h" #ifdef CONFIG_IRQ_OFFLOAD diff --git a/arch/posix/core/offsets/offsets.c b/arch/posix/core/offsets/offsets.c index bd3af1f43f0..600e388e3f6 100644 --- a/arch/posix/core/offsets/offsets.c +++ b/arch/posix/core/offsets/offsets.c @@ -23,18 +23,13 @@ * completeness. */ -#include /* located in kernel/include */ - -/* list of headers that define whose structure offsets will be generated */ - -#include - +#include +#include +#include #include #if defined(CONFIG_FP_SHARING) GEN_OFFSET_SYM(_thread_arch_t, excNestCount); #endif - - GEN_ABS_SYM_END diff --git a/arch/posix/core/posix_core.c b/arch/posix/core/posix_core.c index d24a34dea2a..417b824d051 100644 --- a/arch/posix/core/posix_core.c +++ b/arch/posix/core/posix_core.c @@ -44,7 +44,7 @@ #include "posix_core.h" #include "posix_arch_internal.h" -#include "posix_soc_if.h" +#include #include "kernel_internal.h" #include "kernel_structs.h" #include "ksched.h" diff --git a/arch/posix/core/thread.c b/arch/posix/core/thread.c index f985fe4aea3..0d207db1237 100644 --- a/arch/posix/core/thread.c +++ b/arch/posix/core/thread.c @@ -15,10 +15,11 @@ #include #include +#include #include #include "posix_core.h" -#include "posix_soc_if.h" +#include /* Note that in this arch we cheat quite a bit: we use as stack a normal * pthreads stack and therefore we ignore the stack size diff --git a/arch/posix/include/kernel_arch_data.h b/arch/posix/include/kernel_arch_data.h index 4cdd4ba0df4..40c223815f3 100644 --- a/arch/posix/include/kernel_arch_data.h +++ b/arch/posix/include/kernel_arch_data.h @@ -14,8 +14,6 @@ #ifndef ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_DATA_H_ #define ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_DATA_H_ -#include - /* stacks */ #define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) #define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE) diff --git a/arch/posix/include/kernel_arch_func.h b/arch/posix/include/kernel_arch_func.h index 5d65fde980e..c5b80e90575 100644 --- a/arch/posix/include/kernel_arch_func.h +++ b/arch/posix/include/kernel_arch_func.h @@ -10,9 +10,7 @@ #ifndef ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_FUNC_H_ -#include "kernel.h" -#include -#include "posix_core.h" +#include #ifndef _ASMLANGUAGE diff --git a/arch/riscv/core/CMakeLists.txt b/arch/riscv/core/CMakeLists.txt index 3b14112e0a6..d7c059adb27 100644 --- a/arch/riscv/core/CMakeLists.txt +++ b/arch/riscv/core/CMakeLists.txt @@ -1,6 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( +zephyr_library() + +zephyr_library_sources( cpu_idle.c fatal.c irq_manage.c @@ -11,4 +13,9 @@ zephyr_sources( thread.c ) -zephyr_sources_if_kconfig(irq_offload.c) +zephyr_library_sources_if_kconfig(irq_offload.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/riscv/include +) diff --git a/arch/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index 38fb46579ad..43b7e5850f1 100644 --- a/arch/riscv/core/irq_manage.c +++ b/arch/riscv/core/irq_manage.c @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include #include LOG_MODULE_DECLARE(os); diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S index 6fc5613bcee..78be5b3d346 100644 --- a/arch/riscv/core/isr.S +++ b/arch/riscv/core/isr.S @@ -7,8 +7,8 @@ #include #include -#include #include +#include /* imports */ GDATA(_sw_isr_table) diff --git a/arch/riscv/core/offsets/offsets.c b/arch/riscv/core/offsets/offsets.c index f8f4771c43c..659d0800400 100644 --- a/arch/riscv/core/offsets/offsets.c +++ b/arch/riscv/core/offsets/offsets.c @@ -13,8 +13,9 @@ * structures. */ +#include +#include #include -#include #include #ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE diff --git a/arch/riscv/core/reset.S b/arch/riscv/core/reset.S index 7e3d285e10a..fbe71202da7 100644 --- a/arch/riscv/core/reset.S +++ b/arch/riscv/core/reset.S @@ -5,7 +5,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include +#include /* exports */ GTEXT(__initialize) diff --git a/arch/riscv/core/swap.S b/arch/riscv/core/swap.S index 523b2267818..c81910a8348 100644 --- a/arch/riscv/core/swap.S +++ b/arch/riscv/core/swap.S @@ -4,9 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include +#include #include +#include /* exports */ GTEXT(z_arch_swap) diff --git a/arch/riscv/core/thread.c b/arch/riscv/core/thread.c index db5a2977f41..f9bcc4813c4 100644 --- a/arch/riscv/core/thread.c +++ b/arch/riscv/core/thread.c @@ -5,10 +5,7 @@ */ #include -#include -#include -#include -#include +#include void z_thread_entry_wrapper(k_thread_entry_t thread, void *arg1, diff --git a/arch/riscv/include/kernel_arch_data.h b/arch/riscv/include/kernel_arch_data.h index a874d52aa9a..13f0d60dc17 100644 --- a/arch/riscv/include/kernel_arch_data.h +++ b/arch/riscv/include/kernel_arch_data.h @@ -18,14 +18,12 @@ #include #include #include -#include #ifndef _ASMLANGUAGE #include #include #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/arch/riscv/include/kernel_arch_func.h b/arch/riscv/include/kernel_arch_func.h index dfaa1cb3f3a..bca8f1d7959 100644 --- a/arch/riscv/include/kernel_arch_func.h +++ b/arch/riscv/include/kernel_arch_func.h @@ -15,7 +15,7 @@ #ifndef ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_FUNC_H_ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/arch/x86/core/CMakeLists.txt b/arch/x86/core/CMakeLists.txt index 36b6bcbc433..082ae37f5eb 100644 --- a/arch/x86/core/CMakeLists.txt +++ b/arch/x86/core/CMakeLists.txt @@ -19,6 +19,11 @@ zephyr_library_sources_if_kconfig(x86_mmu.c) zephyr_library_sources_ifdef(CONFIG_X86_VERY_EARLY_CONSOLE early_serial.c) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/x86/include +) + if(CONFIG_X86_64) include(intel64.cmake) else() diff --git a/arch/x86/core/ia32/excstub.S b/arch/x86/core/ia32/excstub.S index 15828dafeb7..4082abc4795 100644 --- a/arch/x86/core/ia32/excstub.S +++ b/arch/x86/core/ia32/excstub.S @@ -14,7 +14,6 @@ * and exiting a C exception handler. */ -#include #include #include /* For MK_ISR_NAME */ #include diff --git a/arch/x86/core/ia32/fatal.c b/arch/x86/core/ia32/fatal.c index b26a41d301b..e5ec4c3f1c7 100644 --- a/arch/x86/core/ia32/fatal.c +++ b/arch/x86/core/ia32/fatal.c @@ -9,11 +9,8 @@ * @brief Kernel fatal error handler */ -#include -#include - #include -#include +#include #include #include #include diff --git a/arch/x86/core/ia32/float.c b/arch/x86/core/ia32/float.c index 75741fb4604..23e7c0af773 100644 --- a/arch/x86/core/ia32/float.c +++ b/arch/x86/core/ia32/float.c @@ -43,8 +43,8 @@ * to enable FP register sharing on its behalf. */ -#include -#include +#include +#include /* SSE control/status register default value (used by assembler code) */ extern u32_t _sse_mxcsr_default_value; diff --git a/arch/x86/core/ia32/intstub.S b/arch/x86/core/ia32/intstub.S index 963a2e48e29..6ed8f597b5a 100644 --- a/arch/x86/core/ia32/intstub.S +++ b/arch/x86/core/ia32/intstub.S @@ -14,7 +14,6 @@ * entering and exiting a C interrupt handler. */ -#include #include #include #include diff --git a/arch/x86/core/ia32/swap.S b/arch/x86/core/ia32/swap.S index 20147af93f9..f37ff8c8702 100644 --- a/arch/x86/core/ia32/swap.S +++ b/arch/x86/core/ia32/swap.S @@ -11,8 +11,10 @@ * This module implements the z_arch_swap() routine for the IA-32 architecture. */ -#include #include +#include +#include +#include #include /* exports (internal APIs) */ diff --git a/arch/x86/core/ia32/thread.c b/arch/x86/core/ia32/thread.c index 890ea465b3d..711e253e8e8 100644 --- a/arch/x86/core/ia32/thread.c +++ b/arch/x86/core/ia32/thread.c @@ -12,12 +12,9 @@ * processor architecture. */ -#include -#include -#include -#include +#include +#include #include -#include /* forward declaration */ diff --git a/arch/x86/core/ia32/userspace.S b/arch/x86/core/ia32/userspace.S index ba6aced61f6..67dbd1c3d9c 100644 --- a/arch/x86/core/ia32/userspace.S +++ b/arch/x86/core/ia32/userspace.S @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include #include #include diff --git a/arch/x86/core/offsets/ia32_offsets.c b/arch/x86/core/offsets/ia32_offsets.c index fab6c7aed63..3ae3a09c691 100644 --- a/arch/x86/core/offsets/ia32_offsets.c +++ b/arch/x86/core/offsets/ia32_offsets.c @@ -26,8 +26,6 @@ #include -#include - #if defined(CONFIG_LAZY_FP_SHARING) GEN_OFFSET_SYM(_thread_arch_t, excNestCount); #endif diff --git a/arch/x86/core/offsets/intel64_offsets.c b/arch/x86/core/offsets/intel64_offsets.c index 7f60630257c..25ca8a96e28 100644 --- a/arch/x86/core/offsets/intel64_offsets.c +++ b/arch/x86/core/offsets/intel64_offsets.c @@ -3,10 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include - -#include - GEN_OFFSET_SYM(_callee_saved_t, rsp); GEN_OFFSET_SYM(_callee_saved_t, rbp); GEN_OFFSET_SYM(_callee_saved_t, rbx); diff --git a/arch/x86/core/offsets/offsets.c b/arch/x86/core/offsets/offsets.c index 355150762e8..5fd1d542606 100644 --- a/arch/x86/core/offsets/offsets.c +++ b/arch/x86/core/offsets/offsets.c @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include #include -#include +#include +#include #ifdef CONFIG_X86_64 #include "intel64_offsets.c" diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index f0026f850c6..ced015b3052 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include #include diff --git a/arch/x86/include/ia32/kernel_arch_data.h b/arch/x86/include/ia32/kernel_arch_data.h index 392cca1b18f..52a0b61199b 100644 --- a/arch/x86/include/ia32/kernel_arch_data.h +++ b/arch/x86/include/ia32/kernel_arch_data.h @@ -29,12 +29,10 @@ #include #include #include -#include #include #ifndef _ASMLANGUAGE #include -#include #include #include #endif diff --git a/arch/x86/include/intel64/kernel_arch_data.h b/arch/x86/include/intel64/kernel_arch_data.h index 02621446127..bfda15567e1 100644 --- a/arch/x86/include/intel64/kernel_arch_data.h +++ b/arch/x86/include/intel64/kernel_arch_data.h @@ -8,78 +8,12 @@ #include -/* - * Some SSE definitions. Ideally these will ultimately be shared with 32-bit. - */ - -#define X86_FXSAVE_SIZE 512 /* size and alignment of buffer ... */ -#define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */ -#define X86_MXCSR_SANE 0x1dc0 /* enable division-by-zero exception */ - -/* - * GDT selectors - these must agree with the GDT layout in locore.S. - */ - -#define X86_KERNEL_CS_32 0x08 /* 32-bit kernel code */ -#define X86_KERNEL_DS_32 0x10 /* 32-bit kernel data */ -#define X86_KERNEL_CS 0x18 /* 64-bit kernel code */ -#define X86_KERNEL_DS 0x20 /* 64-bit kernel data */ - -#define X86_KERNEL_CPU0_GS 0x30 /* data selector covering TSS */ -#define X86_KERNEL_CPU0_TR 0x40 /* 64-bit task state segment */ -#define X86_KERNEL_CPU1_GS 0x50 /* data selector covering TSS */ -#define X86_KERNEL_CPU1_TR 0x60 /* 64-bit task state segment */ -#define X86_KERNEL_CPU2_GS 0x70 /* data selector covering TSS */ -#define X86_KERNEL_CPU2_TR 0x80 /* 64-bit task state segment */ -#define X86_KERNEL_CPU3_GS 0x90 /* data selector covering TSS */ -#define X86_KERNEL_CPU3_TR 0xA0 /* 64-bit task state segment */ - #ifndef _ASMLANGUAGE /* linker symbols defining the bounds of the kernel part loaded in locore */ extern char _locore_start[], _locore_end[]; -/* - * 64-bit Task State Segment. One defined per CPU. - */ - -struct x86_tss64 { - /* - * Architecturally-defined portion. It is somewhat tedious to - * enumerate each member specifically (rather than using arrays) - * but we need to get (some of) their offsets from assembly. - */ - - u8_t reserved0[4]; - - u64_t rsp0; /* privileged stacks */ - u64_t rsp1; - u64_t rsp2; - - u8_t reserved[8]; - - u64_t ist1; /* interrupt stacks */ - u64_t ist2; - u64_t ist3; - u64_t ist4; - u64_t ist5; - u64_t ist6; - u64_t ist7; - - u8_t reserved1[10]; - - u16_t iomapb; /* offset to I/O base */ - - /* - * Zephyr specific portion. Stash per-CPU data here for convenience. - */ - - struct _cpu *cpu; -} __packed __aligned(8); - -typedef struct x86_tss64 x86_tss64_t; - /* * Per-CPU bootstrapping parameters. See locore.S and cpu.c. */ diff --git a/arch/x86/include/intel64/kernel_arch_func.h b/arch/x86/include/intel64/kernel_arch_func.h index 5b58cdd64fb..7c717fdc2a6 100644 --- a/arch/x86/include/intel64/kernel_arch_func.h +++ b/arch/x86/include/intel64/kernel_arch_func.h @@ -30,16 +30,6 @@ static inline void z_arch_kernel_init(void) /* nothing */; } -static inline struct _cpu *z_arch_curr_cpu(void) -{ - struct _cpu *cpu; - - __asm__ volatile("movq %%gs:(%c1), %0" - : "=r" (cpu) - : "i" (offsetof(x86_tss64_t, cpu))); - - return cpu; -} #endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_ */ diff --git a/arch/x86/include/intel64/kernel_arch_thread.h b/arch/x86/include/intel64/kernel_arch_thread.h deleted file mode 100644 index a087d0d502f..00000000000 --- a/arch/x86/include/intel64/kernel_arch_thread.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2019 Intel Corporation - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ - -#define X86_THREAD_FLAG_ALL 0x01 /* _thread_arch.flags: entire state saved */ - -#ifndef _ASMLANGUAGE - -#include -#include - -/* - * The _callee_saved registers are unconditionally saved/restored across - * context switches; the _thread_arch registers are only preserved when - * the thread is interrupted. _arch_thread.flags tells __resume when to - * cheat and only restore the first set. For more details see locore.S. - */ - -struct _callee_saved { - u64_t rsp; - u64_t rbx; - u64_t rbp; - u64_t r12; - u64_t r13; - u64_t r14; - u64_t r15; - u64_t rip; - u64_t rflags; -}; - -typedef struct _callee_saved _callee_saved_t; - -struct _thread_arch { - u8_t flags; - - u64_t rax; - u64_t rcx; - u64_t rdx; - u64_t rsi; - u64_t rdi; - u64_t r8; - u64_t r9; - u64_t r10; - u64_t r11; - char __aligned(X86_FXSAVE_ALIGN) sse[X86_FXSAVE_SIZE]; -}; - -typedef struct _thread_arch _thread_arch_t; - -#endif /* _ASMLANGUAGE */ - -#endif /* ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_THREAD_H_ */ diff --git a/arch/x86/include/kernel_arch_func.h b/arch/x86/include/kernel_arch_func.h index 86e72a0e434..6c69e471c66 100644 --- a/arch/x86/include/kernel_arch_func.h +++ b/arch/x86/include/kernel_arch_func.h @@ -6,6 +6,8 @@ #ifndef ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_FUNC_H_ +#include + #ifdef CONFIG_X86_64 #include #else diff --git a/arch/x86/include/kernel_arch_thread.h b/arch/x86/include/kernel_arch_thread.h deleted file mode 100644 index d85bb82e2b3..00000000000 --- a/arch/x86/include/kernel_arch_thread.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2019 Intel Corporation - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_THREAD_H_ - -#ifdef CONFIG_X86_64 -#include -#else -#include -#endif - -#endif /* ZEPHYR_ARCH_X86_INCLUDE_KERNEL_ARCH_THREAD_H_ */ diff --git a/arch/xtensa/core/CMakeLists.txt b/arch/xtensa/core/CMakeLists.txt index 62fcc2445dc..b19b30c9f9b 100644 --- a/arch/xtensa/core/CMakeLists.txt +++ b/arch/xtensa/core/CMakeLists.txt @@ -1,19 +1,24 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_cc_option(-mlongcalls) -zephyr_sources( - cpu_idle.c - fatal.c - window_vectors.S - xtensa-asm2-util.S - xtensa-asm2.c - ) -zephyr_sources_ifndef(CONFIG_ATOMIC_OPERATIONS_C atomic.S) -zephyr_sources_ifdef(CONFIG_XTENSA_USE_CORE_CRT1 - crt1.S -) -zephyr_sources_ifdef(CONFIG_IRQ_OFFLOAD - irq_offload.c -) +zephyr_library() + +zephyr_library_sources( + cpu_idle.c + fatal.c + window_vectors.S + xtensa-asm2-util.S + xtensa-asm2.c + ) + +zephyr_library_sources_ifndef(CONFIG_ATOMIC_OPERATIONS_C atomic.S) +zephyr_library_sources_ifdef(CONFIG_XTENSA_USE_CORE_CRT1 crt1.S) +zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/xtensa/include + ) + add_subdirectory(startup) diff --git a/arch/xtensa/core/atomic.S b/arch/xtensa/core/atomic.S index 20b51078783..ff93314cb67 100644 --- a/arch/xtensa/core/atomic.S +++ b/arch/xtensa/core/atomic.S @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include /** * * @brief Atomically clear a memory location diff --git a/arch/xtensa/core/crt1.S b/arch/xtensa/core/crt1.S index c4b27198903..bebecd752da 100644 --- a/arch/xtensa/core/crt1.S +++ b/arch/xtensa/core/crt1.S @@ -7,7 +7,7 @@ * Control arrives here at _start from the reset vector or from crt0-app.S. */ -#include +#include /* Exports */ .global _start diff --git a/arch/xtensa/core/irq_offload.c b/arch/xtensa/core/irq_offload.c index a0a0059b5d8..981e70d74e1 100644 --- a/arch/xtensa/core/irq_offload.c +++ b/arch/xtensa/core/irq_offload.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include /* * Xtensa core should support software interrupt in order to allow using diff --git a/arch/xtensa/core/offsets/offsets.c b/arch/xtensa/core/offsets/offsets.c index 8ff8ce3241b..ee78f56723a 100644 --- a/arch/xtensa/core/offsets/offsets.c +++ b/arch/xtensa/core/offsets/offsets.c @@ -23,12 +23,9 @@ * completeness. */ -#include /* located in kernel/arch/common/include */ - -/* list of headers that define whose structure offsets will be generated */ - -#include - +#include +#include +#include #include /* Xtensa-specific k_thread structure member offsets */ diff --git a/arch/xtensa/core/startup/CMakeLists.txt b/arch/xtensa/core/startup/CMakeLists.txt index c3283d90064..d6595f5cb33 100644 --- a/arch/xtensa/core/startup/CMakeLists.txt +++ b/arch/xtensa/core/startup/CMakeLists.txt @@ -10,8 +10,13 @@ if(CONFIG_XTENSA_RESET_VECTOR) ) zephyr_library_sources( - reset-vector.S - memerror-vector.S - memctl_default.S + reset-vector.S + memerror-vector.S + memctl_default.S + ) + + zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/xtensa/include ) endif() diff --git a/arch/xtensa/core/window_vectors.S b/arch/xtensa/core/window_vectors.S index 44a9bfb393a..5423cbaface 100644 --- a/arch/xtensa/core/window_vectors.S +++ b/arch/xtensa/core/window_vectors.S @@ -2,7 +2,7 @@ * Copyright (c) 2016 Cadence Design Systems, Inc. * SPDX-License-Identifier: Apache-2.0 */ -#include "xtensa_rtos.h" +#include /* WINDOW OVERFLOW AND UNDERFLOW EXCEPTION VECTORS AND ALLOCA EXCEPTION * HANDLER diff --git a/arch/xtensa/include/kernel_arch_data.h b/arch/xtensa/include/kernel_arch_data.h index e0de40e2f4b..3a403342259 100644 --- a/arch/xtensa/include/kernel_arch_data.h +++ b/arch/xtensa/include/kernel_arch_data.h @@ -23,7 +23,6 @@ #include #include #include -#include /* stacks */ #define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) @@ -31,7 +30,6 @@ #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) #include /* public kernel API */ -#include #include #include #include diff --git a/arch/xtensa/include/kernel_arch_func.h b/arch/xtensa/include/kernel_arch_func.h index ac52eb98914..71762205841 100644 --- a/arch/xtensa/include/kernel_arch_func.h +++ b/arch/xtensa/include/kernel_arch_func.h @@ -10,9 +10,8 @@ #define ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_FUNC_H_ #ifndef _ASMLANGUAGE +#include #include -#include -#include /* For size_t */ #ifdef __cplusplus extern "C" { @@ -23,16 +22,6 @@ extern "C" { #define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE) #define STACK_ROUND_DOWN(x) ROUND_DOWN(x, STACK_ALIGN_SIZE) -#define RSR(sr) \ - ({u32_t v; \ - __asm__ volatile ("rsr." sr " %0" : "=a"(v)); \ - v; }) - -#define WSR(sr, v) \ - do { \ - __asm__ volatile ("wsr." sr " %0" : : "r"(v)); \ - } while (false) - extern void FatalErrorHandler(void); extern void ReservedInterruptHandler(unsigned int intNo); extern void z_xtensa_fatal_error(unsigned int reason, const z_arch_esf_t *esf); @@ -42,15 +31,6 @@ extern void z_xt_coproc_init(void); extern K_THREAD_STACK_DEFINE(_interrupt_stack, CONFIG_ISR_STACK_SIZE); -static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void) -{ - void *val; - - val = (void *)RSR(CONFIG_XTENSA_KERNEL_CPU_PTR_SR); - - return val; -} - static ALWAYS_INLINE void z_arch_kernel_init(void) { _cpu_t *cpu0 = &_kernel.cpus[0]; diff --git a/boards/posix/native_posix/CMakeLists.txt b/boards/posix/native_posix/CMakeLists.txt index 39ea2f13563..5fa77d6ca54 100644 --- a/boards/posix/native_posix/CMakeLists.txt +++ b/boards/posix/native_posix/CMakeLists.txt @@ -1,7 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() + zephyr_library_compile_definitions(NO_POSIX_CHEATS) + zephyr_library_sources( hw_models_top.c timer_model.c @@ -14,6 +16,11 @@ zephyr_library_sources( cmdline.c ) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/posix/include + ) + if(CONFIG_HAS_SDL) find_package(PkgConfig REQUIRED) pkg_search_module(SDL2 REQUIRED sdl2) diff --git a/boards/posix/native_posix/cmdline.c b/boards/posix/native_posix/cmdline.c index 67db127051c..a56cc788769 100644 --- a/boards/posix/native_posix/cmdline.c +++ b/boards/posix/native_posix/cmdline.c @@ -13,7 +13,7 @@ #include "timer_model.h" #include "cmdline.h" #include "toolchain.h" -#include "posix_trace.h" +#include #include "native_tracing.h" static int s_argc, test_argc; diff --git a/boards/posix/native_posix/cmdline_common.c b/boards/posix/native_posix/cmdline_common.c index 00df76f8c15..2f2cf587901 100644 --- a/boards/posix/native_posix/cmdline_common.c +++ b/boards/posix/native_posix/cmdline_common.c @@ -10,7 +10,7 @@ #include #include #include -#include "posix_trace.h" +#include #include "posix_board_if.h" #include "zephyr/types.h" #include "cmdline_common.h" diff --git a/boards/posix/native_posix/hw_models_top.c b/boards/posix/native_posix/hw_models_top.c index 7e156434b9e..30d7c152e6b 100644 --- a/boards/posix/native_posix/hw_models_top.c +++ b/boards/posix/native_posix/hw_models_top.c @@ -18,7 +18,7 @@ #include "timer_model.h" #include "irq_ctrl.h" #include "posix_board_if.h" -#include "posix_soc_if.h" +#include #include "posix_arch_internal.h" #include "sdl_events.h" #include diff --git a/boards/posix/native_posix/native_rtc.c b/boards/posix/native_posix/native_rtc.c index ff2dedb9b47..7715e3b8359 100644 --- a/boards/posix/native_posix/native_rtc.c +++ b/boards/posix/native_posix/native_rtc.c @@ -11,7 +11,7 @@ #include "native_rtc.h" #include "hw_models_top.h" #include "timer_model.h" -#include "posix_trace.h" +#include /** * Return the (simulation) time in microseconds diff --git a/boards/posix/native_posix/sdl_events.c b/boards/posix/native_posix/sdl_events.c index 7e8381d13cd..8b2511e01d7 100644 --- a/boards/posix/native_posix/sdl_events.c +++ b/boards/posix/native_posix/sdl_events.c @@ -6,7 +6,7 @@ #include #include "posix_board_if.h" -#include "posix_trace.h" +#include #include "posix_arch_internal.h" #include "soc.h" #include "hw_models_top.h" diff --git a/boards/posix/native_posix/timer_model.c b/boards/posix/native_posix/timer_model.c index 55dbee24f97..aa97dde7ff8 100644 --- a/boards/posix/native_posix/timer_model.c +++ b/boards/posix/native_posix/timer_model.c @@ -26,7 +26,7 @@ #include "irq_ctrl.h" #include "board_soc.h" #include "zephyr/types.h" -#include "posix_trace.h" +#include #include #include "cmdline.h" #include "soc.h" diff --git a/boards/posix/nrf52_bsim/CMakeLists.txt b/boards/posix/nrf52_bsim/CMakeLists.txt index 37e2b8f6853..b2bc60c4b9a 100644 --- a/boards/posix/nrf52_bsim/CMakeLists.txt +++ b/boards/posix/nrf52_bsim/CMakeLists.txt @@ -88,6 +88,8 @@ zephyr_library_include_directories( $ENV{BSIM_COMPONENTS_PATH}/ext_NRF52_hw_models/src/HW_models/ $ENV{BSIM_COMPONENTS_PATH}/ext_NRF52_hw_models/src/nrfx_hal/ $ENV{BSIM_COMPONENTS_PATH}/libRandv2/src/ + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/posix/include ) zephyr_ld_options( diff --git a/boards/posix/nrf52_bsim/k_busy_wait.c b/boards/posix/nrf52_bsim/k_busy_wait.c index 8e43ed777e3..2787a5f592d 100644 --- a/boards/posix/nrf52_bsim/k_busy_wait.c +++ b/boards/posix/nrf52_bsim/k_busy_wait.c @@ -6,7 +6,7 @@ #include "zephyr/types.h" #include "fake_timer.h" #include "time_machine.h" -#include "posix_soc_if.h" +#include #if defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) /** diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index f96408f6242..f553313a5be 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -1148,6 +1148,12 @@ function(zephyr_library_sources_ifdef feature_toggle source) endif() endfunction() +function(zephyr_library_sources_ifndef feature_toggle source) + if(NOT ${feature_toggle}) + zephyr_library_sources(${source} ${ARGN}) + endif() +endfunction() + function(zephyr_sources_ifdef feature_toggle) if(${${feature_toggle}}) zephyr_sources(${ARGN}) diff --git a/drivers/entropy/fake_entropy_native_posix.c b/drivers/entropy/fake_entropy_native_posix.c index ef1c0088131..5b4a6ab100d 100644 --- a/drivers/entropy/fake_entropy_native_posix.c +++ b/drivers/entropy/fake_entropy_native_posix.c @@ -17,7 +17,7 @@ #include #include #include -#include "posix_trace.h" +#include #include "soc.h" #include "cmdline.h" /* native_posix command line options header */ diff --git a/drivers/ethernet/eth_native_posix_adapt.c b/drivers/ethernet/eth_native_posix_adapt.c index b34174ba0a2..996b3fff6fd 100644 --- a/drivers/ethernet/eth_native_posix_adapt.c +++ b/drivers/ethernet/eth_native_posix_adapt.c @@ -25,7 +25,7 @@ #include #include #include -#include "posix_trace.h" +#include #ifdef __linux #include diff --git a/drivers/timer/native_posix_timer.c b/drivers/timer/native_posix_timer.c index e730c114be8..2bb1e5d59c6 100644 --- a/drivers/timer/native_posix_timer.c +++ b/drivers/timer/native_posix_timer.c @@ -17,7 +17,7 @@ #include "sys_clock.h" #include "timer_model.h" #include "soc.h" -#include "posix_trace.h" +#include static u64_t tick_period; /* System tick period in microseconds */ /* Time (microseconds since boot) of the last timer tick interrupt */ diff --git a/drivers/timer/xtensa_sys_timer.c b/drivers/timer/xtensa_sys_timer.c index b0fe417faf9..977336cc18f 100644 --- a/drivers/timer/xtensa_sys_timer.c +++ b/drivers/timer/xtensa_sys_timer.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #define TIMER_IRQ UTIL_CAT(XCHAL_TIMER, \ UTIL_CAT(CONFIG_XTENSA_TIMER_ID, _INTERRUPT)) diff --git a/include/arch/arc/arch.h b/include/arch/arc/arch.h index 71f61c3b491..c116eb7bd36 100644 --- a/include/arch/arc/arch.h +++ b/include/arch/arc/arch.h @@ -18,6 +18,7 @@ #include #include +#include #ifdef CONFIG_CPU_ARCV2 #include #include diff --git a/include/arch/arc/arch_inlines.h b/include/arch/arc/arch_inlines.h new file mode 100644 index 00000000000..316507ca9db --- /dev/null +++ b/include/arch/arc/arch_inlines.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014-2016 Wind River Systems, Inc. + * Copyright (c) 2019 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ +#define ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ + +#ifndef _ASMLANGUAGE + +#include + +#ifdef CONFIG_CPU_ARCV2 +#include +#endif + +static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void) +{ +#ifdef CONFIG_SMP + u32_t core; + + core = z_arc_v2_core_id(); + + return &_kernel.cpus[core]; +#else + return &_kernel.cpus[0]; +#endif /* CONFIG_SMP */ +} + +#endif /* !_ASMLANGUAGE */ +#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ */ diff --git a/arch/arc/include/kernel_arch_thread.h b/include/arch/arc/thread.h similarity index 87% rename from arch/arc/include/kernel_arch_thread.h rename to include/arch/arc/thread.h index 1406b84d101..c2945cf6a31 100644 --- a/arch/arc/include/kernel_arch_thread.h +++ b/include/arch/arc/thread.h @@ -16,8 +16,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARC_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_ARC_THREAD_H_ /* * Reason a thread has relinquished control. @@ -70,4 +70,4 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARC_THREAD_H_ */ diff --git a/include/arch/arch_inlines.h b/include/arch/arch_inlines.h new file mode 100644 index 00000000000..4277f94fcec --- /dev/null +++ b/include/arch/arch_inlines.h @@ -0,0 +1,23 @@ +/* + * arch_inlines.h - automatically selects the correct arch_inlines.h file to + * include based on the selected architecture. + */ + +/* + * Copyright (c) 2019 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_INLINES_H_ +#define ZEPHYR_INCLUDE_ARCH_INLINES_H_ + +#if defined(CONFIG_X86) || defined(CONFIG_X86_64) +#include +#elif defined(CONFIG_ARC) +#include +#elif defined(CONFIG_XTENSA) +#include +#endif + +#endif /* ZEPHYR_INCLUDE_ARCH_INLINES_H_ */ diff --git a/include/arch/arm/arch.h b/include/arch/arm/arch.h index 8e19fe8524e..04bd26f144a 100644 --- a/include/arch/arm/arch.h +++ b/include/arch/arm/arch.h @@ -22,6 +22,7 @@ /* ARM GPRs are often designated by two different names */ #define sys_define_gpr_with_alias(name1, name2) union { u32_t name1, name2; } +#include #include #include #include diff --git a/include/arch/arm/asm_inline.h b/include/arch/arm/asm_inline.h index 1ddc49b6d56..f6e943dd72f 100644 --- a/include/arch/arm/asm_inline.h +++ b/include/arch/arm/asm_inline.h @@ -6,8 +6,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_H_ /* * The file must not be included directly @@ -20,4 +20,4 @@ #include #endif -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_H_ */ diff --git a/include/arch/arm/asm_inline_gcc.h b/include/arch/arm/asm_inline_gcc.h index 839777904d0..460849fd78d 100644 --- a/include/arch/arm/asm_inline_gcc.h +++ b/include/arch/arm/asm_inline_gcc.h @@ -8,8 +8,8 @@ /* Either public functions or macros or invoked by public functions */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_GCC_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_GCC_H_ /* * The file must not be included directly @@ -112,4 +112,4 @@ static ALWAYS_INLINE bool z_arch_irq_unlocked(unsigned int key) #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ASM_INLINE_GCC_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_ASM_INLINE_GCC_H_ */ diff --git a/include/arch/arm/error.h b/include/arch/arm/error.h index 71c8f7d575c..4017369524a 100644 --- a/include/arch/arm/error.h +++ b/include/arch/arm/error.h @@ -11,8 +11,8 @@ * ARM-specific kernel error handling interface. Included by arm/arch.h. */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ERROR_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ERROR_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_ #include #include @@ -62,4 +62,4 @@ do { \ } #endif -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_ERROR_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_ERROR_H_ */ diff --git a/include/arch/arm/exc.h b/include/arch/arm/exc.h index 2903e2e1422..cec89492c0e 100644 --- a/include/arch/arm/exc.h +++ b/include/arch/arm/exc.h @@ -11,8 +11,8 @@ * ARM-specific kernel exception handling interface. Included by arm/arch.h. */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_EXC_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_EXC_H_ /* for assembler, only works with constants */ #define Z_EXC_PRIO(pri) (((pri) << (8 - DT_NUM_IRQ_PRIO_BITS)) & 0xff) @@ -72,4 +72,4 @@ extern void z_arm_exc_exit(void); #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_EXC_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_EXC_H_ */ diff --git a/include/arch/arm/irq.h b/include/arch/arm/irq.h index 3ef252ba674..c698b222d32 100644 --- a/include/arch/arm/irq.h +++ b/include/arch/arm/irq.h @@ -11,8 +11,8 @@ * ARM-specific kernel interrupt handling interface. Included by arm/arch.h. */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_IRQ_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_IRQ_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_IRQ_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_IRQ_H_ #include #include @@ -149,4 +149,4 @@ extern void _isr_wrapper(void); } #endif -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_IRQ_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_IRQ_H_ */ diff --git a/include/arch/arm/misc.h b/include/arch/arm/misc.h index 4f2911d4483..47f051cf4c2 100644 --- a/include/arch/arm/misc.h +++ b/include/arch/arm/misc.h @@ -11,8 +11,8 @@ * ARM-specific kernel miscellaneous interface. Included by arm/arch.h. */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_MISC_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_MISC_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_MISC_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_MISC_H_ #ifdef __cplusplus extern "C" { @@ -37,4 +37,4 @@ static ALWAYS_INLINE void z_arch_nop(void) } #endif -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_MISC_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_MISC_H_ */ diff --git a/include/arch/arm/nmi.h b/include/arch/arm/nmi.h index 7d7945fe3b1..00ed6718610 100644 --- a/include/arch/arm/nmi.h +++ b/include/arch/arm/nmi.h @@ -10,8 +10,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_NMI_H_ -#define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_NMI_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_NMI_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_NMI_H_ #ifndef _ASMLANGUAGE #ifdef CONFIG_RUNTIME_NMI @@ -22,4 +22,4 @@ extern void z_arm_nmi_init(void); #endif #endif -#endif /* ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_NMI_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_NMI_H_ */ diff --git a/arch/arm/include/kernel_arch_thread.h b/include/arch/arm/thread.h similarity index 92% rename from arch/arm/include/kernel_arch_thread.h rename to include/arch/arm/thread.h index a359e8f816f..8ab66cb27a9 100644 --- a/arch/arm/include/kernel_arch_thread.h +++ b/include/arch/arm/thread.h @@ -16,8 +16,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_ #ifndef _ASMLANGUAGE #include @@ -92,4 +92,4 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* _kernel_arch_thread__h_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_ARM_THREAD_H_ */ diff --git a/include/arch/cpu.h b/include/arch/cpu.h index cac26937cb6..0b75d325f0f 100644 --- a/include/arch/cpu.h +++ b/include/arch/cpu.h @@ -9,7 +9,7 @@ #ifndef ZEPHYR_INCLUDE_ARCH_CPU_H_ #define ZEPHYR_INCLUDE_ARCH_CPU_H_ -#include +#include #if defined(CONFIG_X86) #include diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index 0ff924401df..f5fdaf4442a 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -15,10 +15,12 @@ #define ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_ #include + +#include #include #include #include -#include "nios2.h" +#include #include #include diff --git a/arch/nios2/include/kernel_arch_thread.h b/include/arch/nios2/thread.h similarity index 85% rename from arch/nios2/include/kernel_arch_thread.h rename to include/arch/nios2/thread.h index 975b66c2a42..c101c269104 100644 --- a/arch/nios2/include/kernel_arch_thread.h +++ b/include/arch/nios2/thread.h @@ -16,8 +16,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_NIOS2_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_NIOS2_THREAD_H_ #ifndef _ASMLANGUAGE #include @@ -61,5 +61,5 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_NIOS2_INCLUDE_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_NIOS2_THREAD_H_ */ diff --git a/include/arch/posix/arch.h b/include/arch/posix/arch.h index 3ccf26cfc66..245e0490329 100644 --- a/include/arch/posix/arch.h +++ b/include/arch/posix/arch.h @@ -23,9 +23,10 @@ #include #include #include +#include #include /* Each board must define this */ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/include/arch/posix/asm_inline_gcc.h b/include/arch/posix/asm_inline_gcc.h index eb863524728..1853bb6d608 100644 --- a/include/arch/posix/asm_inline_gcc.h +++ b/include/arch/posix/asm_inline_gcc.h @@ -25,7 +25,7 @@ #include #include #include -#include "posix_soc_if.h" +#include #endif /* _ASMLANGUAGE */ diff --git a/arch/posix/include/posix_soc_if.h b/include/arch/posix/posix_soc_if.h similarity index 82% rename from arch/posix/include/posix_soc_if.h rename to include/arch/posix/posix_soc_if.h index 0dede34e8e6..d1fd2ea586a 100644 --- a/arch/posix/include/posix_soc_if.h +++ b/include/arch/posix/posix_soc_if.h @@ -3,8 +3,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_ARCH_POSIX_INCLUDE_POSIX_SOC_IF_H_ -#define ZEPHYR_ARCH_POSIX_INCLUDE_POSIX_SOC_IF_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_POSIX_POSIX_SOC_IF_H_ +#define ZEPHYR_INCLUDE_ARCH_POSIX_POSIX_SOC_IF_H_ /* * This file lists the functions the POSIX architecture core expects the @@ -14,7 +14,7 @@ * or all its boards */ -#include "posix_trace.h" +#include #include "soc_irq.h" /* Must exist and define _ARCH_IRQ/ISR_* macros */ #ifdef __cplusplus @@ -39,4 +39,4 @@ void posix_irq_offload(void (*routine)(void *), void *parameter); } #endif -#endif /* ZEPHYR_ARCH_POSIX_INCLUDE_POSIX_SOC_IF_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_POSIX_POSIX_SOC_IF_H_ */ diff --git a/arch/posix/include/posix_trace.h b/include/arch/posix/posix_trace.h similarity index 88% rename from arch/posix/include/posix_trace.h rename to include/arch/posix/posix_trace.h index ae160b0d705..76432e71a60 100644 --- a/arch/posix/include/posix_trace.h +++ b/include/arch/posix/posix_trace.h @@ -3,8 +3,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_ARCH_POSIX_INCLUDE_POSIX_TRACE_H_ -#define ZEPHYR_ARCH_POSIX_INCLUDE_POSIX_TRACE_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_POSIX_POSIX_TRACE_H_ +#define ZEPHYR_INCLUDE_ARCH_POSIX_POSIX_TRACE_H_ #ifdef __cplusplus extern "C" { @@ -13,7 +13,7 @@ extern "C" { void posix_print_error_and_exit(const char *format, ...); void posix_print_warning(const char *format, ...); void posix_print_trace(const char *format, ...); -/** +/* * Return 1 if traces to will go to a tty. * When printing to a terminal we may use ASCII escapes for color or other * niceties. diff --git a/arch/posix/include/kernel_arch_thread.h b/include/arch/posix/thread.h similarity index 81% rename from arch/posix/include/kernel_arch_thread.h rename to include/arch/posix/thread.h index d2dd95742e9..8c9f83240dd 100644 --- a/arch/posix/include/kernel_arch_thread.h +++ b/include/arch/posix/thread.h @@ -17,8 +17,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_POSIX_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_POSIX_THREAD_H_ #ifndef _ASMLANGUAGE #include @@ -52,4 +52,4 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_POSIX_INCLUDE_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_POSIX_THREAD_H_ */ diff --git a/include/arch/riscv/arch.h b/include/arch/riscv/arch.h index 90db6e75a58..b841a85d6c5 100644 --- a/include/arch/riscv/arch.h +++ b/include/arch/riscv/arch.h @@ -15,7 +15,8 @@ #ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_ #define ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_ -#include "exp.h" +#include +#include #include #include diff --git a/arch/riscv/include/kernel_arch_thread.h b/include/arch/riscv/thread.h similarity index 87% rename from arch/riscv/include/kernel_arch_thread.h rename to include/arch/riscv/thread.h index b73a4062fe9..02fe6354424 100644 --- a/arch/riscv/include/kernel_arch_thread.h +++ b/include/arch/riscv/thread.h @@ -16,8 +16,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_RISCV_THREAD_H_ #ifndef _ASMLANGUAGE #include @@ -52,4 +52,4 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_RISCV_INCLUDE_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_THREAD_H_ */ diff --git a/include/arch/x86/arch_inlines.h b/include/arch/x86/arch_inlines.h new file mode 100644 index 00000000000..3b60dd35733 --- /dev/null +++ b/include/arch/x86/arch_inlines.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019 Intel Corporation + * Copyright (c) 2019 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_X86_ARCH_INLINES_H_ +#define ZEPHYR_INCLUDE_ARCH_X86_ARCH_INLINES_H_ + +#ifndef _ASMLANGUAGE + +#if defined(CONFIG_X86_64) + +#include +#include + +static inline struct _cpu *z_arch_curr_cpu(void) +{ + struct _cpu *cpu; + + __asm__ volatile("movq %%gs:(%c1), %0" + : "=r" (cpu) + : "i" (offsetof(x86_tss64_t, cpu))); + + return cpu; +} + +#endif /* CONFIG_X86_64 */ + +#endif /* !_ASMLANGUAGE */ + +#endif /* ZEPHYR_INCLUDE_ARCH_X86_ARCH_INLINES_H_ */ diff --git a/include/arch/x86/ia32/arch.h b/include/arch/x86/ia32/arch.h index f65c593089f..c3abeedd16e 100644 --- a/include/arch/x86/ia32/arch.h +++ b/include/arch/x86/ia32/arch.h @@ -16,10 +16,10 @@ #include "sys_io.h" #include -#include #include #include #include +#include #include #ifndef _ASMLANGUAGE diff --git a/arch/x86/include/ia32/kernel_arch_thread.h b/include/arch/x86/ia32/thread.h similarity index 97% rename from arch/x86/include/ia32/kernel_arch_thread.h rename to include/arch/x86/ia32/thread.h index a93a5699153..23e74070a79 100644 --- a/arch/x86/include/ia32/kernel_arch_thread.h +++ b/include/arch/x86/ia32/thread.h @@ -16,8 +16,8 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_ /** * Floating point register set alignment. @@ -237,4 +237,4 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_X86_INCLUDE_IA32_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_X86_IA32_THREAD_H_ */ diff --git a/include/arch/x86/intel64/arch.h b/include/arch/x86/intel64/arch.h index 189d1e23e7f..6cbe8f85193 100644 --- a/include/arch/x86/intel64/arch.h +++ b/include/arch/x86/intel64/arch.h @@ -6,7 +6,7 @@ #ifndef ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_ #define ZEPHYR_INCLUDE_ARCH_X86_INTEL64_ARCH_H_ -#include +#include #define STACK_ALIGN 16 #define STACK_SIZE_ALIGN 16 diff --git a/include/arch/x86/intel64/thread.h b/include/arch/x86/intel64/thread.h new file mode 100644 index 00000000000..f1bc66dfc12 --- /dev/null +++ b/include/arch/x86/intel64/thread.h @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2019 Intel Corporation + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_ + +#define X86_THREAD_FLAG_ALL 0x01 /* _thread_arch.flags: entire state saved */ + +/* + * GDT selectors - these must agree with the GDT layout in locore.S. + */ + +#define X86_KERNEL_CS_32 0x08 /* 32-bit kernel code */ +#define X86_KERNEL_DS_32 0x10 /* 32-bit kernel data */ +#define X86_KERNEL_CS 0x18 /* 64-bit kernel code */ +#define X86_KERNEL_DS 0x20 /* 64-bit kernel data */ + +#define X86_KERNEL_CPU0_GS 0x30 /* data selector covering TSS */ +#define X86_KERNEL_CPU0_TR 0x40 /* 64-bit task state segment */ +#define X86_KERNEL_CPU1_GS 0x50 /* data selector covering TSS */ +#define X86_KERNEL_CPU1_TR 0x60 /* 64-bit task state segment */ +#define X86_KERNEL_CPU2_GS 0x70 /* data selector covering TSS */ +#define X86_KERNEL_CPU2_TR 0x80 /* 64-bit task state segment */ +#define X86_KERNEL_CPU3_GS 0x90 /* data selector covering TSS */ +#define X86_KERNEL_CPU3_TR 0xA0 /* 64-bit task state segment */ + +/* + * Some SSE definitions. Ideally these will ultimately be shared with 32-bit. + */ + +#define X86_FXSAVE_SIZE 512 /* size and alignment of buffer ... */ +#define X86_FXSAVE_ALIGN 16 /* ... for FXSAVE/FXRSTOR ops */ +#define X86_MXCSR_SANE 0x1dc0 /* enable division-by-zero exception */ + +#ifndef _ASMLANGUAGE + +#include + +/* + * 64-bit Task State Segment. One defined per CPU. + */ + +struct x86_tss64 { + /* + * Architecturally-defined portion. It is somewhat tedious to + * enumerate each member specifically (rather than using arrays) + * but we need to get (some of) their offsets from assembly. + */ + + u8_t reserved0[4]; + + u64_t rsp0; /* privileged stacks */ + u64_t rsp1; + u64_t rsp2; + + u8_t reserved[8]; + + u64_t ist1; /* interrupt stacks */ + u64_t ist2; + u64_t ist3; + u64_t ist4; + u64_t ist5; + u64_t ist6; + u64_t ist7; + + u8_t reserved1[10]; + + u16_t iomapb; /* offset to I/O base */ + + /* + * Zephyr specific portion. Stash per-CPU data here for convenience. + */ + + struct _cpu *cpu; +} __packed __aligned(8); + +typedef struct x86_tss64 x86_tss64_t; + +/* + * The _callee_saved registers are unconditionally saved/restored across + * context switches; the _thread_arch registers are only preserved when + * the thread is interrupted. _arch_thread.flags tells __resume when to + * cheat and only restore the first set. For more details see locore.S. + */ + +struct _callee_saved { + u64_t rsp; + u64_t rbx; + u64_t rbp; + u64_t r12; + u64_t r13; + u64_t r14; + u64_t r15; + u64_t rip; + u64_t rflags; +}; + +typedef struct _callee_saved _callee_saved_t; + +struct _thread_arch { + u8_t flags; + + u64_t rax; + u64_t rcx; + u64_t rdx; + u64_t rsi; + u64_t rdi; + u64_t r8; + u64_t r9; + u64_t r10; + u64_t r11; + char __aligned(X86_FXSAVE_ALIGN) sse[X86_FXSAVE_SIZE]; +}; + +typedef struct _thread_arch _thread_arch_t; + +#endif /* _ASMLANGUAGE */ + +#endif /* ZEPHYR_INCLUDE_ARCH_X86_INTEL64_THREAD_H_ */ diff --git a/include/arch/xtensa/arch.h b/include/arch/xtensa/arch.h index 49e14089e30..4b2896fafe5 100644 --- a/include/arch/xtensa/arch.h +++ b/include/arch/xtensa/arch.h @@ -17,10 +17,11 @@ #include #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) +#include #include #include -#include #include +#include #include #include #include diff --git a/include/arch/xtensa/arch_inlines.h b/include/arch/xtensa/arch_inlines.h new file mode 100644 index 00000000000..d7bb0374a35 --- /dev/null +++ b/include/arch/xtensa/arch_inlines.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016 Cadence Design Systems, Inc. + * Copyright (c) 2019 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ +#define ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ + +#ifndef _ASMLANGUAGE + +#include + +#define RSR(sr) \ + ({u32_t v; \ + __asm__ volatile ("rsr." sr " %0" : "=a"(v)); \ + v; }) + +#define WSR(sr, v) \ + do { \ + __asm__ volatile ("wsr." sr " %0" : : "r"(v)); \ + } while (false) + +static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void) +{ + _cpu_t *cpu; + + cpu = (_cpu_t *)RSR(CONFIG_XTENSA_KERNEL_CPU_PTR_SR); + + return cpu; +} + +#endif /* !_ASMLANGUAGE */ + +#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ */ diff --git a/include/arch/xtensa/irq.h b/include/arch/xtensa/irq.h index 8c6b0130046..264eaf6b1f2 100644 --- a/include/arch/xtensa/irq.h +++ b/include/arch/xtensa/irq.h @@ -6,7 +6,7 @@ #ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_XTENSA_IRQ_H_ #define ZEPHYR_INCLUDE_ARCH_XTENSA_XTENSA_IRQ_H_ -#include +#include #include #define CONFIG_GEN_IRQ_START_VECTOR 0 diff --git a/arch/xtensa/include/kernel_arch_thread.h b/include/arch/xtensa/thread.h similarity index 94% rename from arch/xtensa/include/kernel_arch_thread.h rename to include/arch/xtensa/thread.h index dc2bb692e58..6e05dda0089 100644 --- a/arch/xtensa/include/kernel_arch_thread.h +++ b/include/arch/xtensa/thread.h @@ -16,12 +16,12 @@ * necessary to instantiate instances of struct k_thread. */ -#ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_THREAD_H_ -#define ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_THREAD_H_ +#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_THREAD_H_ +#define ZEPHYR_INCLUDE_ARCH_XTENSA_THREAD_H_ #ifndef _ASMLANGUAGE #include -#include +#include /* * The following structure defines the set of 'non-volatile' integer registers. @@ -112,5 +112,5 @@ typedef struct _thread_arch _thread_arch_t; #endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_KERNEL_ARCH_THREAD_H_ */ +#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_THREAD_H_ */ diff --git a/arch/xtensa/include/xtensa_api.h b/include/arch/xtensa/xtensa_api.h similarity index 100% rename from arch/xtensa/include/xtensa_api.h rename to include/arch/xtensa/xtensa_api.h diff --git a/arch/xtensa/include/xtensa_config.h b/include/arch/xtensa/xtensa_config.h similarity index 100% rename from arch/xtensa/include/xtensa_config.h rename to include/arch/xtensa/xtensa_config.h diff --git a/arch/xtensa/include/xtensa_context.h b/include/arch/xtensa/xtensa_context.h similarity index 100% rename from arch/xtensa/include/xtensa_context.h rename to include/arch/xtensa/xtensa_context.h diff --git a/arch/xtensa/include/xtensa_rtos.h b/include/arch/xtensa/xtensa_rtos.h similarity index 100% rename from arch/xtensa/include/xtensa_rtos.h rename to include/arch/xtensa/xtensa_rtos.h diff --git a/arch/xtensa/include/xtensa_timer.h b/include/arch/xtensa/xtensa_timer.h similarity index 100% rename from arch/xtensa/include/xtensa_timer.h rename to include/arch/xtensa/xtensa_timer.h diff --git a/include/kernel.h b/include/kernel.h index 60107005405..959a05cb232 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -4841,6 +4841,13 @@ extern void z_sys_power_save_idle_exit(s32_t ticks); * private APIs that are utilized by one or more public APIs */ +/** + * @internal + */ +extern void z_init_thread_base(struct _thread_base *thread_base, + int priority, u32_t initial_state, + unsigned int options); + #ifdef CONFIG_MULTITHREADING /** * @internal diff --git a/include/kernel_includes.h b/include/kernel_includes.h index f52a3728076..03e39b5791a 100644 --- a/include/kernel_includes.h +++ b/include/kernel_includes.h @@ -26,9 +26,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/kernel/include/kernel_structs.h b/include/kernel_structs.h similarity index 66% rename from kernel/include/kernel_structs.h rename to include/kernel_structs.h index 49b8f3d910e..59519723714 100644 --- a/kernel/include/kernel_structs.h +++ b/include/kernel_structs.h @@ -4,18 +4,27 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* + * The purpose of this file is to provide essential/minimal kernel structure + * definitions, so that they can be used without including kernel.h. + * + * The following rules must be observed: + * 1. kernel_structs.h shall not depend on kernel.h both directly and + * indirectly (i.e. it shall not include any header files that include + * kernel.h in their dependency chain). + * 2. kernel.h shall imply kernel_structs.h, such that it shall not be + * necessary to include kernel_structs.h explicitly when kernel.h is + * included. + */ + #ifndef ZEPHYR_KERNEL_INCLUDE_KERNEL_STRUCTS_H_ #define ZEPHYR_KERNEL_INCLUDE_KERNEL_STRUCTS_H_ -#include - #if !defined(_ASMLANGUAGE) -#include +#include +#include #include -#include #include -#include -#include #endif #define K_NUM_PRIORITIES \ @@ -66,8 +75,6 @@ /* highest value of _thread_base.preempt at which a thread is preemptible */ #define _PREEMPT_THRESHOLD (_NON_PREEMPT_THRESHOLD - 1) -#include - #if !defined(_ASMLANGUAGE) struct _ready_q { @@ -189,77 +196,6 @@ extern struct z_kernel _kernel; #define _timeout_q _kernel.timeout_q -#include - -#ifdef CONFIG_USE_SWITCH -/* This is a arch function traditionally, but when the switch-based - * z_swap() is in use it's a simple inline provided by the kernel. - */ -static ALWAYS_INLINE void -z_arch_thread_return_value_set(struct k_thread *thread, unsigned int value) -{ - thread->swap_retval = value; -} -#endif - -static ALWAYS_INLINE void -z_thread_return_value_set_with_data(struct k_thread *thread, - unsigned int value, - void *data) -{ - z_arch_thread_return_value_set(thread, value); - thread->base.swap_data = data; -} - -extern void z_init_thread_base(struct _thread_base *thread_base, - int priority, u32_t initial_state, - unsigned int options); - -static ALWAYS_INLINE void z_new_thread_init(struct k_thread *thread, - char *pStack, size_t stackSize, - int prio, unsigned int options) -{ -#if !defined(CONFIG_INIT_STACKS) && !defined(CONFIG_THREAD_STACK_INFO) - ARG_UNUSED(pStack); - ARG_UNUSED(stackSize); -#endif - -#ifdef CONFIG_INIT_STACKS - memset(pStack, 0xaa, stackSize); -#endif -#ifdef CONFIG_STACK_SENTINEL - /* Put the stack sentinel at the lowest 4 bytes of the stack area. - * We periodically check that it's still present and kill the thread - * if it isn't. - */ - *((u32_t *)pStack) = STACK_SENTINEL; -#endif /* CONFIG_STACK_SENTINEL */ - /* Initialize various struct k_thread members */ - z_init_thread_base(&thread->base, prio, _THREAD_PRESTART, options); - - /* static threads overwrite it afterwards with real value */ - thread->init_data = NULL; - thread->fn_abort = NULL; - -#ifdef CONFIG_THREAD_CUSTOM_DATA - /* Initialize custom data field (value is opaque to kernel) */ - thread->custom_data = NULL; -#endif - -#ifdef CONFIG_THREAD_NAME - thread->name[0] = '\0'; -#endif - -#if defined(CONFIG_USERSPACE) - thread->mem_domain_info.mem_domain = NULL; -#endif /* CONFIG_USERSPACE */ - -#if defined(CONFIG_THREAD_STACK_INFO) - thread->stack_info.start = (uintptr_t)pStack; - thread->stack_info.size = (u32_t)stackSize; -#endif /* CONFIG_THREAD_STACK_INFO */ -} - #endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_KERNEL_INCLUDE_KERNEL_STRUCTS_H_ */ diff --git a/include/sys/arch_inlines.h b/include/sys/arch_inlines.h deleted file mode 100644 index 6e04fad03fe..00000000000 --- a/include/sys/arch_inlines.h +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (c) 2019 Intel Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Internal kernel APIs with public scope - * - * The main set of architecture APIs is specified by - * include/sys/arch_interface.h - * - * Any public kernel APIs that are implemented as inline functions and need to - * call architecture-specific APIso will have the prototypes for the - * architecture-specific APIs here. Architecture APIs that aren't used in this - * way go in include/sys/arch_interface.h. - * - * The set of architecture-specific macros used internally by public macros - * in public headers is also specified and documented. - * - * For all macros and inline function prototypes described herein, - * must eventually pull in full definitions for all of them (the actual macro - * defines and inline function bodies) - * - * include/kernel.h and other public headers depend on definitions in this - * header. - */ - -#ifndef ZEPHYR_INCLUDE_SYS_ARCH_INLINES_H_ -#define ZEPHYR_INCLUDE_SYS_ARCH_INLINES_H_ - -#ifndef _ASMLANGUAGE - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* NOTE: We cannot pull in kernel.h here, need some forward declarations */ -struct k_thread; -typedef struct _k_thread_stack_element k_thread_stack_t; - -/** - * @addtogroup arch-timing - * @{ - */ - -/** - * Obtain the current cycle count, in units that are hardware-specific - * - * @see k_cycle_get_32() - */ -static inline u32_t z_arch_k_cycle_get_32(void); - -/** @} */ - - -/** - * @addtogroup arch-threads - * @{ - */ - -/** - * @def Z_ARCH_THREAD_STACK_DEFINE(sym, size) - * - * @see K_THREAD_STACK_DEFINE() - */ - -/** - * @def Z_ARCH_THREAD_STACK_ARRAY_DEFINE(sym, size) - * - * @see K_THREAD_STACK_ARRAY_DEFINE() - */ - -/** - * @def Z_ARCH_THREAD_STACK_LEN(size) - * - * @see K_THREAD_STACK_LEN() - */ - -/** - * @def Z_ARCH_THREAD_STACK_MEMBER(sym, size) - * - * @see K_THREAD_STACK_MEMBER() - */ - -/* - * @def Z_ARCH_THREAD_STACK_SIZEOF(sym) - * - * @see K_THREAD_STACK_SIZEOF() - */ - -/** - * @def Z_ARCH_THREAD_STACK_RESERVED - * - * @see K_THREAD_STACK_RESERVED - */ - -/** - * @def Z_ARCH_THREAD_STACK_BUFFER(sym) - * - * @see K_THREAD_STACK_RESERVED - */ - -/** @} */ - - -/** - * @addtogroup arch-pm - * @{ - */ - -/** - * @brief Power save idle routine - * - * This function will be called by the kernel idle loop or possibly within - * an implementation of z_sys_power_save_idle in the kernel when the - * '_sys_power_save_flag' variable is non-zero. - * - * Architectures that do not implement power management instructions may - * immediately return, otherwise a power-saving instruction should be - * issued to wait for an interrupt. - * - * @see k_cpu_idle() - */ -void z_arch_cpu_idle(void); - -/** - * @brief Atomically re-enable interrupts and enter low power mode - * - * The requirements for z_arch_cpu_atomic_idle() are as follows: - * - * 1) Enabling interrupts and entering a low-power mode needs to be - * atomic, i.e. there should be no period of time where interrupts are - * enabled before the processor enters a low-power mode. See the comments - * in k_lifo_get(), for example, of the race condition that - * occurs if this requirement is not met. - * - * 2) After waking up from the low-power mode, the interrupt lockout state - * must be restored as indicated in the 'key' input parameter. - * - * @see k_cpu_atomic_idle() - * - * @param key Lockout key returned by previous invocation of z_arch_irq_lock() - */ -void z_arch_cpu_atomic_idle(unsigned int key); - -/** @} */ - - -/** - * @addtogroup arch-smp - * @{ - */ - -/** - * @brief Start a numbered CPU on a MP-capable system - * - * This starts and initializes a specific CPU. The main thread on startup is - * running on CPU zero, other processors are numbered sequentially. On return - * from this function, the CPU is known to have begun operating and will enter - * the provided function. Its interrupts will be initialized but disabled such - * that irq_unlock() with the provided key will work to enable them. - * - * Normally, in SMP mode this function will be called by the kernel - * initialization and should not be used as a user API. But it is defined here - * for special-purpose apps which want Zephyr running on one core and to use - * others for design-specific processing. - * - * @param cpu_num Integer number of the CPU - * @param stack Stack memory for the CPU - * @param sz Stack buffer size, in bytes - * @param fn Function to begin running on the CPU. First argument is - * an irq_unlock() key. - * @param arg Untyped argument to be passed to "fn" - */ -void z_arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int key, void *data), void *arg); -/** @} */ - - -/** - * @addtogroup arch-irq - * @{ - */ - -/** - * Lock interrupts on the current CPU - * - * @see irq_lock() - */ -static inline unsigned int z_arch_irq_lock(void); - -/** - * Unlock interrupts on the current CPU - * - * @see irq_unlock() - */ -static inline void z_arch_irq_unlock(unsigned int key); - -/** - * Test if calling z_arch_irq_unlock() with this key would unlock irqs - * - * @param key value returned by z_arch_irq_lock() - * @return true if interrupts were unlocked prior to the z_arch_irq_lock() - * call that produced the key argument. - */ -static inline bool z_arch_irq_unlocked(unsigned int key); - -/** - * Disable the specified interrupt line - * - * @see irq_disable() - */ -void z_arch_irq_disable(unsigned int irq); - -/** - * Enable the specified interrupt line - * - * @see irq_enable() - */ -void z_arch_irq_enable(unsigned int irq); - -/** - * Test if an interrupt line is enabled - * - * @see irq_is_enabled() - */ -int z_arch_irq_is_enabled(unsigned int irq); - -/** - * Arch-specific hook to install a dynamic interrupt. - * - * @param irq IRQ line number - * @param priority Interrupt priority - * @param routine Interrupt service routine - * @param parameter ISR parameter - * @param flags Arch-specific IRQ configuration flag - * - * @return The vector assigned to this interrupt - */ -int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, - void (*routine)(void *parameter), - void *parameter, u32_t flags); - -/** - * @def Z_ARCH_IRQ_CONNECT(irq, pri, isr, arg, flags) - * - * @see IRQ_CONNECT() - */ - -/** - * @def Z_ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) - * - * @see IRQ_DIRECT_CONNECT() - */ - -/** - * @def Z_ARCH_ISR_DIRECT_PM() - * - * @see ISR_DIRECT_PM() - */ - -/** - * @def Z_ARCH_ISR_DIRECT_HEADER() - * - * @see ISR_DIRECT_HEADER() - */ - -/** - * @def Z_ARCH_ISR_DIRECT_FOOTER(swap) - * - * @see ISR_DIRECT_FOOTER() - */ - -/** - * @def Z_ARCH_ISR_DIRECT_DECLARE(name) - * - * @see ISR_DIRECT_DECLARE() - */ - -/** - * @def Z_ARCH_EXCEPT(reason_p) - * - * Generate a software induced fatal error. - * - * If the caller is running in user mode, only K_ERR_KERNEL_OOPS or - * K_ERR_STACK_CHK_FAIL may be induced. - * - * This should ideally generate a software trap, with exception context - * indicating state when this was invoked. General purpose register state at - * the time of trap should not be disturbed from the calling context. - * - * @param reason_p K_ERR_ scoped reason code for the fatal error. - */ - -#ifdef CONFIG_IRQ_OFFLOAD -typedef void (*irq_offload_routine_t)(void *parameter); - -/** - * Run a function in interrupt context. - * - * Implementations should invoke an exception such that the kernel goes through - * its interrupt handling dispatch path, to include switching to the interrupt - * stack, and runs the provided routine and parameter. - * - * The only intended use-case for this function is for test code to simulate - * the correctness of kernel APIs in interrupt handling context. This API - * is not intended for real applications. - * - * @see irq_offload() - * - * @param routine Function to run in interrupt context - * @param parameter Value to pass to the function when invoked - */ -void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter); -#endif /* CONFIG_IRQ_OFFLOAD */ - -/** @} */ - - -/** - * @addtogroup arch-userspace - * @{ - */ - -#ifdef CONFIG_USERSPACE -/** - * Invoke a system call with 0 arguments. - * - * No general-purpose register state other than return value may be preserved - * when transitioning from supervisor mode back down to user mode for - * security reasons. - * - * It is required that all arguments be stored in registers when elevating - * privileges from user to supervisor mode. - * - * Processing of the syscall takes place on a separate kernel stack. Interrupts - * should be enabled when invoking the system call marshallers from the - * dispatch table. Thread preemption may occur when handling system calls. - * - * Call ids are untrusted and must be bounds-checked, as the value is used to - * index the system call dispatch table, containing function pointers to the - * specific system call code. - * - * @param call_id System call ID - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id); - -/** - * Invoke a system call with 1 argument. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1, - uintptr_t call_id); - -/** - * Invoke a system call with 2 arguments. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param arg2 Second argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2, - uintptr_t call_id); - -/** - * Invoke a system call with 3 arguments. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param arg2 Second argument to the system call. - * @param arg3 Third argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2, - uintptr_t arg3, - uintptr_t call_id); - -/** - * Invoke a system call with 4 arguments. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param arg2 Second argument to the system call. - * @param arg3 Third argument to the system call. - * @param arg4 Fourth argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2, - uintptr_t arg3, uintptr_t arg4, - uintptr_t call_id); - -/** - * Invoke a system call with 5 arguments. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param arg2 Second argument to the system call. - * @param arg3 Third argument to the system call. - * @param arg4 Fourth argument to the system call. - * @param arg5 Fifth argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2, - uintptr_t arg3, uintptr_t arg4, - uintptr_t arg5, - uintptr_t call_id); - -/** - * Invoke a system call with 6 arguments. - * - * @see z_arch_syscall_invoke0() - * - * @param arg1 First argument to the system call. - * @param arg2 Second argument to the system call. - * @param arg3 Third argument to the system call. - * @param arg4 Fourth argument to the system call. - * @param arg5 Fifth argument to the system call. - * @param arg6 Sixth argument to the system call. - * @param call_id System call ID, will be bounds-checked and used to reference - * kernel-side dispatch table - * @return Return value of the system call. Void system calls return 0 here. - */ -static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2, - uintptr_t arg3, uintptr_t arg4, - uintptr_t arg5, uintptr_t arg6, - uintptr_t call_id); - -/** - * Indicate whether we are currently running in user mode - * - * @return true if the CPU is currently running with user permissions - */ -static inline bool z_arch_is_user_context(void); -#endif /* CONFIG_USERSPACE */ - -/** @} */ - -#ifdef __cplusplus -} -#endif -#endif /* _ASMLANGUAGE */ -#endif /* ZEPHYR_INCLUDE?SYS_ARCH_INLINES_H_ */ diff --git a/include/sys/arch_interface.h b/include/sys/arch_interface.h index c3b61531836..2b023869380 100644 --- a/include/sys/arch_interface.h +++ b/include/sys/arch_interface.h @@ -6,175 +6,320 @@ /** * @defgroup arch-interface Architecture Interface - * @brief Internal kernel APIs implemented at the architecture layer. + * @brief Internal kernel APIs with public scope * - * Not all architecture-specific defines are here, APIs that are used - * by public inline functions and macros are described in - * include/sys/arch_inlines.h. + * Any public kernel APIs that are implemented as inline functions and need to + * call architecture-specific API so will have the prototypes for the + * architecture-specific APIs here. Architecture APIs that aren't used in this + * way go in kernel/include/kernel_arch_interface.h. * - * For all inline functions prototyped here, the implementation is expected - * to be provided by arch/ARCH/include/kernel_arch_func.h + * The set of architecture-specific APIs used internally by public macros and + * inline functions in public headers are also specified and documented. * - * This header is not intended for general use; like kernel_arch_func.h, - * it is intended to be pulled in by internal kernel headers, specifically - * kernel/include/kernel_structs.h + * For all macros and inline function prototypes described herein, + * must eventually pull in full definitions for all of them (the actual macro + * defines and inline function bodies) + * + * include/kernel.h and other public headers depend on definitions in this + * header. */ #ifndef ZEPHYR_INCLUDE_SYS_ARCH_INTERFACE_H_ #define ZEPHYR_INCLUDE_SYS_ARCH_INTERFACE_H_ #ifndef _ASMLANGUAGE -#include +#include +#include +#include +#include #ifdef __cplusplus extern "C" { #endif +/* NOTE: We cannot pull in kernel.h here, need some forward declarations */ +struct k_thread; +struct k_mem_domain; + +typedef struct _k_thread_stack_element k_thread_stack_t; + +typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3); + /** * @defgroup arch-timing Architecture timing APIs * @ingroup arch-interface * @{ */ -#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT + /** - * Architecture-specific implementation of busy-waiting + * Obtain the current cycle count, in units that are hardware-specific * - * @param usec_to_wait Wait period, in microseconds + * @see k_cycle_get_32() */ -void z_arch_busy_wait(u32_t usec_to_wait); -#endif +static inline u32_t z_arch_k_cycle_get_32(void); /** @} */ + /** - * @defgroup arch-threads Architecture thread APIs - * @ingroup arch-interface + * @addtogroup arch-threads * @{ */ -/** Handle arch-specific logic for setting up new threads - * - * The stack and arch-specific thread state variables must be set up - * such that a later attempt to switch to this thread will succeed - * and we will enter z_thread_entry with the requested thread and - * arguments as its parameters. - * - * At some point in this function's implementation, z_setup_new_thread() must - * be called with the true bounds of the available stack buffer within the - * thread's stack object. - * - * @param thread Pointer to uninitialized struct k_thread - * @param pStack Pointer to the stack space. - * @param stackSize Stack size in bytes. - * @param entry Thread entry function. - * @param p1 1st entry point parameter. - * @param p2 2nd entry point parameter. - * @param p3 3rd entry point parameter. - * @param prio Thread priority. - * @param options Thread options. - */ -void z_arch_new_thread(struct k_thread *thread, k_thread_stack_t *pStack, - size_t stackSize, k_thread_entry_t entry, - void *p1, void *p2, void *p3, - int prio, unsigned int options); - -#ifdef CONFIG_USE_SWITCH /** - * Cooperatively context switch + * @def Z_ARCH_THREAD_STACK_DEFINE(sym, size) * - * Architectures have considerable leeway on what the specific semantics of - * the switch handles are, but optimal implementations should do the following - * if possible: - * - * 1) Push all thread state relevant to the context switch to the current stack - * 2) Update the switched_from parameter to contain the current stack pointer, - * after all context has been saved. switched_from is used as an output- - * only parameter and its current value is ignored (and can be NULL, see - * below). - * 3) Set the stack pointer to the value provided in switch_to - * 4) Pop off all thread state from the stack we switched to and return. - * - * Some arches may implement thread->switch handle as a pointer to the thread - * itself, and save context somewhere in thread->arch. In this case, on initial - * context switch from the dummy thread, thread->switch handle for the outgoing - * thread is NULL. Instead of dereferencing switched_from all the way to get - * the thread pointer, subtract ___thread_t_switch_handle_OFFSET to obtain the - * thread pointer instead. - * - * @param switch_to Incoming thread's switch handle - * @param switched_from Pointer to outgoing thread's switch handle storage - * location, which may be updated. + * @see K_THREAD_STACK_DEFINE() */ -static inline void z_arch_switch(void *switch_to, void **switched_from); -#else -/** - * Cooperatively context switch - * - * Must be called with interrupts locked with the provided key. - * This is the older-style context switching method, which is incompatible - * with SMP. New arch ports, either SMP or UP, are encouraged to implement - * z_arch_switch() instead. - * - * @param key Interrupt locking key - * @return If woken from blocking on some kernel object, the result of that - * blocking operation. - */ -int z_arch_swap(unsigned int key); /** - * Set the return value for the specified thread. + * @def Z_ARCH_THREAD_STACK_ARRAY_DEFINE(sym, size) * - * It is assumed that the specified @a thread is pending. - * - * @param thread Pointer to thread object - * @param value value to set as return value + * @see K_THREAD_STACK_ARRAY_DEFINE() */ -static ALWAYS_INLINE void -z_arch_thread_return_value_set(struct k_thread *thread, unsigned int value); -#endif /* CONFIG_USE_SWITCH i*/ -#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN /** - * Custom logic for entering main thread context at early boot + * @def Z_ARCH_THREAD_STACK_LEN(size) * - * Used by architectures where the typical trick of setting up a dummy thread - * in early boot context to "switch out" of isn't workable. - * - * @param main_thread main thread object - * @param main_stack main thread's stack object - * @param main_stack_size Size of the stack object's buffer - * @param _main Entry point for application main function. + * @see K_THREAD_STACK_LEN() */ -void z_arch_switch_to_main_thread(struct k_thread *main_thread, - k_thread_stack_t *main_stack, - size_t main_stack_size, - k_thread_entry_t _main); -#endif /* CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN */ -#if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING) /** - * @brief Disable floating point context preservation + * @def Z_ARCH_THREAD_STACK_MEMBER(sym, size) * - * The function is used to disable the preservation of floating - * point context information for a particular thread. - * - * @note For ARM architecture, disabling floating point preservation may only - * be requested for the current thread and cannot be requested in ISRs. - * - * @retval 0 On success. - * @retval -EINVAL If the floating point disabling could not be performed. + * @see K_THREAD_STACK_MEMBER() + */ + +/* + * @def Z_ARCH_THREAD_STACK_SIZEOF(sym) + * + * @see K_THREAD_STACK_SIZEOF() + */ + +/** + * @def Z_ARCH_THREAD_STACK_RESERVED + * + * @see K_THREAD_STACK_RESERVED + */ + +/** + * @def Z_ARCH_THREAD_STACK_BUFFER(sym) + * + * @see K_THREAD_STACK_RESERVED */ -int z_arch_float_disable(struct k_thread *thread); -#endif /* CONFIG_FLOAT && CONFIG_FP_SHARING */ /** @} */ + /** - * @defgroup arch-pm Architecture-specific power management APIs - * @ingroup arch-interface + * @addtogroup arch-pm * @{ */ -/** Halt the system, optionally propagating a reason code */ -FUNC_NORETURN void z_arch_system_halt(unsigned int reason); + +/** + * @brief Power save idle routine + * + * This function will be called by the kernel idle loop or possibly within + * an implementation of z_sys_power_save_idle in the kernel when the + * '_sys_power_save_flag' variable is non-zero. + * + * Architectures that do not implement power management instructions may + * immediately return, otherwise a power-saving instruction should be + * issued to wait for an interrupt. + * + * @see k_cpu_idle() + */ +void z_arch_cpu_idle(void); + +/** + * @brief Atomically re-enable interrupts and enter low power mode + * + * The requirements for z_arch_cpu_atomic_idle() are as follows: + * + * 1) Enabling interrupts and entering a low-power mode needs to be + * atomic, i.e. there should be no period of time where interrupts are + * enabled before the processor enters a low-power mode. See the comments + * in k_lifo_get(), for example, of the race condition that + * occurs if this requirement is not met. + * + * 2) After waking up from the low-power mode, the interrupt lockout state + * must be restored as indicated in the 'key' input parameter. + * + * @see k_cpu_atomic_idle() + * + * @param key Lockout key returned by previous invocation of z_arch_irq_lock() + */ +void z_arch_cpu_atomic_idle(unsigned int key); + +/** @} */ + + +/** + * @addtogroup arch-smp + * @{ + */ + +/** + * @brief Start a numbered CPU on a MP-capable system + * + * This starts and initializes a specific CPU. The main thread on startup is + * running on CPU zero, other processors are numbered sequentially. On return + * from this function, the CPU is known to have begun operating and will enter + * the provided function. Its interrupts will be initialized but disabled such + * that irq_unlock() with the provided key will work to enable them. + * + * Normally, in SMP mode this function will be called by the kernel + * initialization and should not be used as a user API. But it is defined here + * for special-purpose apps which want Zephyr running on one core and to use + * others for design-specific processing. + * + * @param cpu_num Integer number of the CPU + * @param stack Stack memory for the CPU + * @param sz Stack buffer size, in bytes + * @param fn Function to begin running on the CPU. First argument is + * an irq_unlock() key. + * @param arg Untyped argument to be passed to "fn" + */ +void z_arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, + void (*fn)(int key, void *data), void *arg); +/** @} */ + + +/** + * @addtogroup arch-irq + * @{ + */ + +/** + * Lock interrupts on the current CPU + * + * @see irq_lock() + */ +static inline unsigned int z_arch_irq_lock(void); + +/** + * Unlock interrupts on the current CPU + * + * @see irq_unlock() + */ +static inline void z_arch_irq_unlock(unsigned int key); + +/** + * Test if calling z_arch_irq_unlock() with this key would unlock irqs + * + * @param key value returned by z_arch_irq_lock() + * @return true if interrupts were unlocked prior to the z_arch_irq_lock() + * call that produced the key argument. + */ +static inline bool z_arch_irq_unlocked(unsigned int key); + +/** + * Disable the specified interrupt line + * + * @see irq_disable() + */ +void z_arch_irq_disable(unsigned int irq); + +/** + * Enable the specified interrupt line + * + * @see irq_enable() + */ +void z_arch_irq_enable(unsigned int irq); + +/** + * Test if an interrupt line is enabled + * + * @see irq_is_enabled() + */ +int z_arch_irq_is_enabled(unsigned int irq); + +/** + * Arch-specific hook to install a dynamic interrupt. + * + * @param irq IRQ line number + * @param priority Interrupt priority + * @param routine Interrupt service routine + * @param parameter ISR parameter + * @param flags Arch-specific IRQ configuration flag + * + * @return The vector assigned to this interrupt + */ +int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, + void (*routine)(void *parameter), + void *parameter, u32_t flags); + +/** + * @def Z_ARCH_IRQ_CONNECT(irq, pri, isr, arg, flags) + * + * @see IRQ_CONNECT() + */ + +/** + * @def Z_ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) + * + * @see IRQ_DIRECT_CONNECT() + */ + +/** + * @def Z_ARCH_ISR_DIRECT_PM() + * + * @see ISR_DIRECT_PM() + */ + +/** + * @def Z_ARCH_ISR_DIRECT_HEADER() + * + * @see ISR_DIRECT_HEADER() + */ + +/** + * @def Z_ARCH_ISR_DIRECT_FOOTER(swap) + * + * @see ISR_DIRECT_FOOTER() + */ + +/** + * @def Z_ARCH_ISR_DIRECT_DECLARE(name) + * + * @see ISR_DIRECT_DECLARE() + */ + +/** + * @def Z_ARCH_EXCEPT(reason_p) + * + * Generate a software induced fatal error. + * + * If the caller is running in user mode, only K_ERR_KERNEL_OOPS or + * K_ERR_STACK_CHK_FAIL may be induced. + * + * This should ideally generate a software trap, with exception context + * indicating state when this was invoked. General purpose register state at + * the time of trap should not be disturbed from the calling context. + * + * @param reason_p K_ERR_ scoped reason code for the fatal error. + */ + +#ifdef CONFIG_IRQ_OFFLOAD +typedef void (*irq_offload_routine_t)(void *parameter); + +/** + * Run a function in interrupt context. + * + * Implementations should invoke an exception such that the kernel goes through + * its interrupt handling dispatch path, to include switching to the interrupt + * stack, and runs the provided routine and parameter. + * + * The only intended use-case for this function is for test code to simulate + * the correctness of kernel APIs in interrupt handling context. This API + * is not intended for real applications. + * + * @see irq_offload() + * + * @param routine Function to run in interrupt context + * @param parameter Value to pass to the function when invoked + */ +void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter); +#endif /* CONFIG_IRQ_OFFLOAD */ /** @} */ @@ -199,31 +344,142 @@ void z_arch_sched_ipi(void); /** @} */ -/** - * @defgroup arch-irq Architecture-specific IRQ APIs - * @ingroup arch-interface - * @{ - */ - -/** - * Test if the current context is in interrupt context - * - * XXX: This is inconsistently handled among arches wrt exception context - * See: #17656 - * - * @return true if we are in interrupt context - */ -static inline bool z_arch_is_in_isr(void); - -/** @} */ - - /** * @defgroup arch-userspace Architecture-specific userspace APIs * @ingroup arch-interface * @{ */ + #ifdef CONFIG_USERSPACE +/** + * Invoke a system call with 0 arguments. + * + * No general-purpose register state other than return value may be preserved + * when transitioning from supervisor mode back down to user mode for + * security reasons. + * + * It is required that all arguments be stored in registers when elevating + * privileges from user to supervisor mode. + * + * Processing of the syscall takes place on a separate kernel stack. Interrupts + * should be enabled when invoking the system call marshallers from the + * dispatch table. Thread preemption may occur when handling system calls. + * + * Call ids are untrusted and must be bounds-checked, as the value is used to + * index the system call dispatch table, containing function pointers to the + * specific system call code. + * + * @param call_id System call ID + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id); + +/** + * Invoke a system call with 1 argument. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1, + uintptr_t call_id); + +/** + * Invoke a system call with 2 arguments. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param arg2 Second argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2, + uintptr_t call_id); + +/** + * Invoke a system call with 3 arguments. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param arg2 Second argument to the system call. + * @param arg3 Third argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2, + uintptr_t arg3, + uintptr_t call_id); + +/** + * Invoke a system call with 4 arguments. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param arg2 Second argument to the system call. + * @param arg3 Third argument to the system call. + * @param arg4 Fourth argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2, + uintptr_t arg3, uintptr_t arg4, + uintptr_t call_id); + +/** + * Invoke a system call with 5 arguments. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param arg2 Second argument to the system call. + * @param arg3 Third argument to the system call. + * @param arg4 Fourth argument to the system call. + * @param arg5 Fifth argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2, + uintptr_t arg3, uintptr_t arg4, + uintptr_t arg5, + uintptr_t call_id); + +/** + * Invoke a system call with 6 arguments. + * + * @see z_arch_syscall_invoke0() + * + * @param arg1 First argument to the system call. + * @param arg2 Second argument to the system call. + * @param arg3 Third argument to the system call. + * @param arg4 Fourth argument to the system call. + * @param arg5 Fifth argument to the system call. + * @param arg6 Sixth argument to the system call. + * @param call_id System call ID, will be bounds-checked and used to reference + * kernel-side dispatch table + * @return Return value of the system call. Void system calls return 0 here. + */ +static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2, + uintptr_t arg3, uintptr_t arg4, + uintptr_t arg5, uintptr_t arg6, + uintptr_t call_id); + +/** + * Indicate whether we are currently running in user mode + * + * @return true if the CPU is currently running with user permissions + */ +static inline bool z_arch_is_user_context(void); + /** * @brief Get the maximum number of partitions for a memory domain * @@ -380,51 +636,12 @@ size_t z_arch_user_string_nlen(const char *s, size_t maxsize, int *err); /** @} */ - -/** - * @defgroup arch-benchmarking Architecture-specific benchmarking globals - * @ingroup arch-interface - */ - -#ifdef CONFIG_EXECUTION_BENCHMARKING -extern u64_t z_arch_timing_swap_start; -extern u64_t z_arch_timing_swap_end; -extern u64_t z_arch_timing_irq_start; -extern u64_t z_arch_timing_irq_end; -extern u64_t z_arch_timing_tick_start; -extern u64_t z_arch_timing_tick_end; -extern u64_t z_arch_timing_user_mode_end; -extern u32_t z_arch_timing_value_swap_end; -extern u64_t z_arch_timing_value_swap_common; -extern u64_t z_arch_timing_value_swap_temp; -#endif /* CONFIG_EXECUTION_BENCHMARKING */ - -/** @} */ - - -/** - * @defgroup arch-misc Miscellaneous architecture APIs - * @ingroup arch-interface - */ - -/** - * Architecture-specific kernel initialization hook - * - * This function is invoked near the top of _Cstart, for additional - * architecture-specific setup before the rest of the kernel is brought up. - * - * TODO: Deprecate, most arches are using a prep_c() function to do the same - * thing in a simpler way - */ -static inline void z_arch_kernel_init(void); - -/** Do nothing and return. Yawn. */ -static inline void z_arch_nop(void); - -/** @} */ - #ifdef __cplusplus } #endif /* __cplusplus */ + +#include + #endif /* _ASMLANGUAGE */ + #endif /* ZEPHYR_INCLUDE_SYS_ARCH_INTERFACE_H_ */ diff --git a/kernel/include/syscall_handler.h b/include/syscall_handler.h similarity index 98% rename from kernel/include/syscall_handler.h rename to include/syscall_handler.h index a5e5b7a5e80..e8beaa54467 100644 --- a/kernel/include/syscall_handler.h +++ b/include/syscall_handler.h @@ -5,16 +5,15 @@ */ -#ifndef ZEPHYR_KERNEL_INCLUDE_SYSCALL_HANDLER_H_ -#define ZEPHYR_KERNEL_INCLUDE_SYSCALL_HANDLER_H_ +#ifndef ZEPHYR_INCLUDE_SYSCALL_HANDLER_H_ +#define ZEPHYR_INCLUDE_SYSCALL_HANDLER_H_ #ifdef CONFIG_USERSPACE #ifndef _ASMLANGUAGE #include +#include #include -#include -#include #include #include @@ -515,4 +514,4 @@ static inline int z_obj_validation_check(struct _k_object *ko, #endif /* CONFIG_USERSPACE */ -#endif /* ZEPHYR_KERNEL_INCLUDE_SYSCALL_HANDLER_H_ */ +#endif /* ZEPHYR_INCLUDE_SYSCALL_HANDLER_H_ */ diff --git a/kernel/include/timeout_q.h b/include/timeout_q.h similarity index 100% rename from kernel/include/timeout_q.h rename to include/timeout_q.h diff --git a/include/toolchain/gcc.h b/include/toolchain/gcc.h index 936dde341c7..bc3baaf93d4 100644 --- a/include/toolchain/gcc.h +++ b/include/toolchain/gcc.h @@ -71,7 +71,7 @@ return_type new_alias() ALIAS_OF(real_func) #if defined(CONFIG_ARCH_POSIX) -#include +#include /*let's not segfault if this were to happen for some reason*/ #define CODE_UNREACHABLE \ diff --git a/kernel/include/wait_q.h b/include/wait_q.h similarity index 98% rename from kernel/include/wait_q.h rename to include/wait_q.h index 6f66985304b..499d630e9d6 100644 --- a/kernel/include/wait_q.h +++ b/include/wait_q.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 7d8e8585b11..988df63371a 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -53,6 +53,10 @@ target_sources_ifdef( userspace.c ) +target_include_directories(kernel PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) add_dependencies(kernel ${OFFSETS_H_TARGET}) diff --git a/kernel/errno.c b/kernel/errno.c index e23593785fc..51a2363d28d 100644 --- a/kernel/errno.c +++ b/kernel/errno.c @@ -12,7 +12,7 @@ * context switching. */ -#include +#include #include /* diff --git a/kernel/idle.c b/kernel/idle.c index 2bbdf16d464..0bfe35dc6c9 100644 --- a/kernel/idle.c +++ b/kernel/idle.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include diff --git a/kernel/include/kernel_arch_interface.h b/kernel/include/kernel_arch_interface.h new file mode 100644 index 00000000000..47d75a6d127 --- /dev/null +++ b/kernel/include/kernel_arch_interface.h @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2019 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Internal kernel APIs implemented at the architecture layer. + * + * Not all architecture-specific defines are here, APIs that are used + * by public functions and macros are defined in include/sys/arch_interface.h. + * + * For all inline functions prototyped here, the implementation is expected + * to be provided by arch/ARCH/include/kernel_arch_func.h + */ +#ifndef ZEPHYR_KERNEL_INCLUDE_KERNEL_ARCH_INTERFACE_H_ +#define ZEPHYR_KERNEL_INCLUDE_KERNEL_ARCH_INTERFACE_H_ + +#include +#include + +#ifndef _ASMLANGUAGE + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup arch-timing Architecture timing APIs + * @{ + */ +#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT +/** + * Architecture-specific implementation of busy-waiting + * + * @param usec_to_wait Wait period, in microseconds + */ +void z_arch_busy_wait(u32_t usec_to_wait); +#endif + +/** @} */ + +/** + * @defgroup arch-threads Architecture thread APIs + * @ingroup arch-interface + * @{ + */ + +/** Handle arch-specific logic for setting up new threads + * + * The stack and arch-specific thread state variables must be set up + * such that a later attempt to switch to this thread will succeed + * and we will enter z_thread_entry with the requested thread and + * arguments as its parameters. + * + * At some point in this function's implementation, z_setup_new_thread() must + * be called with the true bounds of the available stack buffer within the + * thread's stack object. + * + * @param thread Pointer to uninitialized struct k_thread + * @param pStack Pointer to the stack space. + * @param stackSize Stack size in bytes. + * @param entry Thread entry function. + * @param p1 1st entry point parameter. + * @param p2 2nd entry point parameter. + * @param p3 3rd entry point parameter. + * @param prio Thread priority. + * @param options Thread options. + */ +void z_arch_new_thread(struct k_thread *thread, k_thread_stack_t *pStack, + size_t stackSize, k_thread_entry_t entry, + void *p1, void *p2, void *p3, + int prio, unsigned int options); + +#ifdef CONFIG_USE_SWITCH +/** + * Cooperatively context switch + * + * Architectures have considerable leeway on what the specific semantics of + * the switch handles are, but optimal implementations should do the following + * if possible: + * + * 1) Push all thread state relevant to the context switch to the current stack + * 2) Update the switched_from parameter to contain the current stack pointer, + * after all context has been saved. switched_from is used as an output- + * only parameter and its current value is ignored (and can be NULL, see + * below). + * 3) Set the stack pointer to the value provided in switch_to + * 4) Pop off all thread state from the stack we switched to and return. + * + * Some arches may implement thread->switch handle as a pointer to the thread + * itself, and save context somewhere in thread->arch. In this case, on initial + * context switch from the dummy thread, thread->switch handle for the outgoing + * thread is NULL. Instead of dereferencing switched_from all the way to get + * the thread pointer, subtract ___thread_t_switch_handle_OFFSET to obtain the + * thread pointer instead. + * + * @param switch_to Incoming thread's switch handle + * @param switched_from Pointer to outgoing thread's switch handle storage + * location, which may be updated. + */ +static inline void z_arch_switch(void *switch_to, void **switched_from); +#else +/** + * Cooperatively context switch + * + * Must be called with interrupts locked with the provided key. + * This is the older-style context switching method, which is incompatible + * with SMP. New arch ports, either SMP or UP, are encouraged to implement + * z_arch_switch() instead. + * + * @param key Interrupt locking key + * @return If woken from blocking on some kernel object, the result of that + * blocking operation. + */ +int z_arch_swap(unsigned int key); + +/** + * Set the return value for the specified thread. + * + * It is assumed that the specified @a thread is pending. + * + * @param thread Pointer to thread object + * @param value value to set as return value + */ +static ALWAYS_INLINE void +z_arch_thread_return_value_set(struct k_thread *thread, unsigned int value); +#endif /* CONFIG_USE_SWITCH i*/ + +#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN +/** + * Custom logic for entering main thread context at early boot + * + * Used by architectures where the typical trick of setting up a dummy thread + * in early boot context to "switch out" of isn't workable. + * + * @param main_thread main thread object + * @param main_stack main thread's stack object + * @param main_stack_size Size of the stack object's buffer + * @param _main Entry point for application main function. + */ +void z_arch_switch_to_main_thread(struct k_thread *main_thread, + k_thread_stack_t *main_stack, + size_t main_stack_size, + k_thread_entry_t _main); +#endif /* CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN */ + +#if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING) +/** + * @brief Disable floating point context preservation + * + * The function is used to disable the preservation of floating + * point context information for a particular thread. + * + * @note For ARM architecture, disabling floating point preservation may only + * be requested for the current thread and cannot be requested in ISRs. + * + * @retval 0 On success. + * @retval -EINVAL If the floating point disabling could not be performed. + */ +int z_arch_float_disable(struct k_thread *thread); +#endif /* CONFIG_FLOAT && CONFIG_FP_SHARING */ + +/** @} */ + +/** + * @defgroup arch-pm Architecture-specific power management APIs + * @ingroup arch-interface + * @{ + */ +/** Halt the system, optionally propagating a reason code */ +FUNC_NORETURN void z_arch_system_halt(unsigned int reason); + +/** @} */ + + +/** + * @defgroup arch-irq Architecture-specific IRQ APIs + * @ingroup arch-interface + * @{ + */ + +/** + * Test if the current context is in interrupt context + * + * XXX: This is inconsistently handled among arches wrt exception context + * See: #17656 + * + * @return true if we are in interrupt context + */ +static inline bool z_arch_is_in_isr(void); + +/** @} */ + + +/** + * @defgroup arch-benchmarking Architecture-specific benchmarking globals + * @ingroup arch-interface + */ + +#ifdef CONFIG_EXECUTION_BENCHMARKING +extern u64_t z_arch_timing_swap_start; +extern u64_t z_arch_timing_swap_end; +extern u64_t z_arch_timing_irq_start; +extern u64_t z_arch_timing_irq_end; +extern u64_t z_arch_timing_tick_start; +extern u64_t z_arch_timing_tick_end; +extern u64_t z_arch_timing_user_mode_end; +extern u32_t z_arch_timing_value_swap_end; +extern u64_t z_arch_timing_value_swap_common; +extern u64_t z_arch_timing_value_swap_temp; +#endif /* CONFIG_EXECUTION_BENCHMARKING */ + +/** @} */ + + +/** + * @defgroup arch-misc Miscellaneous architecture APIs + * @ingroup arch-interface + */ + +/** + * Architecture-specific kernel initialization hook + * + * This function is invoked near the top of _Cstart, for additional + * architecture-specific setup before the rest of the kernel is brought up. + * + * TODO: Deprecate, most arches are using a prep_c() function to do the same + * thing in a simpler way + */ +static inline void z_arch_kernel_init(void); + +/** Do nothing and return. Yawn. */ +static inline void z_arch_nop(void); + +/** @} */ + +/* Include arch-specific inline function implementation */ +#include + +#ifdef __cplusplus +} +#endif + +#endif /* _ASMLANGUAGE */ + +#endif /* ZEPHYR_KERNEL_INCLUDE_KERNEL_ARCH_INTERFACE_H_ */ diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 1c03bec5f32..4f8bacd32e6 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -15,7 +15,8 @@ #define ZEPHYR_KERNEL_INCLUDE_KERNEL_INTERNAL_H_ #include -#include +#include +#include #ifndef _ASMLANGUAGE @@ -45,6 +46,51 @@ extern void z_setup_new_thread(struct k_thread *new_thread, void *p1, void *p2, void *p3, int prio, u32_t options, const char *name); +static ALWAYS_INLINE void z_new_thread_init(struct k_thread *thread, + char *pStack, size_t stackSize, + int prio, unsigned int options) +{ +#if !defined(CONFIG_INIT_STACKS) && !defined(CONFIG_THREAD_STACK_INFO) + ARG_UNUSED(pStack); + ARG_UNUSED(stackSize); +#endif + +#ifdef CONFIG_INIT_STACKS + memset(pStack, 0xaa, stackSize); +#endif +#ifdef CONFIG_STACK_SENTINEL + /* Put the stack sentinel at the lowest 4 bytes of the stack area. + * We periodically check that it's still present and kill the thread + * if it isn't. + */ + *((u32_t *)pStack) = STACK_SENTINEL; +#endif /* CONFIG_STACK_SENTINEL */ + /* Initialize various struct k_thread members */ + z_init_thread_base(&thread->base, prio, _THREAD_PRESTART, options); + + /* static threads overwrite it afterwards with real value */ + thread->init_data = NULL; + thread->fn_abort = NULL; + +#ifdef CONFIG_THREAD_CUSTOM_DATA + /* Initialize custom data field (value is opaque to kernel) */ + thread->custom_data = NULL; +#endif + +#ifdef CONFIG_THREAD_NAME + thread->name[0] = '\0'; +#endif + +#if defined(CONFIG_USERSPACE) + thread->mem_domain_info.mem_domain = NULL; +#endif /* CONFIG_USERSPACE */ + +#if defined(CONFIG_THREAD_STACK_INFO) + thread->stack_info.start = (uintptr_t)pStack; + thread->stack_info.size = (u32_t)stackSize; +#endif /* CONFIG_THREAD_STACK_INFO */ +} + #ifdef CONFIG_USERSPACE /** * @brief Zero out BSS sections for application shared memory @@ -83,6 +129,26 @@ extern void z_thread_monitor_exit(struct k_thread *thread); } while (false) #endif /* CONFIG_THREAD_MONITOR */ +#ifdef CONFIG_USE_SWITCH +/* This is a arch function traditionally, but when the switch-based + * z_swap() is in use it's a simple inline provided by the kernel. + */ +static ALWAYS_INLINE void +z_arch_thread_return_value_set(struct k_thread *thread, unsigned int value) +{ + thread->swap_retval = value; +} +#endif + +static ALWAYS_INLINE void +z_thread_return_value_set_with_data(struct k_thread *thread, + unsigned int value, + void *data) +{ + z_arch_thread_return_value_set(thread, value); + thread->base.swap_data = data; +} + extern void z_smp_init(void); extern void smp_timer_init(void); diff --git a/kernel/mailbox.c b/kernel/mailbox.c index 5bc6ebe65bd..308d90bd36d 100644 --- a/kernel/mailbox.c +++ b/kernel/mailbox.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/kernel/msg_q.c b/kernel/msg_q.c index f46655b533b..7c12440ba91 100644 --- a/kernel/msg_q.c +++ b/kernel/msg_q.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/kernel/mutex.c b/kernel/mutex.c index cd9f76eb120..ba3aa4de992 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/kernel/pipes.c b/kernel/pipes.c index e48fa9b1450..78417cff692 100644 --- a/kernel/pipes.c +++ b/kernel/pipes.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/kernel/thread.c b/kernel/thread.c index 0642d0f10fb..ff2cf0b8259 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -12,12 +12,7 @@ */ #include - -#include -#include - #include -#include #include #include #include @@ -29,6 +24,7 @@ #include #include #include +#include #include static struct k_spinlock lock; diff --git a/kernel/timeout.c b/kernel/timeout.c index 12e4c48483a..9694653d69a 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -3,12 +3,14 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include -#include -#include + +#include #include #include +#include #include +#include +#include #define LOCKED(lck) for (k_spinlock_key_t __i = {}, \ __key = k_spin_lock(lck); \ diff --git a/kernel/timer.c b/kernel/timer.c index 997cbc2d10d..3c4c4caacf7 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/cmsis_rtos_v1/CMakeLists.txt b/lib/cmsis_rtos_v1/CMakeLists.txt index b3c31c66d68..b67f971de09 100644 --- a/lib/cmsis_rtos_v1/CMakeLists.txt +++ b/lib/cmsis_rtos_v1/CMakeLists.txt @@ -20,4 +20,9 @@ zephyr_library_sources_ifdef( cmsis_signal.c ) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include +) + zephyr_library_link_libraries(CMSIS) diff --git a/lib/cmsis_rtos_v1/cmsis_kernel.c b/lib/cmsis_rtos_v1/cmsis_kernel.c index 71c049bb029..a61136ac292 100644 --- a/lib/cmsis_rtos_v1/cmsis_kernel.c +++ b/lib/cmsis_rtos_v1/cmsis_kernel.c @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include #include +#include #include /** diff --git a/lib/cmsis_rtos_v1/cmsis_mailq.c b/lib/cmsis_rtos_v1/cmsis_mailq.c index cc62bb2747b..ed579a4b8e7 100644 --- a/lib/cmsis_rtos_v1/cmsis_mailq.c +++ b/lib/cmsis_rtos_v1/cmsis_mailq.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include /** * @brief Create and Initialize mail queue. diff --git a/lib/cmsis_rtos_v1/cmsis_mempool.c b/lib/cmsis_rtos_v1/cmsis_mempool.c index 31aea5e7870..d1df402308c 100644 --- a/lib/cmsis_rtos_v1/cmsis_mempool.c +++ b/lib/cmsis_rtos_v1/cmsis_mempool.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include #define TIME_OUT 100 diff --git a/lib/cmsis_rtos_v1/cmsis_msgq.c b/lib/cmsis_rtos_v1/cmsis_msgq.c index 5e3869c9a71..0293c3f5f02 100644 --- a/lib/cmsis_rtos_v1/cmsis_msgq.c +++ b/lib/cmsis_rtos_v1/cmsis_msgq.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include /** diff --git a/lib/cmsis_rtos_v1/cmsis_mutex.c b/lib/cmsis_rtos_v1/cmsis_mutex.c index 9842d47e7e9..bc9e05b4935 100644 --- a/lib/cmsis_rtos_v1/cmsis_mutex.c +++ b/lib/cmsis_rtos_v1/cmsis_mutex.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include K_MEM_SLAB_DEFINE(cmsis_mutex_slab, sizeof(struct k_mutex), CONFIG_CMSIS_MUTEX_MAX_COUNT, 4); diff --git a/lib/cmsis_rtos_v1/cmsis_semaphore.c b/lib/cmsis_rtos_v1/cmsis_semaphore.c index 8bb0d04158e..ce5e5f6a71c 100644 --- a/lib/cmsis_rtos_v1/cmsis_semaphore.c +++ b/lib/cmsis_rtos_v1/cmsis_semaphore.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include K_MEM_SLAB_DEFINE(cmsis_semaphore_slab, sizeof(struct k_sem), CONFIG_CMSIS_SEMAPHORE_MAX_COUNT, 4); diff --git a/lib/cmsis_rtos_v1/cmsis_signal.c b/lib/cmsis_rtos_v1/cmsis_signal.c index a0cfa37fa55..02a262d33e4 100644 --- a/lib/cmsis_rtos_v1/cmsis_signal.c +++ b/lib/cmsis_rtos_v1/cmsis_signal.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC) diff --git a/lib/cmsis_rtos_v1/cmsis_thread.c b/lib/cmsis_rtos_v1/cmsis_thread.c index 3972010f20c..3fb236fbce8 100644 --- a/lib/cmsis_rtos_v1/cmsis_thread.c +++ b/lib/cmsis_rtos_v1/cmsis_thread.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/lib/cmsis_rtos_v1/cmsis_timer.c b/lib/cmsis_rtos_v1/cmsis_timer.c index 738c8414d47..6200d1558c8 100644 --- a/lib/cmsis_rtos_v1/cmsis_timer.c +++ b/lib/cmsis_rtos_v1/cmsis_timer.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include +#include #define ACTIVE 1 #define NOT_ACTIVE 0 diff --git a/lib/cmsis_rtos_v1/cmsis_wait.c b/lib/cmsis_rtos_v1/cmsis_wait.c index 45de33e3d12..228ac94bc56 100644 --- a/lib/cmsis_rtos_v1/cmsis_wait.c +++ b/lib/cmsis_rtos_v1/cmsis_wait.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include /** diff --git a/lib/cmsis_rtos_v2/CMakeLists.txt b/lib/cmsis_rtos_v2/CMakeLists.txt index 5327dad9b5d..c4c8129b9f4 100644 --- a/lib/cmsis_rtos_v2/CMakeLists.txt +++ b/lib/cmsis_rtos_v2/CMakeLists.txt @@ -19,4 +19,9 @@ zephyr_library_sources_ifdef( thread_flags.c ) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include +) + zephyr_library_link_libraries(CMSIS) diff --git a/lib/cmsis_rtos_v2/event_flags.c b/lib/cmsis_rtos_v2/event_flags.c index 26205cbce76..93e751ed6cc 100644 --- a/lib/cmsis_rtos_v2/event_flags.c +++ b/lib/cmsis_rtos_v2/event_flags.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" K_MEM_SLAB_DEFINE(cv2_event_flags_slab, sizeof(struct cv2_event_flags), diff --git a/lib/cmsis_rtos_v2/kernel.c b/lib/cmsis_rtos_v2/kernel.c index dad2b177f56..06285911fc7 100644 --- a/lib/cmsis_rtos_v2/kernel.c +++ b/lib/cmsis_rtos_v2/kernel.c @@ -6,8 +6,7 @@ #include #include -#include -#include +#include #include /* Currently the timing implementations for timeouts and osDelay diff --git a/lib/cmsis_rtos_v2/mempool.c b/lib/cmsis_rtos_v2/mempool.c index be594dd3f23..128b8068a6c 100644 --- a/lib/cmsis_rtos_v2/mempool.c +++ b/lib/cmsis_rtos_v2/mempool.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" #define TIME_OUT_TICKS 10 diff --git a/lib/cmsis_rtos_v2/msgq.c b/lib/cmsis_rtos_v2/msgq.c index 22596e587fb..d4f4de9f3e2 100644 --- a/lib/cmsis_rtos_v2/msgq.c +++ b/lib/cmsis_rtos_v2/msgq.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" K_MEM_SLAB_DEFINE(cv2_msgq_slab, sizeof(struct cv2_msgq), diff --git a/lib/cmsis_rtos_v2/mutex.c b/lib/cmsis_rtos_v2/mutex.c index 6626cb23eab..27c8ae13086 100644 --- a/lib/cmsis_rtos_v2/mutex.c +++ b/lib/cmsis_rtos_v2/mutex.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" K_MEM_SLAB_DEFINE(cv2_mutex_slab, sizeof(struct cv2_mutex), diff --git a/lib/cmsis_rtos_v2/semaphore.c b/lib/cmsis_rtos_v2/semaphore.c index 7f35c6ca695..938401fd4ec 100644 --- a/lib/cmsis_rtos_v2/semaphore.c +++ b/lib/cmsis_rtos_v2/semaphore.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" K_MEM_SLAB_DEFINE(cv2_semaphore_slab, sizeof(struct cv2_sem), diff --git a/lib/cmsis_rtos_v2/thread.c b/lib/cmsis_rtos_v2/thread.c index e251e9eed81..f6839a3f0e3 100644 --- a/lib/cmsis_rtos_v2/thread.c +++ b/lib/cmsis_rtos_v2/thread.c @@ -4,10 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include +#include #include #include -#include -#include #include #include #include "wrapper.h" diff --git a/lib/cmsis_rtos_v2/timer.c b/lib/cmsis_rtos_v2/timer.c index abb5e95ba6a..2508e3ec7c2 100644 --- a/lib/cmsis_rtos_v2/timer.c +++ b/lib/cmsis_rtos_v2/timer.c @@ -4,7 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include "wrapper.h" #define ACTIVE 1 diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index fedbecacf69..d0c7070edc1 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index 5d44cf8a792..77d4c4b815f 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -23,4 +23,9 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC pthread_key.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c) zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include +) + zephyr_library_link_libraries(posix_subsys) diff --git a/scripts/gen_relocate_app.py b/scripts/gen_relocate_app.py index 85e13d49c2f..4afa7b55d32 100644 --- a/scripts/gen_relocate_app.py +++ b/scripts/gen_relocate_app.py @@ -99,6 +99,7 @@ SOURCE_CODE_INCLUDES = """ #include #include #include +#include """ EXTERN_LINKER_VAR_DECLARATION = """ diff --git a/soc/arm/atmel_sam/sam3x/soc.c b/soc/arm/atmel_sam/sam3x/soc.c index 6a04b348031..f71a2563a85 100644 --- a/soc/arm/atmel_sam/sam3x/soc.c +++ b/soc/arm/atmel_sam/sam3x/soc.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include /* * PLL clock = Main * (MULA + 1) / DIVA diff --git a/soc/arm/atmel_sam/sam4s/soc.c b/soc/arm/atmel_sam/sam4s/soc.c index ec431179c56..99e75e3fa25 100644 --- a/soc/arm/atmel_sam/sam4s/soc.c +++ b/soc/arm/atmel_sam/sam4s/soc.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include /** * @brief Setup various clock on SoC at boot time. diff --git a/soc/arm/atmel_sam/same70/soc.c b/soc/arm/atmel_sam/same70/soc.c index 3da8cc9fbf0..c6a521d92cf 100644 --- a/soc/arm/atmel_sam/same70/soc.c +++ b/soc/arm/atmel_sam/same70/soc.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #define LOG_LEVEL CONFIG_SOC_LOG_LEVEL diff --git a/soc/arm/atmel_sam0/common/soc_samd2x.c b/soc/arm/atmel_sam0/common/soc_samd2x.c index 4c9db13b097..7532aaa5ab0 100644 --- a/soc/arm/atmel_sam0/common/soc_samd2x.c +++ b/soc/arm/atmel_sam0/common/soc_samd2x.c @@ -10,7 +10,7 @@ */ #include -#include +#include #include #include #include diff --git a/soc/arm/cypress/psoc6/soc.c b/soc/arm/cypress/psoc6/soc.c index 3db3da9d5d2..a9f47970f86 100644 --- a/soc/arm/cypress/psoc6/soc.c +++ b/soc/arm/cypress/psoc6/soc.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "cy_syslib.h" #include "cy_gpio.h" diff --git a/soc/arm/microchip_mec/mec1501/soc.c b/soc/arm/microchip_mec/mec1501/soc.c index 22168cbe5c3..e06ad836106 100644 --- a/soc/arm/microchip_mec/mec1501/soc.c +++ b/soc/arm/microchip_mec/mec1501/soc.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include /* diff --git a/soc/arm/nordic_nrf/nrf51/CMakeLists.txt b/soc/arm/nordic_nrf/nrf51/CMakeLists.txt index 9dd6e2d818b..a657548eef5 100644 --- a/soc/arm/nordic_nrf/nrf51/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf51/CMakeLists.txt @@ -1,9 +1,16 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( +zephyr_library() + +zephyr_library_sources( soc.c ) -zephyr_sources_ifdef(CONFIG_SYS_POWER_MANAGEMENT +zephyr_library_sources_ifdef(CONFIG_SYS_POWER_MANAGEMENT power.c ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include + ) diff --git a/soc/arm/nordic_nrf/nrf52/CMakeLists.txt b/soc/arm/nordic_nrf/nrf52/CMakeLists.txt index 28dcff51cac..8aaf65d1655 100644 --- a/soc/arm/nordic_nrf/nrf52/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf52/CMakeLists.txt @@ -1,17 +1,24 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( +zephyr_library() + +zephyr_library_sources( soc.c ) -zephyr_sources_ifdef(CONFIG_SYS_POWER_MANAGEMENT +zephyr_library_sources_ifdef(CONFIG_SYS_POWER_MANAGEMENT power.c ) -zephyr_sources_ifdef(CONFIG_ARM_MPU +zephyr_library_sources_ifdef(CONFIG_ARM_MPU mpu_regions.c ) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include + ) + if(CONFIG_SOC_NRF52832) if(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58) if(CONFIG_SPI_0_NRF_SPIM OR CONFIG_SPI_1_NRF_SPIM OR CONFIG_SPI_2_NRF_SPIM) diff --git a/soc/arm/nordic_nrf/nrf52/soc.c b/soc/arm/nordic_nrf/nrf52/soc.c index aac12e8f999..0dba393da8e 100644 --- a/soc/arm/nordic_nrf/nrf52/soc.c +++ b/soc/arm/nordic_nrf/nrf52/soc.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include diff --git a/soc/arm/nordic_nrf/nrf91/soc.c b/soc/arm/nordic_nrf/nrf91/soc.c index ec87222fd01..86cad4c635c 100644 --- a/soc/arm/nordic_nrf/nrf91/soc.c +++ b/soc/arm/nordic_nrf/nrf91/soc.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include diff --git a/soc/arm/nxp_imx/mcimx6x_m4/soc.c b/soc/arm/nxp_imx/mcimx6x_m4/soc.c index ee6425fa79e..d92fc7cd492 100644 --- a/soc/arm/nxp_imx/mcimx6x_m4/soc.c +++ b/soc/arm/nxp_imx/mcimx6x_m4/soc.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "wdog_imx.h" /* Initialize Resource Domain Controller. */ diff --git a/soc/arm/nxp_imx/rt/soc.c b/soc/arm/nxp_imx/rt/soc.c index e5e16ad92d2..0f43e0dad30 100644 --- a/soc/arm/nxp_imx/rt/soc.c +++ b/soc/arm/nxp_imx/rt/soc.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #if CONFIG_USB_DC_NXP_EHCI #include "usb_phy.h" diff --git a/soc/arm/nxp_kinetis/k2x/soc.c b/soc/arm/nxp_kinetis/k2x/soc.c index 1916c88c10e..8746fc486a6 100644 --- a/soc/arm/nxp_kinetis/k2x/soc.c +++ b/soc/arm/nxp_kinetis/k2x/soc.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #define PLLFLLSEL_MCGFLLCLK (0) #define PLLFLLSEL_MCGPLLCLK (1) diff --git a/soc/arm/nxp_kinetis/k6x/soc.c b/soc/arm/nxp_kinetis/k6x/soc.c index df6b2250322..6901fc0a166 100644 --- a/soc/arm/nxp_kinetis/k6x/soc.c +++ b/soc/arm/nxp_kinetis/k6x/soc.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #define PLLFLLSEL_MCGFLLCLK (0) #define PLLFLLSEL_MCGPLLCLK (1) diff --git a/soc/arm/nxp_kinetis/ke1xf/soc.c b/soc/arm/nxp_kinetis/ke1xf/soc.c index 017c235859e..9aaf8d75098 100644 --- a/soc/arm/nxp_kinetis/ke1xf/soc.c +++ b/soc/arm/nxp_kinetis/ke1xf/soc.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #define ASSERT_WITHIN_RANGE(val, min, max, str) \ BUILD_ASSERT_MSG(val >= min && val <= max, str) diff --git a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c index 961b9b9c07f..6a881b4b3b5 100644 --- a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c +++ b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #define PLLFLLSEL_MCGFLLCLK (0) #define PLLFLLSEL_MCGPLLCLK (1) diff --git a/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt b/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt index 2347dcb3a0c..6f78f98e39e 100644 --- a/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt +++ b/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt @@ -9,6 +9,11 @@ zephyr_library_sources(soc.c) zephyr_sources_ifdef(CONFIG_ARM_MPU arm_mpu_regions.c) +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) + if (CONFIG_SLAVE_CORE_MCUX) set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) string(CONFIGURE ${CONFIG_SLAVE_IMAGE_MCUX} core_m0_image) diff --git a/soc/arm/nxp_lpc/lpc55xxx/CMakeLists.txt b/soc/arm/nxp_lpc/lpc55xxx/CMakeLists.txt index 11b82e73d8e..9c635e05b2a 100644 --- a/soc/arm/nxp_lpc/lpc55xxx/CMakeLists.txt +++ b/soc/arm/nxp_lpc/lpc55xxx/CMakeLists.txt @@ -6,3 +6,8 @@ zephyr_library() zephyr_library_sources(soc.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/soc/arm/silabs_exx32/common/soc.c b/soc/arm/silabs_exx32/common/soc.c index aaeccb1e32b..6a8a274646b 100644 --- a/soc/arm/silabs_exx32/common/soc.c +++ b/soc/arm/silabs_exx32/common/soc.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include diff --git a/soc/arm/st_stm32/stm32f0/soc.c b/soc/arm/st_stm32/stm32f0/soc.c index 902b44ac231..1ddd24c178d 100644 --- a/soc/arm/st_stm32/stm32f0/soc.c +++ b/soc/arm/st_stm32/stm32f0/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/st_stm32/stm32f1/soc.c b/soc/arm/st_stm32/stm32f1/soc.c index aa83f741b70..b3129561a35 100644 --- a/soc/arm/st_stm32/stm32f1/soc.c +++ b/soc/arm/st_stm32/stm32f1/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32f2/soc.c b/soc/arm/st_stm32/stm32f2/soc.c index 61dd4421df8..0f2e13729f2 100644 --- a/soc/arm/st_stm32/stm32f2/soc.c +++ b/soc/arm/st_stm32/stm32f2/soc.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/st_stm32/stm32f3/soc.c b/soc/arm/st_stm32/stm32f3/soc.c index f70d15e4613..937d896d365 100644 --- a/soc/arm/st_stm32/stm32f3/soc.c +++ b/soc/arm/st_stm32/stm32f3/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32f4/soc.c b/soc/arm/st_stm32/stm32f4/soc.c index 335090870a6..bfd088aa2c9 100644 --- a/soc/arm/st_stm32/stm32f4/soc.c +++ b/soc/arm/st_stm32/stm32f4/soc.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32f7/soc.c b/soc/arm/st_stm32/stm32f7/soc.c index f93d9b6be23..01f14d5ea26 100644 --- a/soc/arm/st_stm32/stm32f7/soc.c +++ b/soc/arm/st_stm32/stm32f7/soc.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32g0/soc.c b/soc/arm/st_stm32/stm32g0/soc.c index a85413fb729..b67f5c7a1e0 100644 --- a/soc/arm/st_stm32/stm32g0/soc.c +++ b/soc/arm/st_stm32/stm32g0/soc.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/st_stm32/stm32g4/soc.c b/soc/arm/st_stm32/stm32g4/soc.c index 3a289917eea..ea7d7c91682 100644 --- a/soc/arm/st_stm32/stm32g4/soc.c +++ b/soc/arm/st_stm32/stm32g4/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32h7/soc_m4.c b/soc/arm/st_stm32/stm32h7/soc_m4.c index d1f744af373..2c2866f0cc5 100644 --- a/soc/arm/st_stm32/stm32h7/soc_m4.c +++ b/soc/arm/st_stm32/stm32h7/soc_m4.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #if defined(CONFIG_STM32H7_BOOT_CM4_CM7) void stm32h7_m4_boot_stop(void) diff --git a/soc/arm/st_stm32/stm32h7/soc_m7.c b/soc/arm/st_stm32/stm32h7/soc_m7.c index ae6215163bd..09e9289767e 100644 --- a/soc/arm/st_stm32/stm32h7/soc_m7.c +++ b/soc/arm/st_stm32/stm32h7/soc_m7.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #if defined(CONFIG_STM32H7_DUAL_CORE) static int stm32h7_m4_wakeup(struct device *arg) diff --git a/soc/arm/st_stm32/stm32l0/soc.c b/soc/arm/st_stm32/stm32l0/soc.c index fe8619dc7ec..6f1f4d77afc 100644 --- a/soc/arm/st_stm32/stm32l0/soc.c +++ b/soc/arm/st_stm32/stm32l0/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/st_stm32/stm32l1/soc.c b/soc/arm/st_stm32/stm32l1/soc.c index ef08ec698f2..6f5ea3dc233 100644 --- a/soc/arm/st_stm32/stm32l1/soc.c +++ b/soc/arm/st_stm32/stm32l1/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/soc/arm/st_stm32/stm32l4/soc.c b/soc/arm/st_stm32/stm32l4/soc.c index 45f3e7b865f..e2e0d86b34e 100644 --- a/soc/arm/st_stm32/stm32l4/soc.c +++ b/soc/arm/st_stm32/stm32l4/soc.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32mp1/soc.c b/soc/arm/st_stm32/stm32mp1/soc.c index 870b1052a7e..b83d24b85b3 100644 --- a/soc/arm/st_stm32/stm32mp1/soc.c +++ b/soc/arm/st_stm32/stm32mp1/soc.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/st_stm32/stm32wb/soc.c b/soc/arm/st_stm32/stm32wb/soc.c index 359389bee29..9c0956289ad 100644 --- a/soc/arm/st_stm32/stm32wb/soc.c +++ b/soc/arm/st_stm32/stm32wb/soc.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include /** * @brief Perform basic hardware initialization at boot. diff --git a/soc/arm/ti_lm3s6965/CMakeLists.txt b/soc/arm/ti_lm3s6965/CMakeLists.txt index 3b889a247cb..1701f41c83f 100644 --- a/soc/arm/ti_lm3s6965/CMakeLists.txt +++ b/soc/arm/ti_lm3s6965/CMakeLists.txt @@ -1,8 +1,15 @@ # SPDX-License-Identifier: Apache-2.0 -zephyr_sources( +zephyr_library() + +zephyr_library_sources( soc.c soc_config.c reboot.S sys_arch_reboot.c ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include + ) diff --git a/soc/arm/ti_lm3s6965/soc.h b/soc/arm/ti_lm3s6965/soc.h index aa335c00239..2338f9106ae 100644 --- a/soc/arm/ti_lm3s6965/soc.h +++ b/soc/arm/ti_lm3s6965/soc.h @@ -67,10 +67,6 @@ #ifndef _ASMLANGUAGE -#include -#include -#include - #endif /* !_ASMLANGUAGE */ #endif /* _BOARD__H_ */ diff --git a/soc/posix/inf_clock/CMakeLists.txt b/soc/posix/inf_clock/CMakeLists.txt index 326f584b3f1..276b2fb7875 100644 --- a/soc/posix/inf_clock/CMakeLists.txt +++ b/soc/posix/inf_clock/CMakeLists.txt @@ -1,7 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() + zephyr_library_compile_definitions(NO_POSIX_CHEATS) + zephyr_library_sources( soc.c ) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/posix/include + ) diff --git a/soc/posix/inf_clock/posix_soc.h b/soc/posix/inf_clock/posix_soc.h index ade53b4ba1a..4a5b972e280 100644 --- a/soc/posix/inf_clock/posix_soc.h +++ b/soc/posix/inf_clock/posix_soc.h @@ -7,7 +7,7 @@ #ifndef _POSIX_POSIX_SOC_INF_CLOCK_H #define _POSIX_POSIX_SOC_INF_CLOCK_H -#include "posix_soc_if.h" +#include #ifdef __cplusplus extern "C" { diff --git a/soc/posix/inf_clock/soc.c b/soc/posix/inf_clock/soc.c index 590ce6fa8f5..93451016e8c 100644 --- a/soc/posix/inf_clock/soc.c +++ b/soc/posix/inf_clock/soc.c @@ -28,7 +28,7 @@ #include #include #include -#include "posix_soc_if.h" +#include #include "posix_soc.h" #include "posix_board_if.h" #include "posix_core.h" diff --git a/subsys/debug/openocd.c b/subsys/debug/openocd.c index 15bd2ad9b87..5eb906c87fa 100644 --- a/subsys/debug/openocd.c +++ b/subsys/debug/openocd.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #define OPENOCD_UNIMPLEMENTED 0xffffffff diff --git a/subsys/debug/tracing/CMakeLists.txt b/subsys/debug/tracing/CMakeLists.txt index 96163eb19fc..b283fbb1569 100644 --- a/subsys/debug/tracing/CMakeLists.txt +++ b/subsys/debug/tracing/CMakeLists.txt @@ -1,16 +1,27 @@ # SPDX-License-Identifier: Apache-2.0 +if(CONFIG_SEGGER_SYSTEMVIEW OR CONFIG_TRACING_CPU_STATS) + zephyr_library() + + zephyr_library_sources_ifdef( + CONFIG_SEGGER_SYSTEMVIEW + sysview_config.c + sysview.c + ) + + zephyr_library_sources_ifdef( + CONFIG_TRACING_CPU_STATS + cpu_stats.c + ) + + if(CONFIG_TRACING) + zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) + endif() +endif() + zephyr_include_directories_ifdef(CONFIG_TRACING include) -zephyr_sources_ifdef( - CONFIG_SEGGER_SYSTEMVIEW - sysview_config.c - sysview.c - ) - -zephyr_sources_ifdef( - CONFIG_TRACING_CPU_STATS - cpu_stats.c - ) - add_subdirectory_ifdef(CONFIG_TRACING_CTF ctf) diff --git a/subsys/debug/tracing/ctf/CMakeLists.txt b/subsys/debug/tracing/ctf/CMakeLists.txt index 14201044e7c..0e7cf129f69 100644 --- a/subsys/debug/tracing/ctf/CMakeLists.txt +++ b/subsys/debug/tracing/ctf/CMakeLists.txt @@ -1,6 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 +zephyr_library() + +zephyr_library_sources(ctf_top.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) + zephyr_include_directories(.) -zephyr_sources(ctf_top.c) add_subdirectory_ifdef(CONFIG_TRACING_CTF_BOTTOM_POSIX bottoms/posix) diff --git a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c b/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c index 7f97b5a1f06..4d28f7501c6 100644 --- a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c +++ b/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c @@ -7,7 +7,7 @@ #include "ctf_bottom.h" #include "soc.h" #include "cmdline.h" /* native_posix command line options header */ -#include "posix_trace.h" +#include ctf_bottom_ctx_t ctf_bottom; diff --git a/subsys/debug/tracing/include/tracing_sysview.h b/subsys/debug/tracing/include/tracing_sysview.h index 02efcc53413..a41338b0a1f 100644 --- a/subsys/debug/tracing/include/tracing_sysview.h +++ b/subsys/debug/tracing/include/tracing_sysview.h @@ -7,7 +7,6 @@ #define _TRACE_SYSVIEW_H #include #include -#include #include #include diff --git a/subsys/logging/log_backend_native_posix.c b/subsys/logging/log_backend_native_posix.c index b26457eeee5..106fa82fb7d 100644 --- a/subsys/logging/log_backend_native_posix.c +++ b/subsys/logging/log_backend_native_posix.c @@ -12,7 +12,7 @@ #include #include #include -#include "posix_trace.h" +#include #define _STDOUT_BUF_SIZE 256 static char stdout_buff[_STDOUT_BUF_SIZE]; diff --git a/subsys/net/ip/CMakeLists.txt b/subsys/net/ip/CMakeLists.txt index 9795b3148ee..b795750c2fa 100644 --- a/subsys/net/ip/CMakeLists.txt +++ b/subsys/net/ip/CMakeLists.txt @@ -44,6 +44,11 @@ zephyr_library_sources_ifdef(CONFIG_NET_SOCKETS_CAN connection.c zephyr_library_sources_ifdef(CONFIG_NET_PROMISCUOUS_MODE promiscuous.c) endif() +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) + if(CONFIG_NET_SHELL) zephyr_library_sources(net_shell.c) zephyr_library_include_directories(. ${ZEPHYR_BASE}/subsys/net/l2) diff --git a/subsys/testsuite/ztest/include/arch/cpu.h b/subsys/testsuite/ztest/include/arch/cpu.h index 90300ca7130..56235b85d0b 100644 --- a/subsys/testsuite/ztest/include/arch/cpu.h +++ b/subsys/testsuite/ztest/include/arch/cpu.h @@ -6,6 +6,18 @@ /* This file exists as a hack around Zephyr's dependencies */ +/* Architecture thread structure */ +struct _callee_saved { +}; + +typedef struct _callee_saved _callee_saved_t; + +struct _thread_arch { +}; + +typedef struct _thread_arch _thread_arch_t; + +/* Architecture functions */ static inline u32_t z_arch_k_cycle_get_32(void) { return 0; @@ -26,7 +38,7 @@ static inline bool z_arch_irq_unlocked(unsigned int key) return 0; } -#include +#include #endif /* ZEPHYR_SUBSYS_TESTSUITE_ZTEST_INCLUDE_ARCH_CPU_H */ diff --git a/subsys/testsuite/ztest/include/kernel_arch_thread.h b/subsys/testsuite/ztest/include/kernel_arch_thread.h deleted file mode 100644 index 0122f42c965..00000000000 --- a/subsys/testsuite/ztest/include/kernel_arch_thread.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Per-arch thread definition - * - * This file contains definitions for - * - * struct _thread_arch - * struct _callee_saved - * - * necessary to instantiate instances of struct k_thread. - */ - - -#ifndef _kernel_arch_thread__h_ -#define _kernel_arch_thread__h_ - -#ifndef _ASMLANGUAGE - -struct _callee_saved { -}; - -typedef struct _callee_saved _callee_saved_t; - -struct _thread_arch { -}; - -typedef struct _thread_arch _thread_arch_t; - -#endif /* _ASMLANGUAGE */ - -#endif /* _kernel_arch_thread__h_ */ - diff --git a/subsys/testsuite/ztest/include/ztest.h b/subsys/testsuite/ztest/include/ztest.h index 344cc63a694..e865b3ee207 100644 --- a/subsys/testsuite/ztest/include/ztest.h +++ b/subsys/testsuite/ztest/include/ztest.h @@ -35,6 +35,7 @@ #define CONFIG_NUM_COOP_PRIORITIES 16 #define CONFIG_COOP_ENABLED 1 #define CONFIG_PREEMPT_ENABLED 1 +#define CONFIG_MP_NUM_CPUS 1 #define CONFIG_SYS_CLOCK_TICKS_PER_SEC 100 #define CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC 10000000 /* FIXME: Properly integrate with Zephyr's arch specific code */ diff --git a/tests/arch/arm/arm_thread_swap/CMakeLists.txt b/tests/arch/arm/arm_thread_swap/CMakeLists.txt index 4763876eace..fa7afe41d1d 100644 --- a/tests/arch/arm/arm_thread_swap/CMakeLists.txt +++ b/tests/arch/arm/arm_thread_swap/CMakeLists.txt @@ -6,3 +6,8 @@ project(arm_swap) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/arm/include +) diff --git a/tests/arch/x86/static_idt/CMakeLists.txt b/tests/arch/x86/static_idt/CMakeLists.txt index a5214b0e8b2..1344355183b 100644 --- a/tests/arch/x86/static_idt/CMakeLists.txt +++ b/tests/arch/x86/static_idt/CMakeLists.txt @@ -8,3 +8,8 @@ enable_language(C ASM) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources} src/test_stubs.S) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/arch/x86/static_idt/src/main.c b/tests/arch/x86/static_idt/src/main.c index 82f1140b8fe..9441df260f5 100644 --- a/tests/arch/x86/static_idt/src/main.c +++ b/tests/arch/x86/static_idt/src/main.c @@ -16,7 +16,7 @@ #include #include -#include +#include #if defined(__GNUC__) #include "test_asm_inline_gcc.h" #else diff --git a/tests/arch/x86/x86_mmu_api/src/userbuffer_validate.c b/tests/arch/x86/x86_mmu_api/src/userbuffer_validate.c index 126f0031363..adc711dabbd 100644 --- a/tests/arch/x86/x86_mmu_api/src/userbuffer_validate.c +++ b/tests/arch/x86/x86_mmu_api/src/userbuffer_validate.c @@ -9,7 +9,6 @@ #include #include #include -#include #define SKIP_SIZE 5 #define BUFF_SIZE 10 diff --git a/tests/benchmarks/boot_time/CMakeLists.txt b/tests/benchmarks/boot_time/CMakeLists.txt index 260f4615bab..2de72b4da52 100644 --- a/tests/benchmarks/boot_time/CMakeLists.txt +++ b/tests/benchmarks/boot_time/CMakeLists.txt @@ -6,3 +6,8 @@ project(boot_time) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/benchmarks/sched/CMakeLists.txt b/tests/benchmarks/sched/CMakeLists.txt index 282e113d860..720f39f1f61 100644 --- a/tests/benchmarks/sched/CMakeLists.txt +++ b/tests/benchmarks/sched/CMakeLists.txt @@ -5,3 +5,8 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(sched_bench) target_sources(app PRIVATE src/main.c) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/benchmarks/timing_info/CMakeLists.txt b/tests/benchmarks/timing_info/CMakeLists.txt index 61098767407..5de4e17c9f8 100644 --- a/tests/benchmarks/timing_info/CMakeLists.txt +++ b/tests/benchmarks/timing_info/CMakeLists.txt @@ -7,3 +7,8 @@ project(timing_info) FILE(GLOB app_sources src/[^u]*.c) target_sources(app PRIVATE ${app_sources}) target_sources_ifdef(CONFIG_USERSPACE app PRIVATE src/userspace_bench.c) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/boards/altera_max10/msgdma/CMakeLists.txt b/tests/boards/altera_max10/msgdma/CMakeLists.txt index 38c813f1abd..35a7f914044 100644 --- a/tests/boards/altera_max10/msgdma/CMakeLists.txt +++ b/tests/boards/altera_max10/msgdma/CMakeLists.txt @@ -6,3 +6,8 @@ project(msgdma) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/boards/altera_max10/msgdma/src/dma.c b/tests/boards/altera_max10/msgdma/src/dma.c index 500225c3c06..2d5e0d9a0b3 100644 --- a/tests/boards/altera_max10/msgdma/src/dma.c +++ b/tests/boards/altera_max10/msgdma/src/dma.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/tests/crypto/rand32/CMakeLists.txt b/tests/crypto/rand32/CMakeLists.txt index 5a51e1b4801..0c3c4eefcd5 100644 --- a/tests/crypto/rand32/CMakeLists.txt +++ b/tests/crypto/rand32/CMakeLists.txt @@ -8,3 +8,8 @@ zephyr_library_include_directories(${ZEPHYR_BASE}/kernel/include/) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/fatal/CMakeLists.txt b/tests/kernel/fatal/CMakeLists.txt index 2282a0c8c8f..dd6b855f4f2 100644 --- a/tests/kernel/fatal/CMakeLists.txt +++ b/tests/kernel/fatal/CMakeLists.txt @@ -6,3 +6,8 @@ project(fatal) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/fifo/fifo_timeout/src/main.c b/tests/kernel/fifo/fifo_timeout/src/main.c index 8b6b38811d5..a6baec355f6 100644 --- a/tests/kernel/fifo/fifo_timeout/src/main.c +++ b/tests/kernel/fifo/fifo_timeout/src/main.c @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt b/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt index b0658f422ca..e8503cddeb9 100644 --- a/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt +++ b/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt @@ -6,3 +6,8 @@ project(mem_pool_api) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/mem_pool/mem_pool_api/src/test_mpool_api.c b/tests/kernel/mem_pool/mem_pool_api/src/test_mpool_api.c index 1bd002d33b2..f8f12a13ddc 100644 --- a/tests/kernel/mem_pool/mem_pool_api/src/test_mpool_api.c +++ b/tests/kernel/mem_pool/mem_pool_api/src/test_mpool_api.c @@ -6,8 +6,8 @@ #include #include -#include "test_mpool.h" #include +#include "test_mpool.h" /** TESTPOINT: Statically define and initialize a memory pool*/ K_MEM_POOL_DEFINE(kmpool, BLK_SIZE_MIN, BLK_SIZE_MAX, BLK_NUM_MAX, BLK_ALIGN); diff --git a/tests/kernel/mem_protect/obj_validation/CMakeLists.txt b/tests/kernel/mem_protect/obj_validation/CMakeLists.txt index 038cb3451c4..1021b6a1b35 100644 --- a/tests/kernel/mem_protect/obj_validation/CMakeLists.txt +++ b/tests/kernel/mem_protect/obj_validation/CMakeLists.txt @@ -6,3 +6,8 @@ project(obj_validation) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/sched/schedule_api/CMakeLists.txt b/tests/kernel/sched/schedule_api/CMakeLists.txt index c0f153598db..85d46ba7980 100644 --- a/tests/kernel/sched/schedule_api/CMakeLists.txt +++ b/tests/kernel/sched/schedule_api/CMakeLists.txt @@ -6,3 +6,8 @@ project(schedule_api) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/smp/CMakeLists.txt b/tests/kernel/smp/CMakeLists.txt index 5057011aa12..6d4b51481c0 100644 --- a/tests/kernel/smp/CMakeLists.txt +++ b/tests/kernel/smp/CMakeLists.txt @@ -5,3 +5,8 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(smp) target_sources(app PRIVATE src/main.c) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/kernel/threads/thread_apis/CMakeLists.txt b/tests/kernel/threads/thread_apis/CMakeLists.txt index f004ae28f33..d95357873af 100644 --- a/tests/kernel/threads/thread_apis/CMakeLists.txt +++ b/tests/kernel/threads/thread_apis/CMakeLists.txt @@ -6,3 +6,8 @@ project(thread_apis) FILE(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) + +target_include_directories(app PRIVATE + ${ZEPHYR_BASE}/kernel/include + ${ZEPHYR_BASE}/arch/${ARCH}/include + ) diff --git a/tests/lib/mem_alloc/src/main.c b/tests/lib/mem_alloc/src/main.c index 4ffef717b12..a7dc6dffd5b 100644 --- a/tests/lib/mem_alloc/src/main.c +++ b/tests/lib/mem_alloc/src/main.c @@ -20,7 +20,6 @@ #include #include #include -#include #define BUF_LEN 10