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 <root@stephanos.io>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5773cb1..90e0d4f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,8 +73,6 @@
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_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 da7f5e4..f3f4c72 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 19c83e0..9a1db81 100644
--- a/arch/arc/core/fast_irq.S
+++ b/arch/arc/core/fast_irq.S
@@ -16,6 +16,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
+#include <linker/sections.h>
#include <arch/cpu.h>
#include <swap_macros.h>
diff --git a/arch/arc/core/fatal.c b/arch/arc/core/fatal.c
index c14a0e2..774b429 100644
--- a/arch/arc/core/fatal.c
+++ b/arch/arc/core/fatal.c
@@ -12,9 +12,8 @@
* ARCv2 CPUs.
*/
-#include <kernel_structs.h>
+#include <kernel.h>
#include <offsets_short.h>
-#include <toolchain.h>
#include <arch/cpu.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(os);
diff --git a/arch/arc/core/fault.c b/arch/arc/core/fault.c
index 2604e83..8961b96 100644
--- a/arch/arc/core/fault.c
+++ b/arch/arc/core/fault.c
@@ -16,6 +16,7 @@
#include <inttypes.h>
#include <kernel.h>
+#include <kernel_internal.h>
#include <kernel_structs.h>
#include <exc_handle.h>
#include <logging/log.h>
diff --git a/arch/arc/core/mpu/CMakeLists.txt b/arch/arc/core/mpu/CMakeLists.txt
index a81e4eb..880c7d3 100644
--- a/arch/arc/core/mpu/CMakeLists.txt
+++ b/arch/arc/core/mpu/CMakeLists.txt
@@ -4,3 +4,8 @@
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 6e9289f..18c07ca 100644
--- a/arch/arc/core/offsets/offsets.c
+++ b/arch/arc/core/offsets/offsets.c
@@ -22,8 +22,9 @@
* completeness.
*/
+#include <kernel.h>
+#include <kernel_arch_data.h>
#include <gen_offset.h>
-#include <kernel_structs.h>
#include <kernel_offsets.h>
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 42fe958..b7c594c 100644
--- a/arch/arc/core/regular_irq.S
+++ b/arch/arc/core/regular_irq.S
@@ -17,6 +17,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
+#include <linker/sections.h>
#include <arch/cpu.h>
#include <swap_macros.h>
diff --git a/arch/arc/core/secureshield/CMakeLists.txt b/arch/arc/core/secureshield/CMakeLists.txt
index c32133a..8b3cb34 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 46fbddd..e312564 100644
--- a/arch/arc/core/switch.S
+++ b/arch/arc/core/switch.S
@@ -17,6 +17,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
+#include <linker/sections.h>
#include <arch/cpu.h>
#include <v2/irq.h>
#include <swap_macros.h>
diff --git a/arch/arc/core/thread.c b/arch/arc/core/thread.c
index 44052e4..e675807 100644
--- a/arch/arc/core/thread.c
+++ b/arch/arc/core/thread.c
@@ -12,8 +12,7 @@
*/
#include <kernel.h>
-#include <toolchain.h>
-#include <kernel_structs.h>
+#include <ksched.h>
#include <offsets_short.h>
#include <wait_q.h>
diff --git a/arch/arc/include/kernel_arch_data.h b/arch/arc/include/kernel_arch_data.h
index 93667eb..a5fa4dc 100644
--- a/arch/arc/include/kernel_arch_data.h
+++ b/arch/arc/include/kernel_arch_data.h
@@ -24,11 +24,9 @@
#include <linker/sections.h>
#include <arch/cpu.h>
#include <vector_table.h>
-#include <kernel_arch_thread.h>
#ifndef _ASMLANGUAGE
#include <kernel.h>
-#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/util.h>
#include <sys/dlist.h>
diff --git a/arch/arc/include/kernel_arch_func.h b/arch/arc/include/kernel_arch_func.h
index 79c2f8f..9883b53 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 <kernel_arch_data.h>
+
#ifdef CONFIG_CPU_ARCV2
#include <v2/cache.h>
#include <v2/irq.h>
@@ -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 cb090da..9428870 100644
--- a/arch/arm/core/CMakeLists.txt
+++ b/arch/arm/core/CMakeLists.txt
@@ -20,6 +20,11 @@
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 556db59..517143d 100644
--- a/arch/arm/core/cortex_m/CMakeLists.txt
+++ b/arch/arm/core/cortex_m/CMakeLists.txt
@@ -15,3 +15,8 @@
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 00b95bc..21bfa04 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 <toolchain.h>
-#include <linker/sections.h>
-
#include <kernel.h>
-#include <kernel_structs.h>
+#include <kernel_internal.h>
#include <inttypes.h>
#include <exc_handle.h>
#include <logging/log.h>
diff --git a/arch/arm/core/cortex_m/thread_abort.c b/arch/arm/core/cortex_m/thread_abort.c
index 657d4fc..2189bfb 100644
--- a/arch/arm/core/cortex_m/thread_abort.c
+++ b/arch/arm/core/cortex_m/thread_abort.c
@@ -17,7 +17,6 @@
*/
#include <kernel.h>
-#include <kernel_structs.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <ksched.h>
diff --git a/arch/arm/core/cortex_r/CMakeLists.txt b/arch/arm/core/cortex_r/CMakeLists.txt
index a1154a3..1b68447 100644
--- a/arch/arm/core/cortex_r/CMakeLists.txt
+++ b/arch/arm/core/cortex_r/CMakeLists.txt
@@ -9,3 +9,8 @@
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 7b500b4..781c92b 100644
--- a/arch/arm/core/cortex_r/fault.c
+++ b/arch/arm/core/cortex_r/fault.c
@@ -5,6 +5,7 @@
*/
#include <kernel.h>
+#include <kernel_internal.h>
#include <kernel_structs.h>
/**
diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c
index ccbd3a3..256d5ce 100644
--- a/arch/arm/core/fatal.c
+++ b/arch/arm/core/fatal.c
@@ -12,12 +12,7 @@
* and Cortex-R CPUs.
*/
-#include <toolchain.h>
-#include <linker/sections.h>
-#include <inttypes.h>
-
#include <kernel.h>
-#include <kernel_structs.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(os);
diff --git a/arch/arm/core/irq_manage.c b/arch/arm/core/irq_manage.c
index 0724be7..6c9c833 100644
--- a/arch/arm/core/irq_manage.c
+++ b/arch/arm/core/irq_manage.c
@@ -27,7 +27,6 @@
#include <linker/sections.h>
#include <sw_isr_table.h>
#include <irq.h>
-#include <kernel_structs.h>
#include <debug/tracing.h>
extern void z_arm_reserved(void);
diff --git a/arch/arm/core/offsets/offsets.c b/arch/arm/core/offsets/offsets.c
index b58945c..6ef9ca5 100644
--- a/arch/arm/core/offsets/offsets.c
+++ b/arch/arm/core/offsets/offsets.c
@@ -22,8 +22,9 @@
* completeness.
*/
+#include <kernel.h>
+#include <kernel_arch_data.h>
#include <gen_offset.h>
-#include <kernel_structs.h>
#include <kernel_offsets.h>
GEN_OFFSET_SYM(_thread_arch_t, basepri);
diff --git a/arch/arm/core/prep_c.c b/arch/arm/core/prep_c.c
index a2e6eb8..d62c14e 100644
--- a/arch/arm/core/prep_c.c
+++ b/arch/arm/core/prep_c.c
@@ -17,14 +17,10 @@
*/
#include <kernel.h>
-#include <zephyr/types.h>
-#include <toolchain.h>
-#include <linker/linker-defs.h>
#include <kernel_internal.h>
-#include <arch/cpu.h>
-#if defined(CONFIG_CPU_CORTEX_M)
-#include <arch/arm/cortex_m/cmsis.h>
-#elif defined(CONFIG_ARMV7_R)
+#include <linker/linker-defs.h>
+
+#if defined(CONFIG_ARMV7_R)
#include <cortex_r/stack.h>
#endif
diff --git a/arch/arm/core/swap.c b/arch/arm/core/swap.c
index 5afb829..79cdea2 100644
--- a/arch/arm/core/swap.c
+++ b/arch/arm/core/swap.c
@@ -5,8 +5,7 @@
*/
#include <kernel.h>
-#include <toolchain.h>
-#include <kernel_structs.h>
+#include <kernel_internal.h>
#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 d06c8f8..42672f7 100644
--- a/arch/arm/core/thread.c
+++ b/arch/arm/core/thread.c
@@ -13,8 +13,7 @@
*/
#include <kernel.h>
-#include <toolchain.h>
-#include <kernel_structs.h>
+#include <ksched.h>
#include <wait_q.h>
#ifdef CONFIG_USERSPACE
diff --git a/arch/arm/include/kernel_arch_data.h b/arch/arm/include/kernel_arch_data.h
index 9932dc9..4dbed96 100644
--- a/arch/arm/include/kernel_arch_data.h
+++ b/arch/arm/include/kernel_arch_data.h
@@ -23,7 +23,6 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
-#include <kernel_arch_thread.h>
/* stacks */
@@ -40,7 +39,6 @@
#ifndef _ASMLANGUAGE
#include <kernel.h>
-#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <sys/atomic.h>
diff --git a/arch/arm/include/kernel_arch_func.h b/arch/arm/include/kernel_arch_func.h
index f11204b..fc7476d 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 <kernel_arch_data.h>
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt
index edeb9c2..5b5d42d 100644
--- a/arch/common/CMakeLists.txt
+++ b/arch/common/CMakeLists.txt
@@ -29,3 +29,8 @@
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 63ecaaf..925e2f6 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 b9c4836..f698b88 100644
--- a/arch/nios2/core/crt0.S
+++ b/arch/nios2/core/crt0.S
@@ -4,7 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <kernel_structs.h>
+#include <toolchain.h>
+#include <linker/sections.h>
/* exports */
GTEXT(__start)
diff --git a/arch/nios2/core/exception.S b/arch/nios2/core/exception.S
index 5f67dc9..6090753 100644
--- a/arch/nios2/core/exception.S
+++ b/arch/nios2/core/exception.S
@@ -4,7 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <kernel_structs.h>
+#include <toolchain.h>
+#include <linker/sections.h>
#include <offsets_short.h>
/* exports */
diff --git a/arch/nios2/core/offsets/offsets.c b/arch/nios2/core/offsets/offsets.c
index 80639af..1b735e7 100644
--- a/arch/nios2/core/offsets/offsets.c
+++ b/arch/nios2/core/offsets/offsets.c
@@ -24,8 +24,9 @@
*/
+#include <kernel.h>
+#include <kernel_arch_data.h>
#include <gen_offset.h>
-#include <kernel_structs.h>
#include <kernel_offsets.h>
/* struct coop member offsets */
diff --git a/arch/nios2/core/reset.S b/arch/nios2/core/reset.S
index 8c2719c..716177d 100644
--- a/arch/nios2/core/reset.S
+++ b/arch/nios2/core/reset.S
@@ -4,9 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <arch/cpu.h>
-#include <kernel_structs.h>
-#include <offsets_short.h>
+#include <toolchain.h>
GTEXT(__start)
diff --git a/arch/nios2/core/swap.S b/arch/nios2/core/swap.S
index 7d43520..c4f2ccf 100644
--- a/arch/nios2/core/swap.S
+++ b/arch/nios2/core/swap.S
@@ -4,7 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <kernel_structs.h>
+#include <toolchain.h>
+#include <linker/sections.h>
#include <offsets_short.h>
/* exports */
diff --git a/arch/nios2/core/thread.c b/arch/nios2/core/thread.c
index 532107a..8ea1337 100644
--- a/arch/nios2/core/thread.c
+++ b/arch/nios2/core/thread.c
@@ -5,10 +5,7 @@
*/
#include <kernel.h>
-#include <kernel_internal.h>
-#include <kernel_structs.h>
-#include <wait_q.h>
-#include <string.h>
+#include <ksched.h>
/* 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 6643103..5fa07ba 100644
--- a/arch/nios2/include/kernel_arch_data.h
+++ b/arch/nios2/include/kernel_arch_data.h
@@ -24,7 +24,6 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
-#include <kernel_arch_thread.h>
/* stacks */
@@ -36,7 +35,6 @@
#ifndef _ASMLANGUAGE
#include <kernel.h>
-#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/util.h>
#include <sys/dlist.h>
diff --git a/arch/nios2/include/kernel_arch_func.h b/arch/nios2/include/kernel_arch_func.h
index 6ff1b38..84ab183 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 <kernel_arch_data.h>
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/arch/posix/core/cpuhalt.c b/arch/posix/core/cpuhalt.c
index 219d7b7..57356ba 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 <arch/posix/posix_soc_if.h>
#include <debug/tracing.h>
void z_arch_cpu_idle(void)
diff --git a/arch/posix/core/fatal.c b/arch/posix/core/fatal.c
index d5e0966..6fa8df6 100644
--- a/arch/posix/core/fatal.c
+++ b/arch/posix/core/fatal.c
@@ -11,7 +11,7 @@
#include <sys/printk.h>
#include <inttypes.h>
#include <logging/log_ctrl.h>
-#include "posix_soc_if.h"
+#include <arch/posix/posix_soc_if.h>
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 d0b16eb..5fffad7 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 <arch/posix/posix_soc_if.h>
#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 bd3af1f..600e388 100644
--- a/arch/posix/core/offsets/offsets.c
+++ b/arch/posix/core/offsets/offsets.c
@@ -23,18 +23,13 @@
* completeness.
*/
-#include <gen_offset.h> /* located in kernel/include */
-
-/* list of headers that define whose structure offsets will be generated */
-
-#include <kernel_structs.h>
-
+#include <kernel.h>
+#include <kernel_arch_data.h>
+#include <gen_offset.h>
#include <kernel_offsets.h>
#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 d24a34d..417b824 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 <arch/posix/posix_soc_if.h>
#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 f985fe4..0d207db 100644
--- a/arch/posix/core/thread.c
+++ b/arch/posix/core/thread.c
@@ -15,10 +15,11 @@
#include <toolchain.h>
#include <kernel_structs.h>
+#include <ksched.h>
#include <wait_q.h>
#include "posix_core.h"
-#include "posix_soc_if.h"
+#include <arch/posix/posix_soc_if.h>
/* 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 4cdd4ba..40c2238 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 <kernel_internal.h>
-
/* 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 5d65fde..c5b80e9 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 <toolchain/common.h>
-#include "posix_core.h"
+#include <kernel_arch_data.h>
#ifndef _ASMLANGUAGE
diff --git a/arch/riscv/core/CMakeLists.txt b/arch/riscv/core/CMakeLists.txt
index 3b14112..d7c059a 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 @@
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 38fb465..43b7e58 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 <toolchain.h>
-#include <kernel_structs.h>
+#include <kernel.h>
+#include <kernel_internal.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(os);
diff --git a/arch/riscv/core/isr.S b/arch/riscv/core/isr.S
index 6fc5613..78be5b3 100644
--- a/arch/riscv/core/isr.S
+++ b/arch/riscv/core/isr.S
@@ -7,8 +7,8 @@
#include <toolchain.h>
#include <linker/sections.h>
-#include <kernel_structs.h>
#include <offsets_short.h>
+#include <arch/cpu.h>
/* imports */
GDATA(_sw_isr_table)
diff --git a/arch/riscv/core/offsets/offsets.c b/arch/riscv/core/offsets/offsets.c
index f8f4771..659d080 100644
--- a/arch/riscv/core/offsets/offsets.c
+++ b/arch/riscv/core/offsets/offsets.c
@@ -13,8 +13,9 @@
* structures.
*/
+#include <kernel.h>
+#include <kernel_arch_data.h>
#include <gen_offset.h>
-#include <kernel_structs.h>
#include <kernel_offsets.h>
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
diff --git a/arch/riscv/core/reset.S b/arch/riscv/core/reset.S
index 7e3d285..fbe7120 100644
--- a/arch/riscv/core/reset.S
+++ b/arch/riscv/core/reset.S
@@ -5,7 +5,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <kernel_structs.h>
+#include <toolchain.h>
+#include <linker/sections.h>
+#include <arch/cpu.h>
/* exports */
GTEXT(__initialize)
diff --git a/arch/riscv/core/swap.S b/arch/riscv/core/swap.S
index 523b226..c81910a 100644
--- a/arch/riscv/core/swap.S
+++ b/arch/riscv/core/swap.S
@@ -4,9 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <irq.h>
-#include <kernel_structs.h>
+#include <toolchain.h>
+#include <linker/sections.h>
#include <offsets_short.h>
+#include <arch/cpu.h>
/* exports */
GTEXT(z_arch_swap)
diff --git a/arch/riscv/core/thread.c b/arch/riscv/core/thread.c
index db5a297..f9bcc48 100644
--- a/arch/riscv/core/thread.c
+++ b/arch/riscv/core/thread.c
@@ -5,10 +5,7 @@
*/
#include <kernel.h>
-#include <arch/cpu.h>
-#include <kernel_structs.h>
-#include <wait_q.h>
-#include <string.h>
+#include <ksched.h>
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 a874d52..13f0d60 100644
--- a/arch/riscv/include/kernel_arch_data.h
+++ b/arch/riscv/include/kernel_arch_data.h
@@ -18,14 +18,12 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
-#include <kernel_arch_thread.h>
#ifndef _ASMLANGUAGE
#include <kernel.h>
#include <zephyr/types.h>
#include <sys/util.h>
#include <sys/dlist.h>
-#include <kernel_internal.h>
#ifdef __cplusplus
extern "C" {
diff --git a/arch/riscv/include/kernel_arch_func.h b/arch/riscv/include/kernel_arch_func.h
index dfaa1cb..bca8f1d 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 <soc.h>
+#include <kernel_arch_data.h>
#ifdef __cplusplus
extern "C" {
diff --git a/arch/x86/core/CMakeLists.txt b/arch/x86/core/CMakeLists.txt
index 36b6bcb..082ae37 100644
--- a/arch/x86/core/CMakeLists.txt
+++ b/arch/x86/core/CMakeLists.txt
@@ -19,6 +19,11 @@
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 15828da..4082abc 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 <kernel_structs.h>
#include <arch/x86/ia32/asm.h>
#include <arch/x86/ia32/arch.h> /* For MK_ISR_NAME */
#include <offsets_short.h>
diff --git a/arch/x86/core/ia32/fatal.c b/arch/x86/core/ia32/fatal.c
index b26a41d..e5ec4c3 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 <toolchain.h>
-#include <linker/sections.h>
-
#include <kernel.h>
-#include <kernel_structs.h>
+#include <kernel_internal.h>
#include <drivers/interrupt_controller/sysapic.h>
#include <arch/x86/ia32/segmentation.h>
#include <ia32/exception.h>
diff --git a/arch/x86/core/ia32/float.c b/arch/x86/core/ia32/float.c
index 75741fb..23e7c0a 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 <kernel_structs.h>
-#include <toolchain.h>
+#include <kernel.h>
+#include <kernel_internal.h>
/* 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 963a2e4..6ed8f59 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 <kernel_structs.h>
#include <arch/x86/ia32/asm.h>
#include <offsets_short.h>
#include <arch/cpu.h>
diff --git a/arch/x86/core/ia32/swap.S b/arch/x86/core/ia32/swap.S
index 20147af..f37ff8c 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 <kernel_structs.h>
#include <arch/x86/ia32/asm.h>
+#include <kernel.h>
+#include <arch/cpu.h>
+#include <kernel_arch_data.h>
#include <offsets_short.h>
/* exports (internal APIs) */
diff --git a/arch/x86/core/ia32/thread.c b/arch/x86/core/ia32/thread.c
index 890ea46..711e253 100644
--- a/arch/x86/core/ia32/thread.c
+++ b/arch/x86/core/ia32/thread.c
@@ -12,12 +12,9 @@
* processor architecture.
*/
-#include <toolchain.h>
-#include <linker/sections.h>
-#include <kernel_structs.h>
-#include <wait_q.h>
+#include <kernel.h>
+#include <ksched.h>
#include <arch/x86/mmustructs.h>
-#include <sys/printk.h>
/* forward declaration */
diff --git a/arch/x86/core/ia32/userspace.S b/arch/x86/core/ia32/userspace.S
index ba6aced..67dbd1c 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 <kernel_structs.h>
#include <arch/x86/ia32/asm.h>
#include <arch/cpu.h>
#include <offsets_short.h>
diff --git a/arch/x86/core/offsets/ia32_offsets.c b/arch/x86/core/offsets/ia32_offsets.c
index fab6c7a..3ae3a09 100644
--- a/arch/x86/core/offsets/ia32_offsets.c
+++ b/arch/x86/core/offsets/ia32_offsets.c
@@ -26,8 +26,6 @@
#include <arch/x86/mmustructs.h>
-#include <kernel_offsets.h>
-
#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 7f60630..25ca8a9 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 <kernel_arch_thread.h>
-
-#include <kernel_offsets.h>
-
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 3551507..5fd1d54 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 <gen_offset.h>
-#include <kernel_structs.h>
+#include <kernel.h>
#include <kernel_arch_data.h>
-#include <arch/x86/multiboot.h>
+#include <gen_offset.h>
+#include <kernel_offsets.h>
#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 f0026f8..ced015b 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 <kernel_structs.h>
+#include <kernel.h>
+#include <kernel_internal.h>
#include <arch/x86/acpi.h>
#include <arch/x86/multiboot.h>
diff --git a/arch/x86/include/ia32/kernel_arch_data.h b/arch/x86/include/ia32/kernel_arch_data.h
index 392cca1..52a0b61 100644
--- a/arch/x86/include/ia32/kernel_arch_data.h
+++ b/arch/x86/include/ia32/kernel_arch_data.h
@@ -29,12 +29,10 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <ia32/exception.h>
-#include <kernel_arch_thread.h>
#include <sys/util.h>
#ifndef _ASMLANGUAGE
#include <kernel.h>
-#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#endif
diff --git a/arch/x86/include/intel64/kernel_arch_data.h b/arch/x86/include/intel64/kernel_arch_data.h
index 0262144..bfda155 100644
--- a/arch/x86/include/intel64/kernel_arch_data.h
+++ b/arch/x86/include/intel64/kernel_arch_data.h
@@ -8,32 +8,6 @@
#include <arch/x86/mmustructs.h>
-/*
- * 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 */
@@ -41,46 +15,6 @@
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 5b58cdd..7c717fd 100644
--- a/arch/x86/include/intel64/kernel_arch_func.h
+++ b/arch/x86/include/intel64/kernel_arch_func.h
@@ -30,16 +30,6 @@
/* 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 a087d0d..0000000
--- 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 <zephyr/types.h>
-#include <kernel_arch_data.h>
-
-/*
- * 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 86e72a0..6c69e47 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 <kernel_arch_data.h>
+
#ifdef CONFIG_X86_64
#include <intel64/kernel_arch_func.h>
#else
diff --git a/arch/x86/include/kernel_arch_thread.h b/arch/x86/include/kernel_arch_thread.h
deleted file mode 100644
index d85bb82..0000000
--- 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 <intel64/kernel_arch_thread.h>
-#else
-#include <ia32/kernel_arch_thread.h>
-#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 62fcc24..b19b30c 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 20b5107..ff93314 100644
--- a/arch/xtensa/core/atomic.S
+++ b/arch/xtensa/core/atomic.S
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <xtensa_context.h>
+#include <arch/xtensa/xtensa_context.h>
/**
*
* @brief Atomically clear a memory location
diff --git a/arch/xtensa/core/crt1.S b/arch/xtensa/core/crt1.S
index c4b2719..bebecd7 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 <xtensa_rtos.h>
+#include <arch/xtensa/xtensa_rtos.h>
/* Exports */
.global _start
diff --git a/arch/xtensa/core/irq_offload.c b/arch/xtensa/core/irq_offload.c
index a0a0059..981e70d 100644
--- a/arch/xtensa/core/irq_offload.c
+++ b/arch/xtensa/core/irq_offload.c
@@ -6,7 +6,7 @@
#include <kernel.h>
#include <irq_offload.h>
#include <arch/xtensa/arch.h>
-#include <xtensa_api.h>
+#include <arch/xtensa/xtensa_api.h>
/*
* 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 8ff8ce3..ee78f56 100644
--- a/arch/xtensa/core/offsets/offsets.c
+++ b/arch/xtensa/core/offsets/offsets.c
@@ -23,12 +23,9 @@
* completeness.
*/
-#include <gen_offset.h> /* located in kernel/arch/common/include */
-
-/* list of headers that define whose structure offsets will be generated */
-
-#include <kernel_structs.h>
-
+#include <kernel.h>
+#include <kernel_arch_data.h>
+#include <gen_offset.h>
#include <kernel_offsets.h>
/* Xtensa-specific k_thread structure member offsets */
diff --git a/arch/xtensa/core/startup/CMakeLists.txt b/arch/xtensa/core/startup/CMakeLists.txt
index c3283d9..d6595f5 100644
--- a/arch/xtensa/core/startup/CMakeLists.txt
+++ b/arch/xtensa/core/startup/CMakeLists.txt
@@ -10,8 +10,13 @@
)
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 44a9bfb..5423cba 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 <arch/xtensa/xtensa_rtos.h>
/* 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 e0de40e..3a40334 100644
--- a/arch/xtensa/include/kernel_arch_data.h
+++ b/arch/xtensa/include/kernel_arch_data.h
@@ -23,7 +23,6 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
-#include <kernel_arch_thread.h>
/* stacks */
#define STACK_ROUND_UP(x) ROUND_UP(x, STACK_ALIGN_SIZE)
@@ -31,7 +30,6 @@
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
#include <kernel.h> /* public kernel API */
-#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <sys/util.h>
diff --git a/arch/xtensa/include/kernel_arch_func.h b/arch/xtensa/include/kernel_arch_func.h
index ac52eb9..7176220 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 <kernel_arch_data.h>
#include <string.h>
-#include <stdbool.h>
-#include <stddef.h> /* For size_t */
#ifdef __cplusplus
extern "C" {
@@ -23,16 +22,6 @@
#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 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 39ea2f1..5fa77d6 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 @@
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 67db127..a56cc78 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 <arch/posix/posix_trace.h>
#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 00df76f..2f2cf58 100644
--- a/boards/posix/native_posix/cmdline_common.c
+++ b/boards/posix/native_posix/cmdline_common.c
@@ -10,7 +10,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
-#include "posix_trace.h"
+#include <arch/posix/posix_trace.h>
#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 7e15643..30d7c15 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 <arch/posix/posix_soc_if.h>
#include "posix_arch_internal.h"
#include "sdl_events.h"
#include <sys/util.h>
diff --git a/boards/posix/native_posix/native_rtc.c b/boards/posix/native_posix/native_rtc.c
index ff2dedb..7715e3b 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 <arch/posix/posix_trace.h>
/**
* 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 7e8381d..8b2511e 100644
--- a/boards/posix/native_posix/sdl_events.c
+++ b/boards/posix/native_posix/sdl_events.c
@@ -6,7 +6,7 @@
#include <SDL.h>
#include "posix_board_if.h"
-#include "posix_trace.h"
+#include <arch/posix/posix_trace.h>
#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 55dbee2..aa97dde 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 <arch/posix/posix_trace.h>
#include <sys/util.h>
#include "cmdline.h"
#include "soc.h"
diff --git a/boards/posix/nrf52_bsim/CMakeLists.txt b/boards/posix/nrf52_bsim/CMakeLists.txt
index 37e2b8f..b2bc60c 100644
--- a/boards/posix/nrf52_bsim/CMakeLists.txt
+++ b/boards/posix/nrf52_bsim/CMakeLists.txt
@@ -88,6 +88,8 @@
$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 8e43ed7..2787a5f 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 <arch/posix/posix_soc_if.h>
#if defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT)
/**
diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake
index f96408f..f553313 100644
--- a/cmake/extensions.cmake
+++ b/cmake/extensions.cmake
@@ -1148,6 +1148,12 @@
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 ef1c008..5b4a6ab 100644
--- a/drivers/entropy/fake_entropy_native_posix.c
+++ b/drivers/entropy/fake_entropy_native_posix.c
@@ -17,7 +17,7 @@
#include <sys/util.h>
#include <stdlib.h>
#include <string.h>
-#include "posix_trace.h"
+#include <arch/posix/posix_trace.h>
#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 b34174b..996b3ff 100644
--- a/drivers/ethernet/eth_native_posix_adapt.c
+++ b/drivers/ethernet/eth_native_posix_adapt.c
@@ -25,7 +25,7 @@
#include <sys/select.h>
#include <net/if.h>
#include <time.h>
-#include "posix_trace.h"
+#include <arch/posix/posix_trace.h>
#ifdef __linux
#include <linux/if_tun.h>
diff --git a/drivers/timer/native_posix_timer.c b/drivers/timer/native_posix_timer.c
index e730c11..2bb1e5d 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 <arch/posix/posix_trace.h>
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 b0fe417..977336c 100644
--- a/drivers/timer/xtensa_sys_timer.c
+++ b/drivers/timer/xtensa_sys_timer.c
@@ -6,7 +6,7 @@
#include <drivers/timer/system_timer.h>
#include <sys_clock.h>
#include <spinlock.h>
-#include <xtensa_rtos.h>
+#include <arch/xtensa/xtensa_rtos.h>
#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 71f61c3..c116eb7 100644
--- a/include/arch/arc/arch.h
+++ b/include/arch/arc/arch.h
@@ -18,6 +18,7 @@
#include <generated_dts_board.h>
#include <sw_isr_table.h>
+#include <arch/arc/thread.h>
#ifdef CONFIG_CPU_ARCV2
#include <arch/arc/v2/exc.h>
#include <arch/arc/v2/irq.h>
diff --git a/include/arch/arc/arch_inlines.h b/include/arch/arc/arch_inlines.h
new file mode 100644
index 0000000..316507c
--- /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 <root@stephanos.io>
+ *
+ * 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 <kernel_structs.h>
+
+#ifdef CONFIG_CPU_ARCV2
+#include <arch/arc/v2/aux_regs.h>
+#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 86%
rename from arch/arc/include/kernel_arch_thread.h
rename to include/arch/arc/thread.h
index 1406b84..c2945cf 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 @@
#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 0000000..4277f94
--- /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 <root@stephanos.io>
+ *
+ * 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 <arch/x86/arch_inlines.h>
+#elif defined(CONFIG_ARC)
+#include <arch/arc/arch_inlines.h>
+#elif defined(CONFIG_XTENSA)
+#include <arch/xtensa/arch_inlines.h>
+#endif
+
+#endif /* ZEPHYR_INCLUDE_ARCH_INLINES_H_ */
diff --git a/include/arch/arm/arch.h b/include/arch/arm/arch.h
index 8e19fe8..04bd26f 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 <arch/arm/thread.h>
#include <arch/arm/exc.h>
#include <arch/arm/irq.h>
#include <arch/arm/error.h>
diff --git a/include/arch/arm/asm_inline.h b/include/arch/arm/asm_inline.h
index 1ddc49b..f6e943d 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 <arch/arm/asm_inline_other.h>
#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 8397779..460849f 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 @@
#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 71c8f7d..4017369 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 <arch/arm/syscall.h>
#include <arch/arm/exc.h>
@@ -62,4 +62,4 @@
}
#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 2903e2e..cec8949 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 @@
#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 3ef252b..c698b22 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 <irq.h>
#include <sw_isr_table.h>
@@ -149,4 +149,4 @@
}
#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 4f2911d..47f051c 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 @@
}
#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 7d7945f..00ed671 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 @@
#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 91%
rename from arch/arm/include/kernel_arch_thread.h
rename to include/arch/arm/thread.h
index a359e8f..8ab66cb 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 <zephyr/types.h>
@@ -92,4 +92,4 @@
#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 cac2693..0b75d32 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 <sys/arch_inlines.h>
+#include <sys/arch_interface.h>
#if defined(CONFIG_X86)
#include <arch/x86/arch.h>
diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h
index 0ff9244..f5fdaf4 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 <system.h>
+
+#include <arch/nios2/thread.h>
#include <arch/nios2/asm_inline.h>
#include <arch/common/addr_types.h>
#include <generated_dts_board.h>
-#include "nios2.h"
+#include <arch/nios2/nios2.h>
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
diff --git a/arch/nios2/include/kernel_arch_thread.h b/include/arch/nios2/thread.h
similarity index 84%
rename from arch/nios2/include/kernel_arch_thread.h
rename to include/arch/nios2/thread.h
index 975b66c..c101c26 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 <zephyr/types.h>
@@ -61,5 +61,5 @@
#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 3ccf26c..245e049 100644
--- a/include/arch/posix/arch.h
+++ b/include/arch/posix/arch.h
@@ -23,9 +23,10 @@
#include <toolchain.h>
#include <irq.h>
#include <arch/posix/asm_inline.h>
+#include <arch/posix/thread.h>
#include <board_irq.h> /* Each board must define this */
#include <sw_isr_table.h>
-#include <posix_soc_if.h>
+#include <arch/posix/posix_soc_if.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/arch/posix/asm_inline_gcc.h b/include/arch/posix/asm_inline_gcc.h
index eb86352..1853bb6 100644
--- a/include/arch/posix/asm_inline_gcc.h
+++ b/include/arch/posix/asm_inline_gcc.h
@@ -25,7 +25,7 @@
#include <zephyr/types.h>
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
-#include "posix_soc_if.h"
+#include <arch/posix/posix_soc_if.h>
#endif /* _ASMLANGUAGE */
diff --git a/arch/posix/include/posix_soc_if.h b/include/arch/posix/posix_soc_if.h
similarity index 81%
rename from arch/posix/include/posix_soc_if.h
rename to include/arch/posix/posix_soc_if.h
index 0dede34..d1fd2ea 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 <arch/posix/posix_trace.h>
#include "soc_irq.h" /* Must exist and define _ARCH_IRQ/ISR_* macros */
#ifdef __cplusplus
@@ -39,4 +39,4 @@
}
#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 ae160b0..76432e7 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 @@
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 <output> 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 d2dd957..8c9f832 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 <zephyr/types.h>
@@ -52,4 +52,4 @@
#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 90db6e7..b841a85 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 <arch/riscv/thread.h>
+#include <arch/riscv/exp.h>
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
diff --git a/arch/riscv/include/kernel_arch_thread.h b/include/arch/riscv/thread.h
similarity index 86%
rename from arch/riscv/include/kernel_arch_thread.h
rename to include/arch/riscv/thread.h
index b73a406..02fe635 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 <zephyr/types.h>
@@ -52,4 +52,4 @@
#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 0000000..3b60dd3
--- /dev/null
+++ b/include/arch/x86/arch_inlines.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Intel Corporation
+ * Copyright (c) 2019 Stephanos Ioannidis <root@stephanos.io>
+ *
+ * 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 <arch/x86/intel64/thread.h>
+#include <kernel_structs.h>
+
+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 f65c593..c3abeed 100644
--- a/include/arch/x86/ia32/arch.h
+++ b/include/arch/x86/ia32/arch.h
@@ -16,10 +16,10 @@
#include "sys_io.h"
#include <drivers/interrupt_controller/sysapic.h>
-#include <kernel_arch_thread.h>
#include <stdbool.h>
#include <arch/common/ffs.h>
#include <misc/util.h>
+#include <arch/x86/ia32/thread.h>
#include <arch/x86/ia32/syscall.h>
#ifndef _ASMLANGUAGE
diff --git a/arch/x86/include/ia32/kernel_arch_thread.h b/include/arch/x86/ia32/thread.h
similarity index 96%
rename from arch/x86/include/ia32/kernel_arch_thread.h
rename to include/arch/x86/ia32/thread.h
index a93a569..23e7407 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 @@
#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 189d1e2..6cbe8f8 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 <kernel_arch_thread.h>
+#include <arch/x86/intel64/thread.h>
#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 0000000..f1bc66d
--- /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 <zephyr/types.h>
+
+/*
+ * 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 49e1408..4b2896f 100644
--- a/include/arch/xtensa/arch.h
+++ b/include/arch/xtensa/arch.h
@@ -17,10 +17,11 @@
#include <generated_dts_board.h>
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
+#include <zephyr/types.h>
#include <arch/common/sys_io.h>
#include <arch/common/ffs.h>
-#include <zephyr/types.h>
#include <sw_isr_table.h>
+#include <arch/xtensa/thread.h>
#include <arch/xtensa/irq.h>
#include <xtensa/config/core.h>
#include <arch/common/addr_types.h>
diff --git a/include/arch/xtensa/arch_inlines.h b/include/arch/xtensa/arch_inlines.h
new file mode 100644
index 0000000..d7bb037
--- /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 <root@stephanos.io>
+ *
+ * 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 <kernel_structs.h>
+
+#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 8c6b013..264eaf6 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 <xtensa_api.h>
+#include <arch/xtensa/xtensa_api.h>
#include <xtensa/xtruntime.h>
#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 93%
rename from arch/xtensa/include/kernel_arch_thread.h
rename to include/arch/xtensa/thread.h
index dc2bb69..6e05dda 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 <zephyr/types.h>
-#include <xtensa_context.h>
+#include <arch/xtensa/xtensa_context.h>
/*
* The following structure defines the set of 'non-volatile' integer registers.
@@ -112,5 +112,5 @@
#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 6010700..959a05c 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -4841,6 +4841,13 @@
* 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 f52a372..03e39b5 100644
--- a/include/kernel_includes.h
+++ b/include/kernel_includes.h
@@ -26,9 +26,9 @@
#include <sys/sflist.h>
#include <sys/util.h>
#include <sys/mempool_base.h>
+#include <kernel_structs.h>
#include <kernel_version.h>
#include <random/rand32.h>
-#include <kernel_arch_thread.h>
#include <syscall.h>
#include <sys/printk.h>
#include <arch/cpu.h>
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 49b8f3d..5951972 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 <kernel.h>
-
#if !defined(_ASMLANGUAGE)
-#include <sys/atomic.h>
+#include <zephyr/types.h>
+#include <sched_priq.h>
#include <sys/dlist.h>
-#include <sys/rb.h>
#include <sys/util.h>
-#include <string.h>
-#include <sys/arch_interface.h>
#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 <kernel_arch_data.h>
-
#if !defined(_ASMLANGUAGE)
struct _ready_q {
@@ -189,77 +196,6 @@
#define _timeout_q _kernel.timeout_q
-#include <kernel_arch_func.h>
-
-#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 6e04fad..0000000
--- 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, <arch/cpu.h>
- * 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 <stdbool.h>
-#include <zephyr/types.h>
-#include <arch/cpu.h>
-
-#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 c3b6153..2b02386 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, <arch/cpu.h>
+ * 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 <kernel.h>
+#include <toolchain.h>
+#include <stddef.h>
+#include <zephyr/types.h>
+#include <arch/cpu.h>
#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()
*/
-int z_arch_float_disable(struct k_thread *thread);
-#endif /* CONFIG_FLOAT && CONFIG_FP_SHARING */
+
+/*
+ * @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
+ */
/** @} */
+
/**
- * @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 */
/** @} */
@@ -200,31 +345,142 @@
/**
- * @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
*
* @return Max number of partitions, or -1 if there is no limit
@@ -380,51 +636,12 @@
/** @} */
-
-/**
- * @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 <arch/arch_inlines.h>
+
#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 a5e5b7a..e8beaa5 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 <kernel.h>
+#include <sys/arch_interface.h>
#include <sys/math_extras.h>
-#include <kernel_internal.h>
-#include <kernel_structs.h>
#include <stdbool.h>
#include <logging/log.h>
@@ -515,4 +514,4 @@
#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 936dde3..bc3baaf 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 <posix_trace.h>
+#include <arch/posix/posix_trace.h>
/*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 6f66985..499d630 100644
--- a/kernel/include/wait_q.h
+++ b/include/wait_q.h
@@ -12,7 +12,6 @@
#include <kernel_structs.h>
#include <sys/dlist.h>
#include <sys/rb.h>
-#include <ksched.h>
#include <sched_priq.h>
#include <timeout_q.h>
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 7d8e858..988df63 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -53,6 +53,10 @@
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 e235937..51a2363 100644
--- a/kernel/errno.c
+++ b/kernel/errno.c
@@ -12,7 +12,7 @@
* context switching.
*/
-#include <kernel_structs.h>
+#include <kernel.h>
#include <syscall_handler.h>
/*
diff --git a/kernel/idle.c b/kernel/idle.c
index 2bbdf16..0bfe35d 100644
--- a/kernel/idle.c
+++ b/kernel/idle.c
@@ -5,7 +5,6 @@
*/
#include <kernel.h>
-#include <kernel_structs.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <drivers/timer/system_timer.h>
diff --git a/kernel/include/kernel_arch_interface.h b/kernel/include/kernel_arch_interface.h
new file mode 100644
index 0000000..47d75a6
--- /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 <kernel.h>
+#include <sys/arch_interface.h>
+
+#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 <kernel_arch_func.h>
+
+#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 1c03bec..4f8bacd 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 <kernel.h>
-#include <stdbool.h>
+#include <kernel_arch_interface.h>
+#include <string.h>
#ifndef _ASMLANGUAGE
@@ -45,6 +46,51 @@
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 @@
} 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 5bc6ebe6..308d90b 100644
--- a/kernel/mailbox.c
+++ b/kernel/mailbox.c
@@ -14,6 +14,7 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <string.h>
+#include <ksched.h>
#include <wait_q.h>
#include <sys/dlist.h>
#include <init.h>
diff --git a/kernel/msg_q.c b/kernel/msg_q.c
index f46655b..7c12440 100644
--- a/kernel/msg_q.c
+++ b/kernel/msg_q.c
@@ -16,6 +16,7 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <string.h>
+#include <ksched.h>
#include <wait_q.h>
#include <sys/dlist.h>
#include <sys/math_extras.h>
diff --git a/kernel/mutex.c b/kernel/mutex.c
index cd9f76e..ba3aa4d 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -30,6 +30,7 @@
#include <kernel_structs.h>
#include <toolchain.h>
#include <linker/sections.h>
+#include <ksched.h>
#include <wait_q.h>
#include <sys/dlist.h>
#include <debug/object_tracing_common.h>
diff --git a/kernel/pipes.c b/kernel/pipes.c
index e48fa9b..78417cf 100644
--- a/kernel/pipes.c
+++ b/kernel/pipes.c
@@ -15,6 +15,7 @@
#include <debug/object_tracing_common.h>
#include <toolchain.h>
#include <linker/sections.h>
+#include <ksched.h>
#include <wait_q.h>
#include <sys/dlist.h>
#include <init.h>
diff --git a/kernel/thread.c b/kernel/thread.c
index 0642d0f..ff2cf0b 100644
--- a/kernel/thread.c
+++ b/kernel/thread.c
@@ -12,12 +12,7 @@
*/
#include <kernel.h>
-
-#include <toolchain.h>
-#include <linker/sections.h>
-
#include <spinlock.h>
-#include <kernel_structs.h>
#include <sys/math_extras.h>
#include <sys_clock.h>
#include <drivers/timer/system_timer.h>
@@ -29,6 +24,7 @@
#include <kswap.h>
#include <init.h>
#include <debug/tracing.h>
+#include <string.h>
#include <stdbool.h>
static struct k_spinlock lock;
diff --git a/kernel/timeout.c b/kernel/timeout.c
index 12e4c48..9694653 100644
--- a/kernel/timeout.c
+++ b/kernel/timeout.c
@@ -3,12 +3,14 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
-#include <timeout_q.h>
-#include <drivers/timer/system_timer.h>
-#include <sys_clock.h>
+
+#include <kernel.h>
#include <spinlock.h>
#include <ksched.h>
+#include <timeout_q.h>
#include <syscall_handler.h>
+#include <drivers/timer/system_timer.h>
+#include <sys_clock.h>
#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 997cbc2..3c4c4caac 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -7,6 +7,7 @@
#include <kernel.h>
#include <debug/object_tracing_common.h>
#include <init.h>
+#include <ksched.h>
#include <wait_q.h>
#include <syscall_handler.h>
#include <stdbool.h>
diff --git a/lib/cmsis_rtos_v1/CMakeLists.txt b/lib/cmsis_rtos_v1/CMakeLists.txt
index b3c31c6..b67f971 100644
--- a/lib/cmsis_rtos_v1/CMakeLists.txt
+++ b/lib/cmsis_rtos_v1/CMakeLists.txt
@@ -20,4 +20,9 @@
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 71c049b..a61136a 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 <kernel_structs.h>
-#include <cmsis_os.h>
+#include <kernel.h>
#include <ksched.h>
+#include <cmsis_os.h>
#include <kernel_internal.h>
/**
diff --git a/lib/cmsis_rtos_v1/cmsis_mailq.c b/lib/cmsis_rtos_v1/cmsis_mailq.c
index cc62bb2..ed579a4 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
+#include <string.h>
/**
* @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 31aea5e..d1df402 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
+#include <string.h>
#define TIME_OUT 100
diff --git a/lib/cmsis_rtos_v1/cmsis_msgq.c b/lib/cmsis_rtos_v1/cmsis_msgq.c
index 5e3869c..0293c3f 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
/**
diff --git a/lib/cmsis_rtos_v1/cmsis_mutex.c b/lib/cmsis_rtos_v1/cmsis_mutex.c
index 9842d47..bc9e05b 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
+#include <string.h>
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 8bb0d04..ce5e5f6 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
+#include <string.h>
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 a0cfa37..02a262d 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
#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 3972010..3fb236f 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 <kernel_structs.h>
+#include <kernel.h>
#include <sys/atomic.h>
#include <cmsis_os.h>
diff --git a/lib/cmsis_rtos_v1/cmsis_timer.c b/lib/cmsis_rtos_v1/cmsis_timer.c
index 738c841..6200d15 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
+#include <string.h>
#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 45de33e..228ac94 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 <kernel_structs.h>
+#include <kernel.h>
#include <cmsis_os.h>
/**
diff --git a/lib/cmsis_rtos_v2/CMakeLists.txt b/lib/cmsis_rtos_v2/CMakeLists.txt
index 5327dad..c4c8129 100644
--- a/lib/cmsis_rtos_v2/CMakeLists.txt
+++ b/lib/cmsis_rtos_v2/CMakeLists.txt
@@ -19,4 +19,9 @@
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 26205cb..93e751e 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#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 dad2b17..0628591 100644
--- a/lib/cmsis_rtos_v2/kernel.c
+++ b/lib/cmsis_rtos_v2/kernel.c
@@ -6,8 +6,7 @@
#include <stdio.h>
#include <string.h>
-#include <kernel_structs.h>
-#include <ksched.h>
+#include <kernel.h>
#include <cmsis_os2.h>
/* 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 be594dd..128b806 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#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 22596e5..d4f4de9 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#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 6626cb2..27c8ae1 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#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 7f35c6c..938401f 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#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 e251e9e..f6839a3 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 <kernel.h>
+#include <ksched.h>
#include <stdio.h>
#include <string.h>
-#include <kernel_structs.h>
-#include <ksched.h>
#include <sys/atomic.h>
#include <debug/stack.h>
#include "wrapper.h"
diff --git a/lib/cmsis_rtos_v2/timer.c b/lib/cmsis_rtos_v2/timer.c
index abb5e95..2508e3e 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 <kernel_structs.h>
+#include <kernel.h>
+#include <string.h>
#include "wrapper.h"
#define ACTIVE 1
diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c
index fedbeca..d0c7070 100644
--- a/lib/libc/newlib/libc-hooks.c
+++ b/lib/libc/newlib/libc-hooks.c
@@ -10,7 +10,6 @@
#include <sys/stat.h>
#include <linker/linker-defs.h>
#include <sys/util.h>
-#include <kernel_internal.h>
#include <sys/errno_private.h>
#include <sys/libc-hooks.h>
#include <syscall_handler.h>
diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt
index 5d44cf8..77d4c4b 100644
--- a/lib/posix/CMakeLists.txt
+++ b/lib/posix/CMakeLists.txt
@@ -23,4 +23,9 @@
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 85e13d4..4afa7b5 100644
--- a/scripts/gen_relocate_app.py
+++ b/scripts/gen_relocate_app.py
@@ -99,6 +99,7 @@
#include <zephyr.h>
#include <linker/linker-defs.h>
#include <kernel_structs.h>
+#include <string.h>
"""
EXTERN_LINKER_VAR_DECLARATION = """
diff --git a/soc/arm/atmel_sam/sam3x/soc.c b/soc/arm/atmel_sam/sam3x/soc.c
index 6a04b34..f71a256 100644
--- a/soc/arm/atmel_sam/sam3x/soc.c
+++ b/soc/arm/atmel_sam/sam3x/soc.c
@@ -18,7 +18,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/*
* 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 ec43117..99e75e3 100644
--- a/soc/arm/atmel_sam/sam4s/soc.c
+++ b/soc/arm/atmel_sam/sam4s/soc.c
@@ -18,7 +18,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 3da8cc9..c6a521d 100644
--- a/soc/arm/atmel_sam/same70/soc.c
+++ b/soc/arm/atmel_sam/same70/soc.c
@@ -14,7 +14,7 @@
#include <device.h>
#include <init.h>
#include <soc.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <logging/log.h>
#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 4c9db13..7532aaa 100644
--- a/soc/arm/atmel_sam0/common/soc_samd2x.c
+++ b/soc/arm/atmel_sam0/common/soc_samd2x.c
@@ -10,7 +10,7 @@
*/
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <device.h>
#include <init.h>
#include <kernel.h>
diff --git a/soc/arm/cypress/psoc6/soc.c b/soc/arm/cypress/psoc6/soc.c
index 3db3da9..a9f4797 100644
--- a/soc/arm/cypress/psoc6/soc.c
+++ b/soc/arm/cypress/psoc6/soc.c
@@ -7,7 +7,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 22168cb..e06ad83 100644
--- a/soc/arm/microchip_mec/mec1501/soc.c
+++ b/soc/arm/microchip_mec/mec1501/soc.c
@@ -9,7 +9,7 @@
#include <soc.h>
#include <kernel.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/*
diff --git a/soc/arm/nordic_nrf/nrf51/CMakeLists.txt b/soc/arm/nordic_nrf/nrf51/CMakeLists.txt
index 9dd6e2d..a657548 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 28dcff5..8aaf65d 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 aac12e8..0dba393 100644
--- a/soc/arm/nordic_nrf/nrf52/soc.c
+++ b/soc/arm/nordic_nrf/nrf52/soc.c
@@ -14,7 +14,7 @@
#include <kernel.h>
#include <init.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <hal/nrf_power.h>
#include <soc/nrfx_coredep.h>
#include <logging/log.h>
diff --git a/soc/arm/nordic_nrf/nrf91/soc.c b/soc/arm/nordic_nrf/nrf91/soc.c
index ec87222..86cad4c 100644
--- a/soc/arm/nordic_nrf/nrf91/soc.c
+++ b/soc/arm/nordic_nrf/nrf91/soc.c
@@ -14,7 +14,7 @@
#include <kernel.h>
#include <init.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <soc/nrfx_coredep.h>
#include <logging/log.h>
diff --git a/soc/arm/nxp_imx/mcimx6x_m4/soc.c b/soc/arm/nxp_imx/mcimx6x_m4/soc.c
index ee6425f..d92fc7c 100644
--- a/soc/arm/nxp_imx/mcimx6x_m4/soc.c
+++ b/soc/arm/nxp_imx/mcimx6x_m4/soc.c
@@ -7,7 +7,7 @@
#include <init.h>
#include <soc.h>
#include <dt-bindings/rdc/imx_rdc.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 e5e16ad..0f43e0d 100644
--- a/soc/arm/nxp_imx/rt/soc.c
+++ b/soc/arm/nxp_imx/rt/soc.c
@@ -11,7 +11,7 @@
#include <linker/sections.h>
#include <fsl_clock.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <fsl_flexspi_nor_boot.h>
#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 1916c88..8746fc4 100644
--- a/soc/arm/nxp_kinetis/k2x/soc.c
+++ b/soc/arm/nxp_kinetis/k2x/soc.c
@@ -23,7 +23,7 @@
#include <fsl_common.h>
#include <fsl_clock.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 df6b225..6901fc0 100644
--- a/soc/arm/nxp_kinetis/k6x/soc.c
+++ b/soc/arm/nxp_kinetis/k6x/soc.c
@@ -21,7 +21,7 @@
#include <fsl_common.h>
#include <fsl_clock.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 017c235..9aaf8d7 100644
--- a/soc/arm/nxp_kinetis/ke1xf/soc.c
+++ b/soc/arm/nxp_kinetis/ke1xf/soc.c
@@ -13,7 +13,7 @@
#include <init.h>
#include <fsl_clock.h>
#include <fsl_cache.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 961b9b9..6a881b4 100644
--- a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c
+++ b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c
@@ -14,7 +14,7 @@
#include <fsl_common.h>
#include <fsl_clock.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 2347dcb..6f78f98 100644
--- a/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt
+++ b/soc/arm/nxp_lpc/lpc54xxx/CMakeLists.txt
@@ -9,6 +9,11 @@
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 11b82e7..9c635e0 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 aaeccb1..6a8a274 100644
--- a/soc/arm/silabs_exx32/common/soc.c
+++ b/soc/arm/silabs_exx32/common/soc.c
@@ -16,7 +16,7 @@
#include <em_emu.h>
#include <em_chip.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <logging/log.h>
diff --git a/soc/arm/st_stm32/stm32f0/soc.c b/soc/arm/st_stm32/stm32f0/soc.c
index 902b44a..1ddd24c 100644
--- a/soc/arm/st_stm32/stm32f0/soc.c
+++ b/soc/arm/st_stm32/stm32f0/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <linker/linker-defs.h>
#include <string.h>
diff --git a/soc/arm/st_stm32/stm32f1/soc.c b/soc/arm/st_stm32/stm32f1/soc.c
index aa83f74..b312956 100644
--- a/soc/arm/st_stm32/stm32f1/soc.c
+++ b/soc/arm/st_stm32/stm32f1/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 61dd442..0f2e137 100644
--- a/soc/arm/st_stm32/stm32f2/soc.c
+++ b/soc/arm/st_stm32/stm32f2/soc.c
@@ -14,7 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <linker/linker-defs.h>
#include <string.h>
diff --git a/soc/arm/st_stm32/stm32f3/soc.c b/soc/arm/st_stm32/stm32f3/soc.c
index f70d15e..937d896 100644
--- a/soc/arm/st_stm32/stm32f3/soc.c
+++ b/soc/arm/st_stm32/stm32f3/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 3350908..bfd088a 100644
--- a/soc/arm/st_stm32/stm32f4/soc.c
+++ b/soc/arm/st_stm32/stm32f4/soc.c
@@ -13,7 +13,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 f93d9b6..01f14d5 100644
--- a/soc/arm/st_stm32/stm32f7/soc.c
+++ b/soc/arm/st_stm32/stm32f7/soc.c
@@ -14,7 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 a85413f..b67f5c7 100644
--- a/soc/arm/st_stm32/stm32g0/soc.c
+++ b/soc/arm/st_stm32/stm32g0/soc.c
@@ -13,7 +13,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <linker/linker-defs.h>
#include <string.h>
diff --git a/soc/arm/st_stm32/stm32g4/soc.c b/soc/arm/st_stm32/stm32g4/soc.c
index 3a28991..ea7d7c9 100644
--- a/soc/arm/st_stm32/stm32g4/soc.c
+++ b/soc/arm/st_stm32/stm32g4/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 d1f744a..2c2866f 100644
--- a/soc/arm/st_stm32/stm32h7/soc_m4.c
+++ b/soc/arm/st_stm32/stm32h7/soc_m4.c
@@ -14,7 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 ae62151..09e9289 100644
--- a/soc/arm/st_stm32/stm32h7/soc_m7.c
+++ b/soc/arm/st_stm32/stm32h7/soc_m7.c
@@ -14,7 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#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 fe8619d..6f1f4d7 100644
--- a/soc/arm/st_stm32/stm32l0/soc.c
+++ b/soc/arm/st_stm32/stm32l0/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <linker/linker-defs.h>
#include <string.h>
diff --git a/soc/arm/st_stm32/stm32l1/soc.c b/soc/arm/st_stm32/stm32l1/soc.c
index ef08ec6..6f5ea3d 100644
--- a/soc/arm/st_stm32/stm32l1/soc.c
+++ b/soc/arm/st_stm32/stm32l1/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
#include <linker/linker-defs.h>
#include <string.h>
diff --git a/soc/arm/st_stm32/stm32l4/soc.c b/soc/arm/st_stm32/stm32l4/soc.c
index 45f3e7b..e2e0d86 100644
--- a/soc/arm/st_stm32/stm32l4/soc.c
+++ b/soc/arm/st_stm32/stm32l4/soc.c
@@ -13,7 +13,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 870b105..b83d24b 100644
--- a/soc/arm/st_stm32/stm32mp1/soc.c
+++ b/soc/arm/st_stm32/stm32mp1/soc.c
@@ -14,7 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @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 359389b..9c09562 100644
--- a/soc/arm/st_stm32/stm32wb/soc.c
+++ b/soc/arm/st_stm32/stm32wb/soc.c
@@ -12,7 +12,7 @@
#include <device.h>
#include <init.h>
#include <arch/cpu.h>
-#include <cortex_m/exc.h>
+#include <arch/arm/cortex_m/cmsis.h>
/**
* @brief Perform basic hardware initialization at boot.
diff --git a/soc/arm/ti_lm3s6965/CMakeLists.txt b/soc/arm/ti_lm3s6965/CMakeLists.txt
index 3b889a2..1701f41 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 aa335c0..2338f910 100644
--- a/soc/arm/ti_lm3s6965/soc.h
+++ b/soc/arm/ti_lm3s6965/soc.h
@@ -67,10 +67,6 @@
#ifndef _ASMLANGUAGE
-#include <device.h>
-#include <sys/util.h>
-#include <random/rand32.h>
-
#endif /* !_ASMLANGUAGE */
#endif /* _BOARD__H_ */
diff --git a/soc/posix/inf_clock/CMakeLists.txt b/soc/posix/inf_clock/CMakeLists.txt
index 326f584..276b2fb 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 ade53b4..4a5b972 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 <arch/posix/posix_soc_if.h>
#ifdef __cplusplus
extern "C" {
diff --git a/soc/posix/inf_clock/soc.c b/soc/posix/inf_clock/soc.c
index 590ce6f..9345101 100644
--- a/soc/posix/inf_clock/soc.c
+++ b/soc/posix/inf_clock/soc.c
@@ -28,7 +28,7 @@
#include <pthread.h>
#include <stdbool.h>
#include <unistd.h>
-#include "posix_soc_if.h"
+#include <arch/posix/posix_soc_if.h>
#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 15bd2ad..5eb906c 100644
--- a/subsys/debug/openocd.c
+++ b/subsys/debug/openocd.c
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <kernel_structs.h>
+#include <kernel.h>
#define OPENOCD_UNIMPLEMENTED 0xffffffff
diff --git a/subsys/debug/tracing/CMakeLists.txt b/subsys/debug/tracing/CMakeLists.txt
index 96163eb..b283fbb 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 1420104..0e7cf12 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 7f97b5a..4d28f75 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 <arch/posix/posix_trace.h>
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 02efcc5..a41338b 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 <kernel.h>
#include <init.h>
-#include <kernel_internal.h>
#include <SEGGER_SYSVIEW.h>
#include <Global.h>
diff --git a/subsys/logging/log_backend_native_posix.c b/subsys/logging/log_backend_native_posix.c
index b26457e..106fa82 100644
--- a/subsys/logging/log_backend_native_posix.c
+++ b/subsys/logging/log_backend_native_posix.c
@@ -12,7 +12,7 @@
#include <logging/log_msg.h>
#include <logging/log_output.h>
#include <irq.h>
-#include "posix_trace.h"
+#include <arch/posix/posix_trace.h>
#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 9795b31..b795750 100644
--- a/subsys/net/ip/CMakeLists.txt
+++ b/subsys/net/ip/CMakeLists.txt
@@ -44,6 +44,11 @@
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 90300ca..56235b8 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 @@
return 0;
}
-#include <sys/arch_inlines.h>
+#include <sys/arch_interface.h>
#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 0122f42..0000000
--- 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 344cc63..e865b3e 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 4763876..fa7afe4 100644
--- a/tests/arch/arm/arm_thread_swap/CMakeLists.txt
+++ b/tests/arch/arm/arm_thread_swap/CMakeLists.txt
@@ -6,3 +6,8 @@
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 a5214b0..1344355 100644
--- a/tests/arch/x86/static_idt/CMakeLists.txt
+++ b/tests/arch/x86/static_idt/CMakeLists.txt
@@ -8,3 +8,8 @@
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 82f1140..9441df2 100644
--- a/tests/arch/x86/static_idt/src/main.c
+++ b/tests/arch/x86/static_idt/src/main.c
@@ -16,7 +16,7 @@
#include <tc_util.h>
#include <arch/x86/ia32/segmentation.h>
-#include <kernel_structs.h>
+#include <kernel_internal.h>
#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 126f003..adc711d 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 <arch/x86/mmustructs.h>
#include <linker/linker-defs.h>
#include <ztest.h>
-#include <kernel_internal.h>
#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 260f461..2de72b4 100644
--- a/tests/benchmarks/boot_time/CMakeLists.txt
+++ b/tests/benchmarks/boot_time/CMakeLists.txt
@@ -6,3 +6,8 @@
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 282e113..720f39f 100644
--- a/tests/benchmarks/sched/CMakeLists.txt
+++ b/tests/benchmarks/sched/CMakeLists.txt
@@ -5,3 +5,8 @@
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 6109876..5de4e17 100644
--- a/tests/benchmarks/timing_info/CMakeLists.txt
+++ b/tests/benchmarks/timing_info/CMakeLists.txt
@@ -7,3 +7,8 @@
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 38c813f..35a7f91 100644
--- a/tests/boards/altera_max10/msgdma/CMakeLists.txt
+++ b/tests/boards/altera_max10/msgdma/CMakeLists.txt
@@ -6,3 +6,8 @@
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 500225c..2d5e0d9 100644
--- a/tests/boards/altera_max10/msgdma/src/dma.c
+++ b/tests/boards/altera_max10/msgdma/src/dma.c
@@ -6,7 +6,7 @@
#include <ztest.h>
#include <soc.h>
-#include <kernel_structs.h>
+#include <kernel_arch_func.h>
#include <device.h>
#include <drivers/dma.h>
diff --git a/tests/crypto/rand32/CMakeLists.txt b/tests/crypto/rand32/CMakeLists.txt
index 5a51e1b..0c3c4ee 100644
--- a/tests/crypto/rand32/CMakeLists.txt
+++ b/tests/crypto/rand32/CMakeLists.txt
@@ -8,3 +8,8 @@
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 2282a0c..dd6b855 100644
--- a/tests/kernel/fatal/CMakeLists.txt
+++ b/tests/kernel/fatal/CMakeLists.txt
@@ -6,3 +6,8 @@
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 8b6b3881..a6baec3 100644
--- a/tests/kernel/fifo/fifo_timeout/src/main.c
+++ b/tests/kernel/fifo/fifo_timeout/src/main.c
@@ -6,7 +6,6 @@
#include <ztest.h>
#include <irq_offload.h>
-#include <ksched.h>
#include <sys/__assert.h>
#include <sys/util.h>
diff --git a/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt b/tests/kernel/mem_pool/mem_pool_api/CMakeLists.txt
index b0658f4..e8503cd 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 @@
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 1bd002d..f8f12a1 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 <ztest.h>
#include <irq_offload.h>
-#include "test_mpool.h"
#include <kernel_internal.h>
+#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 038cb34..1021b6a 100644
--- a/tests/kernel/mem_protect/obj_validation/CMakeLists.txt
+++ b/tests/kernel/mem_protect/obj_validation/CMakeLists.txt
@@ -6,3 +6,8 @@
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 c0f1535..85d46ba 100644
--- a/tests/kernel/sched/schedule_api/CMakeLists.txt
+++ b/tests/kernel/sched/schedule_api/CMakeLists.txt
@@ -6,3 +6,8 @@
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 5057011..6d4b514 100644
--- a/tests/kernel/smp/CMakeLists.txt
+++ b/tests/kernel/smp/CMakeLists.txt
@@ -5,3 +5,8 @@
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 f004ae2..d953578 100644
--- a/tests/kernel/threads/thread_apis/CMakeLists.txt
+++ b/tests/kernel/threads/thread_apis/CMakeLists.txt
@@ -6,3 +6,8 @@
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 4ffef71..a7dc6df 100644
--- a/tests/lib/mem_alloc/src/main.c
+++ b/tests/lib/mem_alloc/src/main.c
@@ -20,7 +20,6 @@
#include <ztest.h>
#include <stdlib.h>
#include <errno.h>
-#include <kernel_internal.h>
#define BUF_LEN 10