10d163575Sopenharmony_ci/* 20d163575Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 30d163575Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 40d163575Sopenharmony_ci * 50d163575Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 60d163575Sopenharmony_ci * are permitted provided that the following conditions are met: 70d163575Sopenharmony_ci * 80d163575Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 90d163575Sopenharmony_ci * conditions and the following disclaimer. 100d163575Sopenharmony_ci * 110d163575Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 120d163575Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 130d163575Sopenharmony_ci * provided with the distribution. 140d163575Sopenharmony_ci * 150d163575Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 160d163575Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 170d163575Sopenharmony_ci * permission. 180d163575Sopenharmony_ci * 190d163575Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 200d163575Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 210d163575Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 220d163575Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 230d163575Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 240d163575Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 250d163575Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 260d163575Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 270d163575Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 280d163575Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 290d163575Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 300d163575Sopenharmony_ci */ 310d163575Sopenharmony_ci 320d163575Sopenharmony_ci/** 330d163575Sopenharmony_ci * @defgroup los_exc Exception handling 340d163575Sopenharmony_ci * @ingroup kernel 350d163575Sopenharmony_ci */ 360d163575Sopenharmony_ci#ifndef _LOS_EXC_H 370d163575Sopenharmony_ci#define _LOS_EXC_H 380d163575Sopenharmony_ci 390d163575Sopenharmony_ci#include "los_typedef.h" 400d163575Sopenharmony_ci#include "arch_config.h" 410d163575Sopenharmony_ci 420d163575Sopenharmony_ci#ifdef __cplusplus 430d163575Sopenharmony_ci#if __cplusplus 440d163575Sopenharmony_ciextern "C" { 450d163575Sopenharmony_ci#endif /* __cplusplus */ 460d163575Sopenharmony_ci#endif /* __cplusplus */ 470d163575Sopenharmony_ci 480d163575Sopenharmony_ci/** 490d163575Sopenharmony_ci * @ingroup los_exc 500d163575Sopenharmony_ci * Register information structure 510d163575Sopenharmony_ci * 520d163575Sopenharmony_ci * Description: register information stored when an exception occurs on an LPC2458 platform. 530d163575Sopenharmony_ci * 540d163575Sopenharmony_ci * Note: The following register names without uw are the register names used in the chip manual. 550d163575Sopenharmony_ci */ 560d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_ARM_AARCH64 570d163575Sopenharmony_ci#define EXC_GEN_REGS_NUM 30 580d163575Sopenharmony_citypedef struct { 590d163575Sopenharmony_ci UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */ 600d163575Sopenharmony_ci UINT64 LR; /**< Program returning address. X30 */ 610d163575Sopenharmony_ci UINT64 SP; 620d163575Sopenharmony_ci UINT64 regELR; 630d163575Sopenharmony_ci UINT64 SPSR; 640d163575Sopenharmony_ci} ExcContext; 650d163575Sopenharmony_ci#else 660d163575Sopenharmony_ci/* It has the same structure as TaskContext */ 670d163575Sopenharmony_citypedef struct { 680d163575Sopenharmony_ci UINT32 R4; 690d163575Sopenharmony_ci UINT32 R5; 700d163575Sopenharmony_ci UINT32 R6; 710d163575Sopenharmony_ci UINT32 R7; 720d163575Sopenharmony_ci UINT32 R8; 730d163575Sopenharmony_ci UINT32 R9; 740d163575Sopenharmony_ci UINT32 R10; 750d163575Sopenharmony_ci UINT32 R11; 760d163575Sopenharmony_ci 770d163575Sopenharmony_ci UINT32 SP; /**< svc sp */ 780d163575Sopenharmony_ci UINT32 reserved; /**< Reserved, multiplexing register */ 790d163575Sopenharmony_ci UINT32 USP; 800d163575Sopenharmony_ci UINT32 ULR; 810d163575Sopenharmony_ci UINT32 R0; /**< Register R0 */ 820d163575Sopenharmony_ci UINT32 R1; /**< Register R1 */ 830d163575Sopenharmony_ci UINT32 R2; /**< Register R2 */ 840d163575Sopenharmony_ci UINT32 R3; /**< Register R3 */ 850d163575Sopenharmony_ci UINT32 R12; /**< Register R12 */ 860d163575Sopenharmony_ci UINT32 LR; /**< Program returning address. */ 870d163575Sopenharmony_ci UINT32 PC; /**< PC pointer of the exceptional function */ 880d163575Sopenharmony_ci UINT32 regCPSR; 890d163575Sopenharmony_ci} ExcContext; 900d163575Sopenharmony_ci#endif 910d163575Sopenharmony_ci 920d163575Sopenharmony_ci/** 930d163575Sopenharmony_ci * @ingroup los_exc 940d163575Sopenharmony_ci * Exception information structure 950d163575Sopenharmony_ci * 960d163575Sopenharmony_ci * Description: exception information stored when an exception occurs on an LPC2458 platform. 970d163575Sopenharmony_ci * 980d163575Sopenharmony_ci */ 990d163575Sopenharmony_citypedef struct { 1000d163575Sopenharmony_ci UINT16 phase; /**< Phase in which an exception occurs */ 1010d163575Sopenharmony_ci UINT16 type; /**< Exception type */ 1020d163575Sopenharmony_ci UINT16 nestCnt; /**< Count of nested exception */ 1030d163575Sopenharmony_ci UINT16 reserved; /**< Reserved for alignment */ 1040d163575Sopenharmony_ci ExcContext *context; /**< Hardware context when an exception occurs */ 1050d163575Sopenharmony_ci} ExcInfo; 1060d163575Sopenharmony_ci 1070d163575Sopenharmony_ci/** 1080d163575Sopenharmony_ci * @ingroup los_exc 1090d163575Sopenharmony_ci * @brief Kernel FP Register address obtain function. 1100d163575Sopenharmony_ci * 1110d163575Sopenharmony_ci * @par Description: 1120d163575Sopenharmony_ci * The API is used to obtain the FP Register address. 1130d163575Sopenharmony_ci * @attention None. 1140d163575Sopenharmony_ci * 1150d163575Sopenharmony_ci * @param None. 1160d163575Sopenharmony_ci * 1170d163575Sopenharmony_ci * @retval #UINTPTR The FP Register address. 1180d163575Sopenharmony_ci * 1190d163575Sopenharmony_ci * @par Dependency: 1200d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 1210d163575Sopenharmony_ci * @see None. 1220d163575Sopenharmony_ci */ 1230d163575Sopenharmony_ciSTATIC INLINE UINTPTR Get_Fp(VOID) 1240d163575Sopenharmony_ci{ 1250d163575Sopenharmony_ci UINTPTR regFp; 1260d163575Sopenharmony_ci 1270d163575Sopenharmony_ci#ifdef LOSCFG_ARCH_ARM_AARCH64 1280d163575Sopenharmony_ci __asm__ __volatile__("mov %0, X29" : "=r"(regFp)); 1290d163575Sopenharmony_ci#else 1300d163575Sopenharmony_ci __asm__ __volatile__("mov %0, fp" : "=r"(regFp)); 1310d163575Sopenharmony_ci#endif 1320d163575Sopenharmony_ci 1330d163575Sopenharmony_ci return regFp; 1340d163575Sopenharmony_ci} 1350d163575Sopenharmony_ci 1360d163575Sopenharmony_ci/** 1370d163575Sopenharmony_ci * @ingroup los_exc 1380d163575Sopenharmony_ci * @brief Define an exception handling function hook. 1390d163575Sopenharmony_ci * 1400d163575Sopenharmony_ci * @par Description: 1410d163575Sopenharmony_ci * This API is used to define the exception handling function hook based on the type of 1420d163575Sopenharmony_ci * the exception handling function and record exceptions. 1430d163575Sopenharmony_ci * @attention None. 1440d163575Sopenharmony_ci * 1450d163575Sopenharmony_ci * @param None. 1460d163575Sopenharmony_ci * 1470d163575Sopenharmony_ci * @retval None. 1480d163575Sopenharmony_ci * 1490d163575Sopenharmony_ci * @par Dependency: 1500d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 1510d163575Sopenharmony_ci * @see None. 1520d163575Sopenharmony_ci */ 1530d163575Sopenharmony_citypedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32); 1540d163575Sopenharmony_ci 1550d163575Sopenharmony_ci/** 1560d163575Sopenharmony_ci * @ingroup los_exc 1570d163575Sopenharmony_ci * @brief Register an exception handling hook. 1580d163575Sopenharmony_ci * 1590d163575Sopenharmony_ci * @par Description: 1600d163575Sopenharmony_ci * This API is used to register an exception handling hook. 1610d163575Sopenharmony_ci * @attention If the hook is registered for multiple times, the hook registered at the last time is effective. 1620d163575Sopenharmony_ci * @attention The hook can be registered as NULL, indicating that the hook registration is canceled. 1630d163575Sopenharmony_ci * @param excHook [IN] Type #EXC_PROC_FUNC: hook function. 1640d163575Sopenharmony_ci * 1650d163575Sopenharmony_ci * @retval #LOS_OK The exception handling hook is successfully registered. 1660d163575Sopenharmony_ci * 1670d163575Sopenharmony_ci * @par Dependency: 1680d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 1690d163575Sopenharmony_ci * @see None. 1700d163575Sopenharmony_ci */ 1710d163575Sopenharmony_ciextern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook); 1720d163575Sopenharmony_ci 1730d163575Sopenharmony_ci/** 1740d163575Sopenharmony_ci * @ingroup los_exc 1750d163575Sopenharmony_ci * @brief Kernel panic function. 1760d163575Sopenharmony_ci * 1770d163575Sopenharmony_ci * @par Description: 1780d163575Sopenharmony_ci * Stack function that prints kernel panics. 1790d163575Sopenharmony_ci * @attention After this function is called and stack information is printed, the system will fail to respond. 1800d163575Sopenharmony_ci * @attention The input parameter can be NULL. 1810d163575Sopenharmony_ci * @param fmt [IN] Type #CHAR* : variadic argument. 1820d163575Sopenharmony_ci * 1830d163575Sopenharmony_ci * @retval #None. 1840d163575Sopenharmony_ci * 1850d163575Sopenharmony_ci * @par Dependency: 1860d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 1870d163575Sopenharmony_ci * @see None. 1880d163575Sopenharmony_ci */ 1890d163575Sopenharmony_ciNORETURN VOID LOS_Panic(const CHAR *fmt, ...); 1900d163575Sopenharmony_ci 1910d163575Sopenharmony_ci/** 1920d163575Sopenharmony_ci * @ingroup los_exc 1930d163575Sopenharmony_ci * @brief record LR function. 1940d163575Sopenharmony_ci * 1950d163575Sopenharmony_ci * @par Description: 1960d163575Sopenharmony_ci * @attention 1970d163575Sopenharmony_ci * @param LR [IN] Type #UINTPTR * LR buffer. 1980d163575Sopenharmony_ci * @param recordCount [IN] Type UINT32 record LR lay number. 1990d163575Sopenharmony_ci * @param jumpCount [IN] Type UINT32 ignore LR lay number. 2000d163575Sopenharmony_ci * 2010d163575Sopenharmony_ci * @retval #None. 2020d163575Sopenharmony_ci * 2030d163575Sopenharmony_ci * @par Dependency: 2040d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 2050d163575Sopenharmony_ci * @see None. 2060d163575Sopenharmony_ci */ 2070d163575Sopenharmony_ciVOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount); 2080d163575Sopenharmony_ci 2090d163575Sopenharmony_ci/** 2100d163575Sopenharmony_ci * @ingroup los_exc 2110d163575Sopenharmony_ci * @brief Kernel backtrace function. 2120d163575Sopenharmony_ci * 2130d163575Sopenharmony_ci * @par Description: 2140d163575Sopenharmony_ci * Backtrace function that prints task call stack information traced from the running task. 2150d163575Sopenharmony_ci * @attention None. 2160d163575Sopenharmony_ci * 2170d163575Sopenharmony_ci * @param None. 2180d163575Sopenharmony_ci * 2190d163575Sopenharmony_ci * @retval #None. 2200d163575Sopenharmony_ci * 2210d163575Sopenharmony_ci * @par Dependency: 2220d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 2230d163575Sopenharmony_ci * @see None. 2240d163575Sopenharmony_ci */ 2250d163575Sopenharmony_ciextern VOID OsBackTrace(VOID); 2260d163575Sopenharmony_ci 2270d163575Sopenharmony_ci/** 2280d163575Sopenharmony_ci * @ingroup los_exc 2290d163575Sopenharmony_ci * @brief Kernel task backtrace function. 2300d163575Sopenharmony_ci * 2310d163575Sopenharmony_ci * @par Description: 2320d163575Sopenharmony_ci * Backtrace function that prints task call stack information traced from the input task. 2330d163575Sopenharmony_ci * @attention 2340d163575Sopenharmony_ci * <ul> 2350d163575Sopenharmony_ci * <li>The input taskID should be valid.</li> 2360d163575Sopenharmony_ci * </ul> 2370d163575Sopenharmony_ci * 2380d163575Sopenharmony_ci * @param taskID [IN] Type #UINT32 Task ID. 2390d163575Sopenharmony_ci * 2400d163575Sopenharmony_ci * @retval #None. 2410d163575Sopenharmony_ci * 2420d163575Sopenharmony_ci * @par Dependency: 2430d163575Sopenharmony_ci * los_exc.h: the header file that contains the API declaration. 2440d163575Sopenharmony_ci * @see None. 2450d163575Sopenharmony_ci */ 2460d163575Sopenharmony_ciextern VOID OsTaskBackTrace(UINT32 taskID); 2470d163575Sopenharmony_ci 2480d163575Sopenharmony_ci#ifdef __cplusplus 2490d163575Sopenharmony_ci#if __cplusplus 2500d163575Sopenharmony_ci} 2510d163575Sopenharmony_ci#endif /* __cplusplus */ 2520d163575Sopenharmony_ci#endif /* __cplusplus */ 2530d163575Sopenharmony_ci 2540d163575Sopenharmony_ci#endif /* _LOS_EXC_H */ 255