diff --git a/arch/arm/core/cortex_m/fault.c b/arch/arm/core/cortex_m/fault.c index 62c2e036d33c..8cab8f429c4f 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_r/fault.c b/arch/arm/core/cortex_r/fault.c index 7b500b4a8647..3e20ee66bd5d 100644 --- a/arch/arm/core/cortex_r/fault.c +++ b/arch/arm/core/cortex_r/fault.c @@ -5,7 +5,7 @@ */ #include -#include +#include /** * diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c index 86a19c8493d2..984d636c1802 100644 --- a/arch/arm/core/fatal.c +++ b/arch/arm/core/fatal.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include LOG_MODULE_DECLARE(os); diff --git a/arch/arm/core/offsets/offsets.c b/arch/arm/core/offsets/offsets.c index b58945c07b62..7305d0daaf2e 100644 --- a/arch/arm/core/offsets/offsets.c +++ b/arch/arm/core/offsets/offsets.c @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include diff --git a/arch/arm/core/swap.c b/arch/arm/core/swap.c index 5afb8294ee80..ec26135a0d9b 100644 --- a/arch/arm/core/swap.c +++ b/arch/arm/core/swap.c @@ -6,7 +6,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 fe0e55e27913..ffb8c4e57f51 100644 --- a/arch/arm/core/thread.c +++ b/arch/arm/core/thread.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #ifdef CONFIG_USERSPACE diff --git a/arch/arm/include/kernel_arch_func.h b/arch/arm/include/kernel_arch_func.h index f11204baf53b..8397c846a364 100644 --- a/arch/arm/include/kernel_arch_func.h +++ b/arch/arm/include/kernel_arch_func.h @@ -22,6 +22,8 @@ #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/nios2/core/crt0.S b/arch/nios2/core/crt0.S index b9c483659fdd..f698b882c491 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 5f67dc943efa..6090753ba6ec 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/prep_c.c b/arch/nios2/core/prep_c.c index 1345d176381c..6e15fed1ae76 100644 --- a/arch/nios2/core/prep_c.c +++ b/arch/nios2/core/prep_c.c @@ -16,11 +16,7 @@ * initialization is performed. */ -#include -#include -#include -#include -#include +#include /** * diff --git a/arch/nios2/core/reset.S b/arch/nios2/core/reset.S index 8c2719cec22f..968f7d91890f 100644 --- a/arch/nios2/core/reset.S +++ b/arch/nios2/core/reset.S @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include -#include +#include #include +#include GTEXT(__start) diff --git a/arch/nios2/core/swap.S b/arch/nios2/core/swap.S index 7d43520c1e80..c4f2ccf1171a 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/include/kernel_arch_func.h b/arch/nios2/include/kernel_arch_func.h index 6ff1b38c17f0..84ab183b5a01 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/riscv/core/irq_manage.c b/arch/riscv/core/irq_manage.c index 38fb46579ad2..b2ccba75cd8c 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 6fc5613bcee8..78be5b3d3461 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/reset.S b/arch/riscv/core/reset.S index 7e3d285e10ad..7f416bdf64af 100644 --- a/arch/riscv/core/reset.S +++ b/arch/riscv/core/reset.S @@ -5,7 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include /* exports */ GTEXT(__initialize) diff --git a/arch/riscv/core/swap.S b/arch/riscv/core/swap.S index 523b22678181..c81910a83489 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/include/kernel_arch_func.h b/arch/riscv/include/kernel_arch_func.h index dfaa1cb3f3a9..bca8f1d79592 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/ia32/cache_s.S b/arch/x86/core/ia32/cache_s.S index 95c0923ec72d..26d72b84a3da 100644 --- a/arch/x86/core/ia32/cache_s.S +++ b/arch/x86/core/ia32/cache_s.S @@ -10,6 +10,8 @@ * This module contains functions for manipulating caches. */ +#include +#include #include #ifndef CONFIG_CLFLUSH_INSTRUCTION_SUPPORTED diff --git a/arch/x86/core/ia32/crt0.S b/arch/x86/core/ia32/crt0.S index 1f431489bfe2..388df72921ed 100644 --- a/arch/x86/core/ia32/crt0.S +++ b/arch/x86/core/ia32/crt0.S @@ -11,6 +11,8 @@ * after having been loaded into RAM. */ +#include +#include #include #include #include diff --git a/arch/x86/core/ia32/excstub.S b/arch/x86/core/ia32/excstub.S index 15828dafeb74..987129602257 100644 --- a/arch/x86/core/ia32/excstub.S +++ b/arch/x86/core/ia32/excstub.S @@ -14,10 +14,11 @@ * and exiting a C exception handler. */ -#include +#include +#include +#include #include #include /* For MK_ISR_NAME */ -#include /* exports (internal APIs) */ diff --git a/arch/x86/core/ia32/fatal.c b/arch/x86/core/ia32/fatal.c index b26a41d301b1..edb9ab39fddc 100644 --- a/arch/x86/core/ia32/fatal.c +++ b/arch/x86/core/ia32/fatal.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include diff --git a/arch/x86/core/ia32/float.c b/arch/x86/core/ia32/float.c index 75741fb46046..e284e12a34be 100644 --- a/arch/x86/core/ia32/float.c +++ b/arch/x86/core/ia32/float.c @@ -43,8 +43,7 @@ * to enable FP register sharing on its behalf. */ -#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 963a2e48e299..ac4bb64da20d 100644 --- a/arch/x86/core/ia32/intstub.S +++ b/arch/x86/core/ia32/intstub.S @@ -14,9 +14,10 @@ * entering and exiting a C interrupt handler. */ -#include -#include +#include +#include #include +#include #include #include diff --git a/arch/x86/core/ia32/swap.S b/arch/x86/core/ia32/swap.S index 20147af93f9a..2f526e565dc9 100644 --- a/arch/x86/core/ia32/swap.S +++ b/arch/x86/core/ia32/swap.S @@ -11,9 +11,12 @@ * This module implements the z_arch_swap() routine for the IA-32 architecture. */ -#include -#include +#include +#include #include +#include +#include +#include /* exports (internal APIs) */ diff --git a/arch/x86/core/ia32/userspace.S b/arch/x86/core/ia32/userspace.S index ba6aced61f61..0fd529c0a0de 100644 --- a/arch/x86/core/ia32/userspace.S +++ b/arch/x86/core/ia32/userspace.S @@ -4,10 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include +#include #include #include -#include #include /* Exports */ diff --git a/arch/x86/core/ia32/x86_mmu.c b/arch/x86/core/ia32/x86_mmu.c index 6bd0fca08905..f109b0c21551 100644 --- a/arch/x86/core/ia32/x86_mmu.c +++ b/arch/x86/core/ia32/x86_mmu.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index f0026f850c63..c3273a2668c3 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include #include #include diff --git a/arch/x86/include/ia32/kernel_arch_func.h b/arch/x86/include/ia32/kernel_arch_func.h index 112ae2777266..541f1c9f8968 100644 --- a/arch/x86/include/ia32/kernel_arch_func.h +++ b/arch/x86/include/ia32/kernel_arch_func.h @@ -12,7 +12,7 @@ #ifndef _ASMLANGUAGE -#include /* For size_t */ +#include #ifdef __cplusplus extern "C" { diff --git a/arch/x86/include/intel64/kernel_arch_func.h b/arch/x86/include/intel64/kernel_arch_func.h index 5b58cdd64fbf..69f26efe539f 100644 --- a/arch/x86/include/intel64/kernel_arch_func.h +++ b/arch/x86/include/intel64/kernel_arch_func.h @@ -6,7 +6,7 @@ #ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_ #define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_ -#include +#include #ifndef _ASMLANGUAGE diff --git a/arch/xtensa/core/offsets/offsets.c b/arch/xtensa/core/offsets/offsets.c index 8ff8ce3241b5..d3470d34dab1 100644 --- a/arch/xtensa/core/offsets/offsets.c +++ b/arch/xtensa/core/offsets/offsets.c @@ -27,8 +27,8 @@ /* list of headers that define whose structure offsets will be generated */ +#include #include - #include /* Xtensa-specific k_thread structure member offsets */ diff --git a/include/arch/arm/irq.h b/include/arch/arm/irq.h index 3ef252ba6748..2abea4a8d4ca 100644 --- a/include/arch/arm/irq.h +++ b/include/arch/arm/irq.h @@ -14,6 +14,7 @@ #ifndef ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_IRQ_H_ #define ZEPHYR_INCLUDE_ARCH_ARM_CORTEX_M_IRQ_H_ +#include #include #include #include diff --git a/include/sys/mutex.h b/include/sys/mutex.h index 9d97a4199031..55afbdd45580 100644 --- a/include/sys/mutex.h +++ b/include/sys/mutex.h @@ -110,7 +110,7 @@ static inline int sys_mutex_unlock(struct sys_mutex *mutex) #else #include -#include +#include struct sys_mutex { struct k_mutex kernel_mutex; diff --git a/kernel/errno.c b/kernel/errno.c index e23593785fc2..1f2c42dc2e3e 100644 --- a/kernel/errno.c +++ b/kernel/errno.c @@ -12,8 +12,8 @@ * context switching. */ -#include -#include +#include +#include /* * Define _k_neg_eagain for use in assembly files as errno.h is diff --git a/kernel/include/kernel_arch.h b/kernel/include/kernel_arch.h new file mode 100644 index 000000000000..e89bac5a144a --- /dev/null +++ b/kernel/include/kernel_arch.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Wind River Systems, Inc. + * Copyright (c) 2019 Stephanos Ioannidis + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_KERNEL_INCLUDE_KERNEL_ARCH_H_ +#define ZEPHYR_KERNEL_INCLUDE_KERNEL_ARCH_H_ + +#if !defined(_ASMLANGUAGE) + +#include +#include + +#include +#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_ARCH_H_ */ diff --git a/kernel/include/kernel_structs.h b/kernel/include/kernel_structs.h index 49b8f3d910e5..2c94191e212c 100644 --- a/kernel/include/kernel_structs.h +++ b/kernel/include/kernel_structs.h @@ -7,15 +7,12 @@ #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 -#include #endif #define K_NUM_PRIORITIES \ @@ -66,10 +63,10 @@ /* highest value of _thread_base.preempt at which a thread is preemptible */ #define _PREEMPT_THRESHOLD (_NON_PREEMPT_THRESHOLD - 1) -#include - #if !defined(_ASMLANGUAGE) +struct k_thread; + struct _ready_q { #ifndef CONFIG_SMP /* always contains next thread to run: cannot be NULL */ @@ -180,6 +177,8 @@ typedef struct z_kernel _kernel_t; extern struct z_kernel _kernel; #ifdef CONFIG_SMP +static inline struct _cpu *z_arch_curr_cpu(void); + #define _current_cpu (z_arch_curr_cpu()) #define _current (z_arch_curr_cpu()->current) #else @@ -189,77 +188,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 /* !_ASMLANGUAGE */ #endif /* ZEPHYR_KERNEL_INCLUDE_KERNEL_STRUCTS_H_ */ diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index 48eb70cd229d..127cc8184c92 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -7,7 +7,7 @@ #ifndef ZEPHYR_KERNEL_INCLUDE_KSCHED_H_ #define ZEPHYR_KERNEL_INCLUDE_KSCHED_H_ -#include +#include #include #include #include diff --git a/kernel/thread.c b/kernel/thread.c index 0642d0f10fb8..0df0fe08cb3e 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -29,6 +29,7 @@ #include #include #include +#include #include static struct k_spinlock lock; diff --git a/kernel/work_q.c b/kernel/work_q.c index f050a437ab81..88ee61e9771a 100644 --- a/kernel/work_q.c +++ b/kernel/work_q.c @@ -11,6 +11,7 @@ * Workqueue support functions */ +#include #include #include #include diff --git a/subsys/debug/openocd.c b/subsys/debug/openocd.c index 15bd2ad9b874..539ea3006ad0 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/tests/arch/x86/static_idt/src/main.c b/tests/arch/x86/static_idt/src/main.c index 82f1140b8fe6..3f27c3ce4382 100644 --- a/tests/arch/x86/static_idt/src/main.c +++ b/tests/arch/x86/static_idt/src/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/tests/kernel/context/src/main.c b/tests/kernel/context/src/main.c index b35802f00db0..84944f352775 100644 --- a/tests/kernel/context/src/main.c +++ b/tests/kernel/context/src/main.c @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include