diff --git a/Kconfig b/Kconfig index ccf86320393b5f0a0195cc9330a9060f91167c27..fbf80924e61f9bc44e12b89c4ce322d6d90f2826 100644 --- a/Kconfig +++ b/Kconfig @@ -165,6 +165,7 @@ config THUMB default n help Answer Y to build thumb version. This will make LiteOS smaller. + config PLATFORM_DVFS bool "Enable Dvfs" default n @@ -173,6 +174,12 @@ config PLATFORM_DVFS Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for low power consumption. +config SAVE_EXCINFO + bool "Enable Saving Exception Information" + default n + help + Answer Y to enable LiteOS support saving exception information to storage medium. + config DEBUG_VERSION bool "Enable a Debug Version" default n diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c index dd94396d09c725bef499c00029445f1aed63fe6c..7b047fcd7f433a25ad4e2ea1b48d3f3fc8a0974b 100644 --- a/arch/arm/arm/src/los_exc.c +++ b/arch/arm/arm/src/los_exc.c @@ -34,7 +34,7 @@ #include "los_printf_pri.h" #include "los_task_pri.h" #include "los_hw_pri.h" -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #ifdef LOSCFG_EXC_INTERACTION @@ -576,7 +576,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr) #endif #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO OsProcessExitCodeCoreDumpSet(runProcess); #endif OsProcessExitCodeSignalSet(runProcess, SIGUSR2); @@ -1086,6 +1086,22 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far) } } +#ifdef LOSCFG_SAVE_EXCINFO +STATIC VOID OsSysStateSave(UINT32 *intCount, UINT32 *lockCount) +{ + *intCount = g_intCount[ArchCurrCpuid()]; + *lockCount = OsPercpuGet()->taskLockCnt; + g_intCount[ArchCurrCpuid()] = 0; + OsPercpuGet()->taskLockCnt = 0; +} + +STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount) +{ + g_intCount[ArchCurrCpuid()] = intCount; + OsPercpuGet()->taskLockCnt = lockCount; +} +#endif + /* * Description : EXC handler entry * Input : excType --- exc type @@ -1093,6 +1109,11 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far) */ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) { +#ifdef LOSCFG_SAVE_EXCINFO + UINT32 intCount; + UINT32 lockCount; +#endif + /* Task scheduling is not allowed during exception handling */ OsPercpuGet()->taskLockCnt++; @@ -1106,18 +1127,18 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd OsAllCpuStatusOutput(); #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO log_read_write_fn func = GetExcInfoRW(); #endif if (g_excHook != NULL) { if (g_curNestCount[ArchCurrCpuid()] == 1) { -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO if (func != NULL) { SetExcInfoIndex(0); - g_intCount[ArchCurrCpuid()] = 0; + OsSysStateSave(&intCount, &lockCount); OsRecordExcInfoTime(); - g_intCount[ArchCurrCpuid()] = 1; + OsSysStateRestore(intCount, lockCount); } #endif g_excHook(excType, excBufAddr, far, fsr); @@ -1125,12 +1146,12 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd OsCallStackInfo(); } -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO if (func != NULL) { PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex()); - g_intCount[ArchCurrCpuid()] = 0; + OsSysStateSave(&intCount, &lockCount); func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf()); - g_intCount[ArchCurrCpuid()] = 1; + OsSysStateRestore(intCount, lockCount); } #endif } diff --git a/kernel/base/misc/mempt_shellcmd.c b/kernel/base/misc/mempt_shellcmd.c index 50322068d55c974364243f2b3db8b0870b8900d3..333d5b284097830e18982a170cba991418ceb1fe 100644 --- a/kernel/base/misc/mempt_shellcmd.c +++ b/kernel/base/misc/mempt_shellcmd.c @@ -31,7 +31,7 @@ #include "stdlib.h" #include "los_memory_pri.h" -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #ifdef LOSCFG_SHELL @@ -64,7 +64,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) while (dataLen) { if (IS_ALIGNED(count, sizeof(CHAR *))) { PRINTK("\n 0x%lx :", alignAddr); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("\n 0x%lx :", alignAddr); #endif } @@ -73,7 +73,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) #else PRINTK("%0+8lx ", *alignAddr); #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #ifdef __LP64__ WriteExcInfoToBuf("0x%0+16x ", *alignAddr); #else @@ -85,7 +85,7 @@ VOID OsDumpMemByte(size_t length, UINTPTR addr) count++; } PRINTK("\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("\n"); #endif @@ -101,14 +101,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]) if (LOS_MemIntegrityCheck(m_aucSysMem1) == LOS_OK) { PRINTK("system memcheck over, all passed!\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("system memcheck over, all passed!\n"); #endif } #ifdef LOSCFG_EXC_INTERACTION if (LOS_MemIntegrityCheck(m_aucSysMem0) == LOS_OK) { PRINTK("exc interaction memcheck over, all passed!\n"); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcInfoToBuf("exc interaction memcheck over, all passed!\n"); #endif } diff --git a/kernel/base/misc/task_shellcmd.c b/kernel/base/misc/task_shellcmd.c index 7c918e1ced929f88d49f20a9f1d70191a38ca3be..49671f7dd30fe2896fab4596859dbe5c90704836 100644 --- a/kernel/base/misc/task_shellcmd.c +++ b/kernel/base/misc/task_shellcmd.c @@ -43,7 +43,7 @@ #ifdef LOSCFG_KERNEL_CPUP #include "los_cpup_pri.h" #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #include "los_process_pri.h" diff --git a/kernel/common/los_config.h b/kernel/common/los_config.h index a59581c1c99565cd7ad06e0a488ad75ea7a0b7f6..7b9cb0ad3d0007babc8176b2940b84d50ed1eb5b 100644 --- a/kernel/common/los_config.h +++ b/kernel/common/los_config.h @@ -398,7 +398,7 @@ extern UINT32 __heap_end; #endif /****************************** exception information configuration ******************************/ -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO /** * @ingroup los_config * the size of space for recording exception information diff --git a/kernel/common/los_excinfo.c b/kernel/common/los_excinfo.c index 422600a21e38827f0230b8c50a26f57b84100b37..92ec64044d11f823ec8c16d92c6d0c5b8156f266 100644 --- a/kernel/common/los_excinfo.c +++ b/kernel/common/los_excinfo.c @@ -34,9 +34,11 @@ #ifdef LOSCFG_FS_VFS #include "fs/fs.h" #endif +#ifdef LOSCFG_SHELL +#include "shcmd.h" +#endif - -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO STATIC log_read_write_fn g_excInfoRW = NULL; /* the hook of read-writing exception information */ STATIC CHAR *g_excInfoBuf = NULL; /* pointer to the buffer for storing the exception information */ STATIC UINT32 g_excInfoIndex = 0xFFFFFFFF; /* the index of the buffer for storing the exception information */ @@ -164,5 +166,32 @@ VOID OsRecordExcInfoTime(VOID) #endif } +#ifdef LOSCFG_SHELL +INT32 OsShellCmdReadExcInfo(INT32 argc, CHAR **argv) +{ + UINT32 recordSpace = GetRecordSpace(); + + (VOID)argc; + (VOID)argv; + + CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1); + if (buf == NULL) { + return LOS_NOK; + } + (void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1); + + log_read_write_fn hook = GetExcInfoRW(); + if (hook != NULL) { + hook(GetRecordAddr(), recordSpace, 1, buf); + } + PRINTK("%s\n", buf); + (VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf); + buf = NULL; + return LOS_OK; +} + +SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)OsShellCmdReadExcInfo); +#endif + #endif diff --git a/kernel/common/los_excinfo_pri.h b/kernel/common/los_excinfo_pri.h index 24f0d0437635e868d2f30e5109adbbe7b86e27b8..ba68d5f402650e208b3b1221f5f938f250ddf15b 100644 --- a/kernel/common/los_excinfo_pri.h +++ b/kernel/common/los_excinfo_pri.h @@ -40,7 +40,7 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO extern VOID SetExcInfoRW(log_read_write_fn func); extern log_read_write_fn GetExcInfoRW(VOID); extern VOID SetExcInfoBuf(CHAR *buf); diff --git a/kernel/common/los_printf.c b/kernel/common/los_printf.c index 567348ff9acafd11ee5fc0a5e415c23aaa7fce22..b5d2a002ce6af6a2b507bb109e7ebf58f0a224cc 100644 --- a/kernel/common/los_printf.c +++ b/kernel/common/los_printf.c @@ -42,7 +42,7 @@ #ifdef LOSCFG_SHELL_DMESG #include "dmesg_pri.h" #endif -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO #include "los_excinfo_pri.h" #endif #include "los_exc_pri.h" @@ -250,7 +250,7 @@ VOID PrintExcInfo(const CHAR *fmt, ...) va_start(ap, fmt); /* uart output without print-spinlock */ OsVprintf(fmt, ap, EXC_OUTPUT); -#ifdef LOSCFG_SHELL_EXCINFO +#ifdef LOSCFG_SAVE_EXCINFO WriteExcBufVa(fmt, ap); #endif va_end(ap); diff --git a/shell/Kconfig b/shell/Kconfig index b37c5918092a97f6c1f05e096c89e5321ce88468..641c740ad805599b00e3e417a3d38743d8fdaef7 100644 --- a/shell/Kconfig +++ b/shell/Kconfig @@ -22,11 +22,4 @@ config SHELL_DMESG help Answer Y to enable LiteOS support shell dmesg. -config SHELL_EXCINFO - bool "Enable Shell excInfo" - default n - depends on DEBUG_VERSION && SHELL - help - Answer Y to enable LiteOS support shell excInfo. - endmenu diff --git a/shell/full/src/cmds/excinfo_shell.c b/shell/full/src/cmds/excinfo_shell.c deleted file mode 100644 index 85f3959c0884f0e6bd11b716657330d6a0687992..0000000000000000000000000000000000000000 --- a/shell/full/src/cmds/excinfo_shell.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 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 copyright holder 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 "shcmd.h" -#include "los_memory.h" -#ifdef LOSCFG_SHELL_EXCINFO -#include "los_excinfo_pri.h" - - -INT32 osShellCmdReadExcInfo(INT32 argc, CHAR **argv) -{ - UINT32 recordSpace = GetRecordSpace(); - - (VOID)argc; - (VOID)argv; - - CHAR *buf = (CHAR*)LOS_MemAlloc((void *)OS_SYS_MEM_ADDR, recordSpace + 1); - if (buf == NULL) { - return LOS_NOK; - } - (void)memset_s(buf, recordSpace + 1, 0, recordSpace + 1); - - log_read_write_fn hook = GetExcInfoRW(); - if (hook != NULL) { - hook(GetRecordAddr(), recordSpace, 1, buf); - } - PRINTK("%s\n", buf); - (VOID)LOS_MemFree((void *)OS_SYS_MEM_ADDR, buf); - buf = NULL; - return LOS_OK; -} -SHELLCMD_ENTRY(readExcInfo_shellcmd, CMD_TYPE_EX, "excInfo", 0, (CmdCallBackFunc)osShellCmdReadExcInfo); -#endif