-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch: native: Run Zephyr natively in a POSIX OS
A new arch (posix) which relies on pthreads to emulate the context switching A new soc for it (inf_clock) which emulates a CPU running at an infinely high clock (so when the CPU is awaken it runs till completion in 0 time) A new board, which provides a trivial system tick timer and irq generation. Origin: Original Fixes #1891 Signed-off-by: Alberto Escolar Piedras <[email protected]> Signed-off-by: Anas Nashif <[email protected]>
- Loading branch information
Showing
42 changed files
with
2,324 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
zephyr_cc_option_ifdef(CONFIG_LTO -flto) | ||
|
||
zephyr_compile_options( | ||
-fno-freestanding | ||
-Wno-undef | ||
-Wno-implicit-function-declaration | ||
-m32 | ||
-MMD | ||
-MP | ||
${TOOLCHAIN_C_FLAGS} | ||
${ARCH_FLAG} | ||
-include ${PROJECT_SOURCE_DIR}/arch/posix/include/posix_cheats.h | ||
) | ||
|
||
zephyr_compile_definitions(_POSIX_C_SOURCE=199309) | ||
|
||
zephyr_ld_options( | ||
-ldl | ||
-pthread | ||
-m32 | ||
) | ||
|
||
# About the -include directive: The reason to do it this way, is because in this | ||
# manner it is transparent to the application. Otherwise posix_cheats.h needs to | ||
# be included in all the applications' files which define main( ), and in any | ||
# app file which uses the pthreads like API provided by Zephyr | ||
# ( include/posix/pthread.h / kernel/pthread.c ) [And any future API added to | ||
# Zephyr which will clash with the native POSIX API] . It would also need to | ||
# be included in a few zephyr kernel files. | ||
|
||
|
||
add_subdirectory(soc) | ||
add_subdirectory(core) | ||
|
||
# Override the flag used with linker.cmd | ||
# "-Wl,--just-symbols linker.cmd" instead of "-T linker.cmd" | ||
set_property(GLOBAL PROPERTY TOPT -Wl,--just-symbols) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Kconfig - General configuration options | ||
|
||
# | ||
# Copyright (c) 2017 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
choice | ||
prompt "POSIX Configuration Selection" | ||
depends on ARCH_POSIX | ||
|
||
source "arch/posix/soc/*/Kconfig.soc" | ||
endchoice | ||
|
||
menu "POSIX (native) Options" | ||
depends on ARCH_POSIX | ||
|
||
config ARCH | ||
default "posix" | ||
|
||
config ARCH_DEFCONFIG | ||
string | ||
default "arch/posix/defconfig" | ||
|
||
source "arch/posix/core/Kconfig" | ||
|
||
|
||
source "arch/posix/soc/*/Kconfig" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
zephyr_library() | ||
zephyr_library_compile_definitions(_POSIX_CHEATS_H) | ||
zephyr_library_sources( | ||
cpuhalt.c | ||
fatal.c | ||
posix_core.c | ||
swap.c | ||
thread.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2011-2015 Wind River Systems, Inc. | ||
* Copyright (c) 2017 Oticon A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
/** | ||
* @file CPU power management code for POSIX | ||
* | ||
* This module provides an implementation of the architecture-specific | ||
* k_cpu_idle() primitive required by the kernel idle loop component. | ||
* It can be called within an implementation of _sys_power_save_idle(), | ||
* which is provided for the kernel by the platform. | ||
* | ||
* The module also provides an implementation of k_cpu_atomic_idle(), which | ||
* atomically re-enables interrupts and enters low power mode. | ||
* | ||
*/ | ||
|
||
#include "posix_core.h" | ||
#include "posix_soc_if.h" | ||
|
||
/** | ||
* | ||
* @brief Power save idle routine for IA-32 | ||
* | ||
* This function will be called by the kernel idle loop or possibly within | ||
* an implementation of _sys_power_save_idle in the kernel when the | ||
* '_sys_power_save_flag' variable is non-zero. | ||
* | ||
* This function is just a pass thru to the SOC one | ||
* | ||
* @return N/A | ||
*/ | ||
void k_cpu_idle(void) | ||
{ | ||
posix_irq_full_unlock(); | ||
posix_halt_cpu(); | ||
} | ||
|
||
/** | ||
* | ||
* @brief Atomically re-enable interrupts and enter low power mode | ||
* | ||
* INTERNAL | ||
* The requirements for k_cpu_atomic_idle() are as follows: | ||
* 1) The enablement of 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 'imask' input parameter. | ||
* | ||
* This function is just a pass thru to the SOC one | ||
* | ||
* @return N/A | ||
*/ | ||
|
||
void k_cpu_atomic_idle(unsigned int imask) | ||
{ | ||
posix_atomic_halt_cpu(imask); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) 2016 Intel Corporation | ||
* Copyright (c) 2017 Oticon A/S | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <arch/cpu.h> | ||
#include <kernel_structs.h> | ||
#include <misc/printk.h> | ||
#include <inttypes.h> | ||
#include "posix_soc_if.h" | ||
|
||
const NANO_ESF _default_esf = { | ||
0xdeadbaad | ||
}; | ||
|
||
/** | ||
* | ||
* @brief Kernel fatal error handler | ||
* | ||
* This routine is called when a fatal error condition is detected | ||
* | ||
* The caller is expected to always provide a usable ESF. In the event that the | ||
* fatal error does not have a hardware generated ESF, the caller should either | ||
* create its own or call _Fault instead. | ||
* | ||
* @param reason the reason that the handler was called | ||
* @param pEsf pointer to the exception stack frame | ||
* | ||
* @return This function does not return. | ||
*/ | ||
FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, | ||
const NANO_ESF *esf) | ||
{ | ||
#ifdef CONFIG_PRINTK | ||
switch (reason) { | ||
case _NANO_ERR_CPU_EXCEPTION: | ||
case _NANO_ERR_SPURIOUS_INT: | ||
break; | ||
|
||
case _NANO_ERR_INVALID_TASK_EXIT: | ||
printk("***** Invalid Exit Software Error! *****\n"); | ||
break; | ||
|
||
|
||
case _NANO_ERR_ALLOCATION_FAIL: | ||
printk("**** Kernel Allocation Failure! ****\n"); | ||
break; | ||
|
||
case _NANO_ERR_KERNEL_OOPS: | ||
printk("***** Kernel OOPS! *****\n"); | ||
break; | ||
|
||
case _NANO_ERR_KERNEL_PANIC: | ||
printk("***** Kernel Panic! *****\n"); | ||
break; | ||
|
||
#ifdef CONFIG_STACK_SENTINEL | ||
case _NANO_ERR_STACK_CHK_FAIL: | ||
printk("***** Stack overflow *****\n"); | ||
break; | ||
#endif | ||
default: | ||
printk("**** Unknown Fatal Error %u! ****\n", reason); | ||
break; | ||
} | ||
|
||
#endif | ||
|
||
void _SysFatalErrorHandler(unsigned int reason, | ||
const NANO_ESF *pEsf); | ||
_SysFatalErrorHandler(reason, esf); | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @brief Fatal error handler | ||
* | ||
* This routine implements the corrective action to be taken when the system | ||
* detects a fatal error. | ||
* | ||
* This sample implementation attempts to abort the current thread and allow | ||
* the system to continue executing, which may permit the system to continue | ||
* functioning with degraded capabilities. | ||
* | ||
* System designers may wish to enhance or substitute this sample | ||
* implementation to take other actions, such as logging error (or debug) | ||
* information to a persistent repository and/or rebooting the system. | ||
* | ||
* @param reason the fatal error reason | ||
* @param pEsf pointer to exception stack frame | ||
* | ||
* @return N/A | ||
*/ | ||
FUNC_NORETURN __weak void _SysFatalErrorHandler(unsigned int reason, | ||
const NANO_ESF *pEsf) | ||
{ | ||
ARG_UNUSED(pEsf); | ||
|
||
#ifdef CONFIG_STACK_SENTINEL | ||
if (reason == _NANO_ERR_STACK_CHK_FAIL) { | ||
goto hang_system; | ||
} | ||
#endif | ||
if (reason == _NANO_ERR_KERNEL_PANIC) { | ||
goto hang_system; | ||
} | ||
if (k_is_in_isr() || _is_thread_essential()) { | ||
posix_print_error_and_exit( | ||
"Fatal fault in %s! Stopping...\n", | ||
k_is_in_isr() ? "ISR" : "essential thread"); | ||
} | ||
printk("Fatal fault in thread %p! Aborting.\n", _current); | ||
k_thread_abort(_current); | ||
|
||
hang_system: | ||
|
||
posix_print_error_and_exit( | ||
"Stopped in _SysFatalErrorHandler()\n"); | ||
CODE_UNREACHABLE; | ||
} |
Oops, something went wrong.