• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @defgroup los_exc Exception handling
34  * @ingroup kernel
35  */
36 #ifndef _LOS_EXC_H
37 #define _LOS_EXC_H
38 
39 #include "los_typedef.h"
40 #include "arch_config.h"
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 #endif /* __cplusplus */
47 
48 /**
49  * @ingroup los_exc
50  * Register information structure
51  *
52  * Description: register information stored when an exception occurs on an LPC2458 platform.
53  *
54  * Note: The following register names without uw are the register names used in the chip manual.
55  */
56 #ifdef LOSCFG_ARCH_ARM_AARCH64
57 #define EXC_GEN_REGS_NUM     30
58 typedef struct {
59     UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */
60     UINT64 LR;                  /**< Program returning address. X30 */
61     UINT64 SP;
62     UINT64 regELR;
63     UINT64 SPSR;
64 } ExcContext;
65 #else
66 /* It has the same structure as TaskContext */
67 typedef struct {
68     UINT32 R4;
69     UINT32 R5;
70     UINT32 R6;
71     UINT32 R7;
72     UINT32 R8;
73     UINT32 R9;
74     UINT32 R10;
75     UINT32 R11;
76 
77     UINT32 SP;       /**< svc sp */
78     UINT32 reserved; /**< Reserved, multiplexing register */
79     UINT32 USP;
80     UINT32 ULR;
81     UINT32 R0;      /**< Register R0 */
82     UINT32 R1;      /**< Register R1 */
83     UINT32 R2;      /**< Register R2 */
84     UINT32 R3;      /**< Register R3 */
85     UINT32 R12;     /**< Register R12 */
86     UINT32 LR;      /**< Program returning address. */
87     UINT32 PC;      /**< PC pointer of the exceptional function */
88     UINT32 regCPSR;
89 } ExcContext;
90 #endif
91 
92 /**
93  * @ingroup los_exc
94  * Exception information structure
95  *
96  * Description: exception information stored when an exception occurs on an LPC2458 platform.
97  *
98  */
99 typedef struct {
100     UINT16 phase;        /**< Phase in which an exception occurs */
101     UINT16 type;         /**< Exception type */
102     UINT16 nestCnt;      /**< Count of nested exception */
103     UINT16 reserved;     /**< Reserved for alignment */
104     ExcContext *context; /**< Hardware context when an exception occurs */
105 } ExcInfo;
106 
107 /**
108  * @ingroup los_exc
109  * @brief Kernel FP Register address obtain function.
110  *
111  * @par Description:
112  * The API is used to obtain the FP Register address.
113  * @attention None.
114  *
115  * @param  None.
116  *
117  * @retval #UINTPTR The FP Register address.
118  *
119  * @par Dependency:
120  * los_exc.h: the header file that contains the API declaration.
121  * @see None.
122  */
Get_Fp(VOID)123 STATIC INLINE UINTPTR Get_Fp(VOID)
124 {
125     UINTPTR regFp;
126 
127 #ifdef LOSCFG_ARCH_ARM_AARCH64
128     __asm__ __volatile__("mov %0, X29" : "=r"(regFp));
129 #else
130     __asm__ __volatile__("mov %0, fp" : "=r"(regFp));
131 #endif
132 
133     return regFp;
134 }
135 
136 /**
137  * @ingroup los_exc
138  * @brief Define an exception handling function hook.
139  *
140  * @par Description:
141  * This API is used to define the exception handling function hook based on the type of
142  * the exception handling function and record exceptions.
143  * @attention None.
144  *
145  * @param None.
146  *
147  * @retval None.
148  *
149  * @par Dependency:
150  * los_exc.h: the header file that contains the API declaration.
151  * @see None.
152  */
153 typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32);
154 
155 /**
156  * @ingroup los_exc
157  * @brief Register an exception handling hook.
158  *
159  * @par Description:
160  * This API is used to register an exception handling hook.
161  * @attention If the hook is registered for multiple times, the hook registered at the last time is effective.
162  * @attention The hook can be registered as NULL, indicating that the hook registration is canceled.
163  * @param excHook [IN] Type #EXC_PROC_FUNC: hook function.
164  *
165  * @retval #LOS_OK                      The exception handling hook is successfully registered.
166  *
167  * @par Dependency:
168  * los_exc.h: the header file that contains the API declaration.
169  * @see None.
170  */
171 extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook);
172 
173 /**
174  * @ingroup los_exc
175  * @brief Kernel panic function.
176  *
177  * @par Description:
178  * Stack function that prints kernel panics.
179  * @attention After this function is called and stack information is printed, the system will fail to respond.
180  * @attention The input parameter can be NULL.
181  * @param fmt [IN] Type #CHAR* : variadic argument.
182  *
183  * @retval #None.
184  *
185  * @par Dependency:
186  * los_exc.h: the header file that contains the API declaration.
187  * @see None.
188  */
189 NORETURN VOID LOS_Panic(const CHAR *fmt, ...);
190 
191 /**
192  * @ingroup los_exc
193  * @brief record LR function.
194  *
195  * @par Description:
196  * @attention
197  * @param LR            [IN] Type #UINTPTR * LR buffer.
198  * @param recordCount   [IN] Type UINT32 record LR lay number.
199  * @param jumpCount     [IN] Type UINT32 ignore LR lay number.
200  *
201  * @retval #None.
202  *
203  * @par Dependency:
204  * los_exc.h: the header file that contains the API declaration.
205  * @see None.
206  */
207 VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount);
208 
209 /**
210  * @ingroup los_exc
211  * @brief Kernel backtrace function.
212  *
213  * @par Description:
214  * Backtrace function that prints task call stack information traced from the running task.
215  * @attention None.
216  *
217  * @param None.
218  *
219  * @retval #None.
220  *
221  * @par Dependency:
222  * los_exc.h: the header file that contains the API declaration.
223  * @see None.
224  */
225 extern VOID OsBackTrace(VOID);
226 
227 /**
228  * @ingroup los_exc
229  * @brief Kernel task backtrace function.
230  *
231  * @par Description:
232  * Backtrace function that prints task call stack information traced from the input task.
233  * @attention
234  * <ul>
235  * <li>The input taskID should be valid.</li>
236  * </ul>
237  *
238  * @param  taskID [IN] Type #UINT32 Task ID.
239  *
240  * @retval #None.
241  *
242  * @par Dependency:
243  * los_exc.h: the header file that contains the API declaration.
244  * @see None.
245  */
246 extern VOID OsTaskBackTrace(UINT32 taskID);
247 
248 #ifdef __cplusplus
249 #if __cplusplus
250 }
251 #endif /* __cplusplus */
252 #endif /* __cplusplus */
253 
254 #endif /* _LOS_EXC_H */
255