diff --git a/arch/arc/arcem/port.h b/arch/arc/arcem/port.h index af36a6c7..78002452 100644 --- a/arch/arc/arcem/port.h +++ b/arch/arc/arcem/port.h @@ -44,219 +44,7 @@ #define _PORT_H_ #if TOS_CFG_FAULT_BACKTRACE_EN > 0u -typedef struct port_fault_regs { - union { - /* System Handler Control and State Register (0xE000ED24) */ - uint32_t value; - struct { - /* Read as 1 if memory management fault is active */ - uint32_t MEMFAULTACT : 1; - /* Read as 1 if bus fault exception is active */ - uint32_t BUSFAULTACT : 1; - uint32_t UnusedBits1 : 1; - /* Read as 1 if usage fault exception is active */ - uint32_t USGFAULTACT : 1; - uint32_t UnusedBits2 : 3; - /* Read as 1 if SVC exception is active */ - uint32_t SVCALLACT : 1; - /* Read as 1 if debug monitor exception is active */ - uint32_t MONITORACT : 1; - uint32_t UnusedBits3 : 1; - /* Read as 1 if PendSV exception is active */ - uint32_t PENDSVACT : 1; - /* Read as 1 if SYSTICK exception is active */ - uint32_t SYSTICKACT : 1; - /* Usage fault pended; usage fault started but was replaced by a higher-priority exception */ - uint32_t USGFAULTPENDED : 1; - /* Memory management fault pended; memory management fault started but was replaced by a - higher-priority exception */ - uint32_t MEMFAULTPENDED : 1; - /* Bus fault pended; bus fault handler was started but was replaced by a higher-priority - exception */ - uint32_t BUSFAULTPENDED : 1; - /* SVC pended; SVC was started but was replaced by a higher-priority exception */ - uint32_t SVCALLPENDED : 1; - /* Memory management fault handler enable */ - uint32_t MEMFAULTENA : 1; - /* Bus fault handler enable */ - uint32_t BUSFAULTENA : 1; - /* Usage fault handler enable */ - uint32_t USGFAULTENA : 1; - } bits; - } syshndctrl; - union { - uint32_t value; - - struct { - union { - /* Memory Management Fault Status Register (0xE000ED28) */ - uint8_t value; - struct { - /* Instruction access violation */ - uint8_t IACCVIOL : 1; - /* Data access violation */ - uint8_t DACCVIOL : 1; - uint8_t UnusedBits : 1; - /* Unstacking error */ - uint8_t MUNSTKERR : 1; - /* Stacking error */ - uint8_t MSTKERR : 1; - /* Floating-point lazy state preservation (M4/M7) */ - uint8_t MLSPERR : 1; - uint8_t UnusedBits2 : 1; - /* Indicates the MMAR is valid */ - uint8_t MMARVALID : 1; - } bits; - } mfsr; - - union { - /* Bus Fault Status Register (0xE000ED29) */ - uint8_t value; - struct { - /* Instruction access violation */ - uint8_t IBUSERR : 1; - /* Precise data access violation */ - uint8_t PRECISERR : 1; - /* Imprecise data access violation */ - uint8_t IMPREISERR : 1; - /* Unstacking error */ - uint8_t UNSTKERR : 1; - /* Stacking error */ - uint8_t STKERR : 1; - /* Floating-point lazy state preservation (M4/M7) */ - uint8_t LSPERR : 1; - uint8_t UnusedBits : 1; - /* Indicates BFAR is valid */ - uint8_t BFARVALID : 1; - } bits; - } bfsr; - - union { - /* Usage Fault Status Register (0xE000ED2A) */ - uint16_t value; - struct { - /* Attempts to execute an undefined instruction */ - uint16_t UNDEFINSTR : 1; - /* Attempts to switch to an invalid state (e.g., ARM) */ - uint16_t INVSTATE : 1; - /* Attempts to do an exception with a bad value in the EXC_RETURN number */ - uint16_t INVPC : 1; - /* Attempts to execute a coprocessor instruction */ - uint16_t NOCP : 1; - uint16_t UnusedBits : 4; - /* Indicates that an unaligned access fault has taken place */ - uint16_t UNALIGNED : 1; - /* Indicates a divide by zero has taken place (can be set only if DIV_0_TRP is set) */ - uint16_t DIVBYZERO0 : 1; - } bits; - } ufsr; - } part; - } cfsr; - - /* Memory Management Fault Address Register (0xE000ED34) */ - uint32_t mmar; - - /* Bus Fault Manage Address Register (0xE000ED38) */ - uint32_t bfar; - - union { - /* Hard Fault Status Register (0xE000ED2C) */ - uint32_t value; - struct { - uint32_t UnusedBits : 1; - /* Indicates hard fault is caused by failed vector fetch */ - uint32_t VECTBL : 1; - uint32_t UnusedBits2 : 28; - /* Indicates hard fault is taken because of bus fault/memory management fault/usage fault */ - uint32_t FORCED : 1; - /* Indicates hard fault is triggered by debug event */ - uint32_t DEBUGEVT : 1; - } bits; - } hfsr; - - union { - /* Debug Fault Status Register (0xE000ED30) */ - uint32_t value; - struct { - /* Halt requested in NVIC */ - uint32_t HALTED : 1; - /* BKPT instruction executed */ - uint32_t BKPT : 1; - /* DWT match occurred */ - uint32_t DWTTRAP : 1; - /* Vector fetch occurred */ - uint32_t VCATCH : 1; - /* EDBGRQ signal asserted */ - uint32_t EXTERNAL : 1; - } bits; - } dfsr; - - /* Auxiliary Fault Status Register (0xE000ED3C), Vendor controlled (optional) */ - uint32_t afsr; -} port_fault_regs_t; - -enum fault_info { - FAULT_INFO_ASSERT_ON_THREAD, - FAULT_INFO_HFSR_VECTBL, - FAULT_INFO_MFSR_IACCVIOL, - FAULT_INFO_MFSR_DACCVIOL, - FAULT_INFO_MFSR_MUNSTKERR, - FAULT_INFO_MFSR_MSTKERR, - FAULT_INFO_MFSR_MLSPERR, - FAULT_INFO_BFSR_IBUSERR, - FAULT_INFO_BFSR_PRECISERR, - FAULT_INFO_BFSR_IMPREISERR, - FAULT_INFO_BFSR_UNSTKERR, - FAULT_INFO_BFSR_STKERR, - FAULT_INFO_BFSR_LSPERR, - FAULT_INFO_UFSR_UNDEFINSTR, - FAULT_INFO_UFSR_INVSTATE, - FAULT_INFO_UFSR_INVPC, - FAULT_INFO_UFSR_NOCP, - FAULT_INFO_UFSR_UNALIGNED, - FAULT_INFO_UFSR_DIVBYZERO0, - FAULT_INFO_DFSR_HALTED, - FAULT_INFO_DFSR_BKPT, - FAULT_INFO_DFSR_DWTTRAP, - FAULT_INFO_DFSR_VCATCH, - FAULT_INFO_DFSR_EXTERNAL, - FAULT_INFO_MMAR, - FAULT_INFO_BFAR, -}; - -static const char *const fault_msg[] = { - [FAULT_INFO_ASSERT_ON_THREAD] = "Assert on thread %s\n", - [FAULT_INFO_HFSR_VECTBL] = "Hard fault is caused by failed vector fetch\n", - [FAULT_INFO_MFSR_IACCVIOL] = "Memory management fault: instruction access violation\n", - [FAULT_INFO_MFSR_DACCVIOL] = "Memory management fault: data access violation\n", - [FAULT_INFO_MFSR_MUNSTKERR] = "Memory management fault: unstacking error\n", - [FAULT_INFO_MFSR_MSTKERR] = "Memory management fault: stacking error\n", - [FAULT_INFO_MFSR_MLSPERR] = "Memory management fault: floating-point lazy state preservation\n", - [FAULT_INFO_BFSR_IBUSERR] = "Bus fault: instruction access violation\n", - [FAULT_INFO_BFSR_PRECISERR] = "Bus fault: precise data access violation\n", - [FAULT_INFO_BFSR_IMPREISERR] = "Bus fault: imprecise data access violation\n", - [FAULT_INFO_BFSR_UNSTKERR] = "Bus fault: unstacking error\n", - [FAULT_INFO_BFSR_STKERR] = "Bus fault: stacking error\n", - [FAULT_INFO_BFSR_LSPERR] = "Bus fault: floating-point lazy state preservation\n", - [FAULT_INFO_UFSR_UNDEFINSTR] = "Usage fault: undefined instruction\n", - [FAULT_INFO_UFSR_INVSTATE] = "Usage fault: invalid state (e.g., ARM)\n", - [FAULT_INFO_UFSR_INVPC] = "Usage fault: invalid EXC_RETURN\n", - [FAULT_INFO_UFSR_NOCP] = "Usage fault: coprocessor instruction\n", - [FAULT_INFO_UFSR_UNALIGNED] = "Usage fault: unaligned access\n", - [FAULT_INFO_UFSR_DIVBYZERO0] = "Usage fault: divide by zero(can be set only if DIV_0_TRP is set)\n", - [FAULT_INFO_DFSR_HALTED] = "Debug fault: halt requested in NVIC\n", - [FAULT_INFO_DFSR_BKPT] = "Debug fault: BKPT instruction executed\n", - [FAULT_INFO_DFSR_DWTTRAP] = "Debug fault: DWT match occurred\n", - [FAULT_INFO_DFSR_VCATCH] = "Debug fault: Vector fetch occurred\n", - [FAULT_INFO_DFSR_EXTERNAL] = "Debug fault: EDBGRQ signal asserted\n", - [FAULT_INFO_MMAR] = "The memory management fault occurred address is %08x\n", - [FAULT_INFO_BFAR] = "The bus fault occurred address is %08x\n", -}; - -__PORT__ void HardFault_Handler(void); - -__PORT__ void port_fault_diagnosis(void); #endif #if defined(TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT) && (TOS_CFG_CPU_LEAD_ZEROS_ASM_PRESENT == 1u) diff --git a/arch/arc/arcem/port_s.s b/arch/arc/arcem/port_s.s index 23fd5c13..7c1fad40 100644 --- a/arch/arc/arcem/port_s.s +++ b/arch/arc/arcem/port_s.s @@ -32,54 +32,6 @@ dispatch_r: RESTORE_NONSCRATCH_REGS j [blink] -/* - * void port_int_disable(void); - */ - .global port_int_disable - .align 4 -port_int_disable: - clri - j [blink] - -/* - * void port_int_enable(void); - */ - .global port_int_enable - .align 4 -port_int_enable: - seti - j [blink] - -/* - * cpu_cpsr_t port_cpsr_save(void); - */ - .global port_cpsr_save - .align 4 -port_cpsr_save: - clri r0 - j [blink] - -/* - * void port_cpsr_restore(cpu_cpsr_t cpsr); - */ - .global port_cpsr_restore - .align 4 -port_cpsr_restore: - seti r0 - j [blink] - -/* - * uint32_t port_cpu_clz(uint32_t val) - * r0 --> val - */ - .global port_cpu_clz - .align 4 -port_cpu_clz: - breq r0, 0, cpu_clz_return - ffs r1, r0 - add r0, r1, 1 -cpu_clz_return: - j [blink] /* * void port_sched_start(void) @@ -128,12 +80,8 @@ start_r: pop r2 pop r0 -#if defined(__MW__) - j_s.d [r1] -#else - j [r1] -#endif kflag r2 + j [r1] /****** exceptions and interrupts handing ******/ /****** entry for exception handling ******/ @@ -356,9 +304,16 @@ firq_hint_handled: firq_return: RESTORE_FIQ_EXC_REGS rtie - - - - - - + +/* + * uint32_t port_cpu_clz(uint32_t val) + * r0 --> val + */ + .global port_cpu_clz + .align 4 +port_cpu_clz: + breq r0, 0, cpu_clz_return + ffs r1, r0 + add r0, r1, 1 +cpu_clz_return: + j [blink] diff --git a/arch/arc/common/include/tos_cpu.h b/arch/arc/common/include/tos_cpu.h index 1b092a08..dc6c1832 100644 --- a/arch/arc/common/include/tos_cpu.h +++ b/arch/arc/common/include/tos_cpu.h @@ -114,20 +114,6 @@ __KNL__ void cpu_standby_mode_enter(void); #endif -#if TOS_CFG_FAULT_BACKTRACE_EN > 0u - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - - -__KNL__ void cpu_flush_fpu(void); - -#endif /* TOS_CFG_CPU_ARM_FPU_EN */ - - -__KNL__ void cpu_fault_diagnosis(void); - -#endif - /* Allocates CPU status register word. */ #define TOS_CPU_CPSR_ALLOC() cpu_cpsr_t cpu_cpsr = (cpu_cpsr_t)0u diff --git a/arch/arc/common/include/tos_fault.h b/arch/arc/common/include/tos_fault.h index 784c5f9d..b8d1b377 100644 --- a/arch/arc/common/include/tos_fault.h +++ b/arch/arc/common/include/tos_fault.h @@ -26,204 +26,6 @@ typedef int (*k_fault_log_writer_t)(const char *format, ...); #define K_FAULT_CALL_STACK_BACKTRACE_DEPTH 5u -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) -typedef struct fault_fpu_frame_st { - cpu_data_t s0; - cpu_data_t s1; - cpu_data_t s2; - cpu_data_t s3; - cpu_data_t s4; - cpu_data_t s5; - cpu_data_t s6; - cpu_data_t s7; - cpu_data_t s8; - cpu_data_t s9; - cpu_data_t s10; - cpu_data_t s11; - cpu_data_t s12; - cpu_data_t s13; - cpu_data_t s14; - cpu_data_t s15; - cpu_data_t fpscr; -} fault_fpu_frame_t; -#endif - -typedef struct fault_cpu_frame_st { - cpu_data_t r0; - cpu_data_t r1; - cpu_data_t r2; - cpu_data_t r3; - cpu_data_t r12; - cpu_data_t lr; - cpu_data_t pc; - cpu_data_t spsr; -} fault_cpu_frame_t; - -typedef struct fault_exc_frame_st { - fault_cpu_frame_t cpu_frame; - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - fault_fpu_frame_t fpu_frame; -#endif -} fault_exc_frame_t; - -/** - * information we need to do fault backtrace - */ -typedef struct fault_information_st { - int is_thumb : 1; /**< whether it is thumb we use when we fall into fault? */ - int is_on_task : 1; /**< whether we are on a task when fall into fault? */ - int is_stk_ovrf : 1; /**< whether we get a stack overflow */ - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - int is_ext_stk_frm : 1; /**< whether it is a extended stack frame?(whether the cpu has pushed fpu registers onto the stack) */ -#endif - - cpu_addr_t pc; /**< just where fault happens */ - - cpu_addr_t sp_before_fault; /**< original sp just before the cpu push the fault exception frame */ - - /** - * we need main_stack_start & main_stack_limit to do call stack backtrace - * when we fall into fault during a task, we should do the call stack backtrace on the task's stack - * but if not, which means we are in kernel, we should do the call stack backtrace on the main stack - * in arm v7-m, this should be the MSP's start and limit - * in arm v7-a, call stack backtrace is another story(much more elegant because we have FP). - */ - cpu_addr_t stack_start; /**< current sp start address we use. if on task, it'll be the task's stack, otherwise it'll be the msp */ - cpu_addr_t stack_limit; /**< current sp limit address */ - cpu_addr_t code_start; /**< current code start address */ - cpu_addr_t code_limit; /**< current code limit address */ -} fault_info_t; - -#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) - -#define DEFAULT_CODE_SECTION_NAME ER_IROM1 -#define DEFAULT_CSTACK_SECTION_NAME STACK - -#define SECTION_START(_name_) _name_##$$Base -#define SECTION_END(_name_) _name_##$$Limit -#define IMAGE_SECTION_START(_name_) Image$$##_name_##$$Base -#define IMAGE_SECTION_END(_name_) Image$$##_name_##$$Limit -#define CSTACK_BLOCK_START(_name_) SECTION_START(_name_) -#define CSTACK_BLOCK_END(_name_) SECTION_END(_name_) -#define CODE_SECTION_START(_name_) IMAGE_SECTION_START(_name_) -#define CODE_SECTION_END(_name_) IMAGE_SECTION_END(_name_) - -extern const int CSTACK_BLOCK_START(DEFAULT_CSTACK_SECTION_NAME); -extern const int CSTACK_BLOCK_END(DEFAULT_CSTACK_SECTION_NAME); -extern const int CODE_SECTION_START(DEFAULT_CODE_SECTION_NAME); -extern const int CODE_SECTION_END(DEFAULT_CODE_SECTION_NAME); - -__STATIC_INLINE__ cpu_addr_t fault_code_start(void) -{ - return (cpu_addr_t)&CODE_SECTION_START(DEFAULT_CODE_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_code_limit(void) -{ - return (cpu_addr_t)&CODE_SECTION_END(DEFAULT_CODE_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_start(void) -{ - return (cpu_addr_t)&CSTACK_BLOCK_START(DEFAULT_CSTACK_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_limit(void) -{ - return (cpu_addr_t)&CSTACK_BLOCK_END(DEFAULT_CSTACK_SECTION_NAME); -} - -#elif defined(__ICCARM__) - -#define DEFAULT_CODE_SECTION_NAME ".text" -#define DEFAULT_CSTACK_SECTION_NAME "CSTACK" - -#pragma section=DEFAULT_CSTACK_SECTION_NAME -#pragma section=DEFAULT_CODE_SECTION_NAME - -__STATIC_INLINE__ cpu_addr_t fault_code_start(void) -{ - return (cpu_addr_t)__section_begin(DEFAULT_CODE_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_code_limit(void) -{ - return (cpu_addr_t)__section_end(DEFAULT_CODE_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_start(void) -{ - return (cpu_addr_t)__section_begin(DEFAULT_CSTACK_SECTION_NAME); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_limit(void) -{ - return (cpu_addr_t)__section_end(DEFAULT_CSTACK_SECTION_NAME); -} - -#elif defined(__GNUC__) - -/** - * if we are using keil(armcc) or mdk(iccarm), we probably use the defult link script supplied by the IDE. - * the way to locate the text/stack section start and limit is to find them in default link script. - * but if we build our project by makefile(or something like scons, cmake, etc), we probably need to write - * our own link scrpit, if so, we should do like this(just a demo): - * - _stext = .; - .text : { - *(.text.startup) - *(.text) - *(.text.*) - } - _etext = .; - - __bss_start = .; - .bss : { - *(.bss) - *(.bss.*) - *(COMMON) - _sstack = .; - *(.cstack) - _estack = .; - } - __bss_end = .; - * by this, we can locate text/stack section start and limit by _stext/_etext and _sstack/_estack - */ -#define DEFAULT_CODE_SECTION_START _stext -#define DEFAULT_CODE_SECTION_END _etext -#define DEFAULT_CSTACK_SECTION_START _sstack -#define DEFAULT_CSTACK_SECTION_END _estack - -extern const int DEFAULT_CODE_SECTION_START; -extern const int DEFAULT_CODE_SECTION_END; - -extern const int DEFAULT_CSTACK_SECTION_START; -extern const int DEFAULT_CSTACK_SECTION_END; - -__STATIC_INLINE__ cpu_addr_t fault_code_start(void) -{ - return (cpu_addr_t)(&(DEFAULT_CODE_SECTION_START)); -} - -__STATIC_INLINE__ cpu_addr_t fault_code_limit(void) -{ - return (cpu_addr_t)(&(DEFAULT_CODE_SECTION_END)); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_start(void) -{ - return (cpu_addr_t)(&(DEFAULT_CSTACK_SECTION_START)); -} - -__STATIC_INLINE__ cpu_addr_t fault_msp_limit(void) -{ - return (cpu_addr_t)(&(DEFAULT_CSTACK_SECTION_END)); -} - -#endif - __API__ void tos_fault_log_writer_set(k_fault_log_writer_t log_writer); __KERNEL__ int fault_default_log_writer(const char *format, ...); diff --git a/arch/arc/common/tos_cpu.c b/arch/arc/common/tos_cpu.c index 11eb0838..cfba2814 100644 --- a/arch/arc/common/tos_cpu.c +++ b/arch/arc/common/tos_cpu.c @@ -61,22 +61,22 @@ __API__ uint32_t tos_cpu_clz(uint32_t val) __API__ void tos_cpu_int_disable(void) { - port_int_disable(); + arc_lock(); } __API__ void tos_cpu_int_enable(void) { - port_int_enable(); + arc_unlock(); } __API__ cpu_cpsr_t tos_cpu_cpsr_save(void) { - return port_cpsr_save(); + return (cpu_cpsr_t)arc_lock_save(); } __API__ void tos_cpu_cpsr_restore(cpu_cpsr_t cpsr) { - port_cpsr_restore(cpsr); + arc_unlock_restore(cpsr); } __KNL__ void cpu_init(void) @@ -219,7 +219,7 @@ __KNL__ k_stack_t *cpu_task_stk_init(void *entry, cpu_context_t *regs = 0; sp = (cpu_data_t *)&stk_base[stk_size]; - sp = (cpu_data_t *)((cpu_addr_t)sp & 0xFFFFFFC); + sp = (cpu_data_t *)((cpu_addr_t)sp & 0xFFFFFFFC); sp -= (sizeof(cpu_context_t)/sizeof(cpu_data_t)); regs = (cpu_context_t*) sp; @@ -229,7 +229,6 @@ __KNL__ k_stack_t *cpu_task_stk_init(void *entry, regs->status32 = ARC_INIT_STATUS; regs->r0 = (cpu_data_t)arg; - return (k_stack_t *)sp; } @@ -264,11 +263,4 @@ __KNL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_siz #if TOS_CFG_FAULT_BACKTRACE_EN > 0u - -__KNL__ void cpu_fault_diagnosis(void) -{ - port_fault_diagnosis(); -} - #endif /* TOS_CFG_FAULT_BACKTRACE_EN */ - diff --git a/arch/arc/common/tos_embarc.c b/arch/arc/common/tos_embarc.c new file mode 100644 index 00000000..4531cc6e --- /dev/null +++ b/arch/arc/common/tos_embarc.c @@ -0,0 +1,56 @@ +/* ------------------------------------------ + * Copyright (c) 2020, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + --------------------------------------------- */ + +#include +#include "cmsis_os.h" +#include "embARC.h" +#include "embARC_debug.h" + +#define APPLICATION_TASK_STK_SIZE 1024 +extern void application_entry(void *arg); +osThreadDef(application_entry, osPriorityNormal, 1, APPLICATION_TASK_STK_SIZE); + +EMBARC_WEAK void application_entry(void *arg) +{ + while (1) { + printf("This is a demo task,please use your task entry!\r\n"); + tos_task_delay(1000); + } +} + +int main(void) +{ + /* OS kernel initialization */ + osKernelInitialize(); + /* application initialization entry */ + osThreadCreate(osThread(application_entry), NULL); + /* start kernel */ + osKernelStart(); +} \ No newline at end of file diff --git a/arch/arc/common/tos_fault.c b/arch/arc/common/tos_fault.c deleted file mode 100644 index 65ae7e02..00000000 --- a/arch/arc/common/tos_fault.c +++ /dev/null @@ -1,268 +0,0 @@ -/*---------------------------------------------------------------------------- - * Tencent is pleased to support the open source community by making TencentOS - * available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * If you have downloaded a copy of the TencentOS binary from Tencent, please - * note that the TencentOS binary is licensed under the BSD 3-Clause License. - * - * If you have downloaded a copy of the TencentOS source code from Tencent, - * please note that TencentOS source code is licensed under the BSD 3-Clause - * License, except for the third-party components listed below which are - * subject to different license terms. Your integration of TencentOS into your - * own projects may require compliance with the BSD 3-Clause License, as well - * as the other licenses applicable to the third-party components included - * within TencentOS. - *---------------------------------------------------------------------------*/ - -#include "tos_k.h" - -#if TOS_CFG_FAULT_BACKTRACE_EN > 0u - -__STATIC_INLINE__ void fault_spin(void) -{ - tos_knl_sched_lock(); - tos_cpu_int_disable(); - while (K_TRUE) { - ; - } -} - -/* EXC_RETURN: - 31 - 28 : EXC_RETURN flag - 27 - 5 : reserved - 4 : 1, basic stack frame; 0, extended stack frame - 3 : 1, return to Thread mode; 0, return to Handler mode - 2 : 1, return to PSP; 0, return to MSP - 1 : reserved, 0 - 0 : reserved, 1 - */ -__STATIC_INLINE__ int fault_is_on_task(cpu_data_t lr) -{ - return (lr & (1u << 2)) != 0; -} - -__STATIC_INLINE__ int fault_is_thumb(cpu_data_t psr) -{ - return (psr & (1u << 24)) != 0; -} - -__STATIC_INLINE__ int fault_is_code(fault_info_t *info, cpu_data_t value) -{ - return value >= info->code_start && value <= info->code_limit; -} - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) -__STATIC_INLINE__ int fault_is_extended_stack_frame(cpu_data_t lr) -{ - return (lr & (1u << 4)) == 0; -} - -__STATIC__ void fault_dump_fpu_frame(fault_fpu_frame_t *fpu_frame) -{ - /* - * As known, v7-m has a feature named "LAZY PUSH", for the reason we do not do any float - * operation in fault_backtrace, cpu will not do the real fpu register push to the stack. - * that means the value we dump in fault_dump_fpu_frame will not be the correct value of - * each FPU register. - * We define a function here which access to FPSCR, if this function involved, cpu will do - * the real FPU register push so we will get the correct dump. - * I know it's ugly, but it works. If you know a better way, please tell me. - */ - cpu_flush_fpu(); - - k_fault_log_writer("\n\n====================== FPU Registers =======================\n"); - k_fault_log_writer(" %s: %08x\n", "FPSCR", fpu_frame->fpscr); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "S0 ", fpu_frame->s0, - "S1 ", fpu_frame->s1, - "S2 ", fpu_frame->s2, - "S3 ", fpu_frame->s3); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "S4 ", fpu_frame->s4, - "S5 ", fpu_frame->s5, - "S6 ", fpu_frame->s6, - "S7 ", fpu_frame->s7); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "S8 ", fpu_frame->s8, - "S9 ", fpu_frame->s9, - "S10", fpu_frame->s10, - "S11", fpu_frame->s11); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "S12", fpu_frame->s12, - "S13", fpu_frame->s13, - "S14", fpu_frame->s14, - "S15", fpu_frame->s15); -} - -#endif - -__STATIC__ void fault_dump_cpu_frame(fault_cpu_frame_t *cpu_frame) -{ - k_fault_log_writer("\n\n====================== CPU Registers =======================\n"); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "R0 ", cpu_frame->r0, - "R1 ", cpu_frame->r1, - "R2 ", cpu_frame->r2, - "R3 ", cpu_frame->r3); - k_fault_log_writer(" %s: %08x %s: %08x %s: %08x %s: %08x\n", - "R12", cpu_frame->r12, - "LR ", cpu_frame->lr, - "PC ", cpu_frame->pc, - "PSR", cpu_frame->spsr); -} - -__STATIC__ void fault_dump_stack(fault_info_t *info, size_t depth) -{ - cpu_addr_t sp = info->sp_before_fault;; - - k_fault_log_writer("\nTASK STACK DUMP:\n"); - while (sp <= info->stack_limit && depth--) { - k_fault_log_writer(" addr: %08x data: %08x\n", sp, (cpu_data_t)*(cpu_data_t *)sp); - sp += sizeof(cpu_addr_t); - } -} - -__STATIC__ void fault_call_stack_backtrace(fault_info_t *info, size_t depth) -{ - cpu_data_t value; - cpu_addr_t sp = info->sp_before_fault; - - if (info->is_stk_ovrf) { - return; - } - - k_fault_log_writer("\n\n====================== Dump Call Stack =====================\n"); - - k_fault_log_writer(" %x\n", info->pc); - - /* walk through the stack, check every content on stack whether is a instruction(code) */ - for (; sp < info->stack_limit && depth; sp += sizeof(cpu_addr_t)) { - value = *((cpu_addr_t *)sp) - sizeof(cpu_addr_t); - - /* if thumb, a instruction's first bit must be 1 */ - if (info->is_thumb && !(value & 1)) { - continue; - } - - if (fault_is_code(info, value)) { - k_fault_log_writer(" %x\n", value); - --depth; - } - } -} - -__STATIC__ void fault_dump_task(fault_info_t *info) -{ - k_task_t *task; - - if (!info->is_on_task) { - return; - } - - task = k_curr_task; - k_fault_log_writer("\n\n====================== Fault on task =======================\n"); - k_fault_log_writer(" TASK NAME: %s\n", task->name); - k_fault_log_writer(" STK BASE: %x\n", info->stack_start); - k_fault_log_writer(" STK SIZE: %x\n", task->stk_size * sizeof(k_stack_t)); - k_fault_log_writer(" STK LIMIT: %x\n", info->stack_limit); - - if (!info->is_stk_ovrf) { - fault_dump_stack(info, K_FAULT_STACK_DUMP_DEPTH); - } -} - -__STATIC__ void fault_dump_information(fault_info_t *info) -{ - k_fault_log_writer("\n\n================== Dump Fault Information ==================\n"); - k_fault_log_writer(" THUMB: %s\n", info->is_thumb ? "TRUE" : "FALSE"); - k_fault_log_writer(" ON TASK: %s\n", info->is_on_task? "TRUE" : "FALSE"); - k_fault_log_writer(" STK OVRF: %s\n", info->is_stk_ovrf? "TRUE" : "FALSE"); - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - k_fault_log_writer(" EXT STK: %s\n", info->is_ext_stk_frm? "TRUE" : "FALSE"); -#endif - - k_fault_log_writer(" PC: %08x\n", info->pc); - k_fault_log_writer(" SP: %08x\n", info->sp_before_fault); - k_fault_log_writer(" STK START: %08x\n", info->stack_start); - k_fault_log_writer(" STK LIMIT: %08x\n", info->stack_limit); - k_fault_log_writer(" COD START: %08x\n", info->code_start); - k_fault_log_writer(" COD LIMIT: %08x\n", info->code_limit); -} - -__STATIC__ void fault_gather_information(cpu_data_t lr, fault_exc_frame_t *frame, fault_info_t *info) -{ - info->is_thumb = fault_is_thumb(frame->cpu_frame.spsr); - info->is_on_task = fault_is_on_task(lr); - - info->pc = frame->cpu_frame.pc; - - info->sp_before_fault = (cpu_addr_t)frame + sizeof(fault_cpu_frame_t); - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - info->is_ext_stk_frm = fault_is_extended_stack_frame(lr); - - if (info->is_ext_stk_frm) { - info->sp_before_fault += sizeof(fault_fpu_frame_t); - } -#endif - - info->code_start = fault_code_start(); - info->code_limit = fault_code_limit(); - - if (info->is_on_task) { - info->stack_start = (cpu_addr_t)k_curr_task->stk_base; - info->stack_limit = info->stack_start + k_curr_task->stk_size * sizeof(k_task_t); - } else { - info->stack_start = fault_msp_start(); - info->stack_limit = fault_msp_limit(); - } - - info->is_stk_ovrf = (info->sp_before_fault < info->stack_start || info->sp_before_fault > info->stack_limit); -} - -__KERNEL__ int fault_default_log_writer(const char *format, ...) -{ - int len; - va_list ap; - - va_start(ap, format); - len = vprintf(format, ap); - va_end(ap); - - return len; -} - -__API__ void tos_fault_log_writer_set(k_fault_log_writer_t log_writer) -{ - k_fault_log_writer = log_writer; -} - -__KERNEL__ void fault_backtrace(cpu_addr_t lr, fault_exc_frame_t *frame) -{ - fault_info_t info; - - fault_gather_information(lr, frame, &info); - - fault_dump_information(&info); - - fault_dump_task(&info); - - fault_dump_cpu_frame(&frame->cpu_frame); - -#if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) - if (info.is_ext_stk_frm) { - fault_dump_fpu_frame(&frame->fpu_frame); - } -#endif - - fault_call_stack_backtrace(&info, K_FAULT_CALL_STACK_BACKTRACE_DEPTH); - - cpu_fault_diagnosis(); - - fault_spin(); -} - -#endif - diff --git a/board/ARC_NSIM_EM/BSP/Inc/tos_config.h b/board/ARC_NSIM_EM/BSP/Inc/tos_config.h index a7ffe2e7..1c3eebe1 100644 --- a/board/ARC_NSIM_EM/BSP/Inc/tos_config.h +++ b/board/ARC_NSIM_EM/BSP/Inc/tos_config.h @@ -4,29 +4,29 @@ #include "stddef.h" #include "embARC.h" -#define TOS_CFG_TASK_PRIO_MAX 10u // 配置TencentOS tiny默认支持的最大优先级数量 +#define TOS_CFG_TASK_PRIO_MAX 10u -#define TOS_CFG_ROUND_ROBIN_EN 1u // 配置TencentOS tiny的内核是否开启时间片轮转 +#define TOS_CFG_ROUND_ROBIN_EN 1u -#define TOS_CFG_OBJECT_VERIFY 0u // 配置TencentOS tiny是否校验指针合法 +#define TOS_CFG_OBJECT_VERIFY 0u -#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 事件模块功能宏 +#define TOS_CFG_EVENT_EN 1u -#define TOS_CFG_MMHEAP_EN 1u // 配置TencentOS tiny是否开启动态内存模块 +#define TOS_CFG_MMHEAP_EN 1u -#define TOS_CFG_MMHEAP_POOL_SIZE (1024*20) // 配置TencentOS tiny动态内存池大小 +#define TOS_CFG_MMHEAP_POOL_SIZE (1024*20) -#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE (1024*20) // 配置TencentOS tiny动态内存池大小 +#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE (1024*20) -#define TOS_CFG_MUTEX_EN 1u // 配置TencentOS tiny是否开启互斥锁模块 +#define TOS_CFG_MUTEX_EN 1u -#define TOS_CFG_QUEUE_EN 1u // 配置TencentOS tiny是否开启队列模块 +#define TOS_CFG_QUEUE_EN 1u -#define TOS_CFG_TIMER_EN 1u // 配置TencentOS tiny是否开启软件定时器模块 +#define TOS_CFG_TIMER_EN 1u -#define TOS_CFG_SEM_EN 1u // 配置TencentOS tiny是否开启信号量模块 +#define TOS_CFG_SEM_EN 1u -#define TOS_CFG_MMBLK_EN 1u +#define TOS_CFG_MMBLK_EN 1u #if (TOS_CFG_QUEUE_EN > 0u) #define TOS_CFG_MSG_EN 1u @@ -34,14 +34,14 @@ #define TOS_CFG_MSG_EN 0u #endif -#define TOS_CFG_MSG_POOL_SIZE 10u // 配置TencentOS tiny消息队列大小 +#define TOS_CFG_MSG_POOL_SIZE 10u -#define TOS_CFG_IDLE_TASK_STK_SIZE 256u // 配置TencentOS tiny空闲任务栈大小 +#define TOS_CFG_IDLE_TASK_STK_SIZE 256u -#define TOS_CFG_CPU_TICK_PER_SECOND 100u // 配置TencentOS tiny的tick频率 +#define TOS_CFG_CPU_TICK_PER_SECOND 100u -#define TOS_CFG_CPU_CLOCK BOARD_CPU_CLOCK // 配置TencentOS tiny CPU频率 +#define TOS_CFG_CPU_CLOCK BOARD_CPU_CLOCK -#define TOS_CFG_TIMER_AS_PROC 1u // 配置是否将TIMER配置成函数模式 +#define TOS_CFG_TIMER_AS_PROC 1u #endif \ No newline at end of file diff --git a/board/ARC_NSIM_EM/BSP/Src/main.c b/board/ARC_NSIM_EM/BSP/Src/main.c deleted file mode 100644 index b4b2bcfc..00000000 --- a/board/ARC_NSIM_EM/BSP/Src/main.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "cmsis_os.h" -#include - -extern void application_entry(void *arg); - -int main(void) -{ - printf("hello world\r\n"); - - printf("Welcome to TencentOS tiny\r\n"); - osKernelInitialize(); //TOS Tiny kernel initialize - application_entry(NULL); - osKernelStart(); //Start TOS Tiny -} diff --git a/board/ARC_NSIM_EM/hello_world/Makefile b/board/ARC_NSIM_EM/hello_world/Makefile index 1fc9980e..e606cdd5 100644 --- a/board/ARC_NSIM_EM/hello_world/Makefile +++ b/board/ARC_NSIM_EM/hello_world/Makefile @@ -1,13 +1,5 @@ -########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.3.0] date: [Mon Aug 05 10:29:11 CST 2019] -########################################################################################################################## - # ------------------------------------------------ -# Generic Makefile (based on gcc) -# -# ChangeLog : -# 2017-02-10 - Several enhancements + project update mode -# 2015-07-22 - first version +# Generic Makefile for Synopsys Designware ARC processor # ------------------------------------------------ ###################################### @@ -17,7 +9,6 @@ TARGET = TencentOS_tiny APPLICATION = hello_world - ###################################### # building variables ###################################### @@ -26,6 +17,7 @@ DEBUG = 1 # optimization OPT = -O0 +# the root of TencentOS Tiny TOP_DIR = ../../.. ####################################### @@ -64,7 +56,7 @@ $(info ######################################################################### $(info # #) $(info # embarc_bsp not exist!!! #) $(info # please git embarc_bsp from github #) -$(info # run cmd blew in folder /platform/vendor_bsp/Synopsys/ARC>: #) +$(info # run the following cmd in folder /platform/vendor_bsp/Synopsys/ARC>: #) $(info # git clone https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_bsp.git -b upstream #) $(info # #) $(info ######################################################################################################)