From b82a3398138dcbbcc32b70b4b377baeeb772ea17 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Tue, 4 Dec 2018 17:15:27 -0800 Subject: [PATCH] kernel: init: Add nop instruction in main The main function is just a weak function that should be override by the applications if they need. Just adding a nop instructions to explicitly says that this function does nothing. MISRA-C rule 2.2 Signed-off-by: Flavio Ceolin --- include/arch/arc/arch.h | 9 +++++++++ include/arch/arm/cortex_m/misc.h | 9 +++++++++ include/arch/nios2/arch.h | 8 ++++++++ include/arch/posix/arch.h | 8 ++++++++ include/arch/riscv32/arch.h | 9 +++++++++ include/arch/x86/arch.h | 9 +++++++++ include/arch/xtensa/arch.h | 8 ++++++++ kernel/init.c | 1 + 8 files changed, 61 insertions(+) diff --git a/include/arch/arc/arch.h b/include/arch/arc/arch.h index c15ba9add74..092427692bf 100644 --- a/include/arch/arc/arch.h +++ b/include/arch/arc/arch.h @@ -220,6 +220,15 @@ extern "C" { #ifndef _ASMLANGUAGE /* Typedef for the k_mem_partition attribute*/ typedef u32_t k_mem_partition_attr_t; + +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + #endif /* _ASMLANGUAGE */ #ifdef __cplusplus diff --git a/include/arch/arm/cortex_m/misc.h b/include/arch/arm/cortex_m/misc.h index 5e592364533..76945a1a0e3 100644 --- a/include/arch/arm/cortex_m/misc.h +++ b/include/arch/arm/cortex_m/misc.h @@ -23,6 +23,15 @@ extern void k_cpu_idle(void); extern u32_t _timer_cycle_get_32(void); #define _arch_k_cycle_get_32() _timer_cycle_get_32() + +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + #endif #ifdef __cplusplus diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index 2449b24f398..9dd0d4e7053 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -201,6 +201,14 @@ enum nios2_exception_cause { extern u32_t _timer_cycle_get_32(void); #define _arch_k_cycle_get_32() _timer_cycle_get_32() +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + #endif /* _ASMLANGUAGE */ #ifdef __cplusplus diff --git a/include/arch/posix/arch.h b/include/arch/posix/arch.h index f0c9b2fd70b..48f96a0643c 100644 --- a/include/arch/posix/arch.h +++ b/include/arch/posix/arch.h @@ -54,6 +54,14 @@ FUNC_NORETURN void _SysFatalErrorHandler(unsigned int reason, FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *esf); +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + #ifdef __cplusplus } #endif diff --git a/include/arch/riscv32/arch.h b/include/arch/riscv32/arch.h index 439d37e4937..f280b464499 100644 --- a/include/arch/riscv32/arch.h +++ b/include/arch/riscv32/arch.h @@ -115,6 +115,15 @@ static ALWAYS_INLINE void _arch_irq_unlock(unsigned int key) : "memory"); } +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + + extern u32_t _timer_cycle_get_32(void); #define _arch_k_cycle_get_32() _timer_cycle_get_32() diff --git a/include/arch/x86/arch.h b/include/arch/x86/arch.h index dc0ec94a567..4a89db9b3ea 100644 --- a/include/arch/x86/arch.h +++ b/include/arch/x86/arch.h @@ -453,6 +453,15 @@ static ALWAYS_INLINE void _arch_irq_unlock(unsigned int key) _do_irq_unlock(); } +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + + /** * The NANO_SOFT_IRQ macro must be used as the value for the @a irq parameter * to NANO_CPU_INT_REGISTER when connecting to an interrupt that does not diff --git a/include/arch/xtensa/arch.h b/include/arch/xtensa/arch.h index b6efd9301a3..021afccf986 100644 --- a/include/arch/xtensa/arch.h +++ b/include/arch/xtensa/arch.h @@ -134,6 +134,14 @@ XTENSA_ERR_NORET void _NanoFatalErrorHandler(unsigned int reason, extern u32_t _timer_cycle_get_32(void); #define _arch_k_cycle_get_32() _timer_cycle_get_32() +/** + * @brief Explicitly nop operation. + */ +static ALWAYS_INLINE void arch_nop(void) +{ + __asm__ volatile("nop"); +} + #endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */ #ifdef __cplusplus } diff --git a/kernel/init.c b/kernel/init.c index d8c3bc3b953..9d2d7329482 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -259,6 +259,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3) void __weak main(void) { /* NOP default main() if the application does not provide one. */ + arch_nop(); } #if defined(CONFIG_MULTITHREADING)