更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_exc.h
浏览该文件的文档.
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
44extern "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 */ //在LPC2458平台上发生异常时存储的寄存器信息 以下不带uw的寄存器名是芯片手册中使用的寄存器名
56#ifdef LOSCFG_ARCH_ARM_AARCH64
57#define EXC_GEN_REGS_NUM 30
58
59typedef struct {
60 UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */
61 UINT64 LR; /**< Program returning address. X30 */
66#else
67typedef struct { //异常上下文,任务被中断需切换上下文,就是一种异常
68 UINT32 R4; /**< Register R4 */
69 UINT32 R5; /**< Register R5 */
70 UINT32 R6; /**< Register R6 */
71 UINT32 R7; /**< Register R7 */
72 UINT32 R8; /**< Register R8 */
73 UINT32 R9; /**< Register R9 */
74 UINT32 R10; /**< Register R10 */
75 UINT32 R11; /**< Register R11 */
76
77 UINT32 SP; /**< Stack pointer */ //内核态栈指针
78 UINT32 reserved; /**< Reserved, multiplexing register */
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 */ //异常函数的程序计数器PC位置
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 */
99typedef 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 */
123STATIC INLINE UINTPTR Get_Fp(VOID)//获取内核FP寄存器地址
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 */
153typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32);//定义异常处理函数钩子
154//此API用于根据异常处理函数的类型定义异常处理函数钩子并记录异常
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 */
171extern 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 */
189NORETURN 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 */
207VOID 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 */
225extern 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 */
246extern VOID OsTaskBackTrace(UINT32 taskID);
247
248#ifdef __cplusplus
249#if __cplusplus
250}
251#endif /* __cplusplus */
252#endif /* __cplusplus */
253
254#endif /* _LOS_EXC_H */
UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook)
Register an exception handling hook.
Definition: los_exc.c:498
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCount)
record LR function.
Definition: los_exc.c:1353
VOID OsTaskBackTrace(UINT32 taskID)
Kernel task backtrace function.
Definition: los_exc.c:1007
VOID(* EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32)
Define an exception handling function hook.
Definition: los_exc.h:153
STATIC INLINE UINTPTR Get_Fp(VOID)
Kernel FP Register address obtain function.
Definition: los_exc.h:123
NORETURN VOID LOS_Panic(const CHAR *fmt,...)
Kernel panic function.
VOID OsBackTrace(VOID)
Kernel backtrace function.
Definition: los_exc.c:1025
unsigned short UINT16
Definition: los_typedef.h:56
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
UINT32 LR
Definition: los_exc.h:86
UINT64 regELR
Definition: los_exc.h:63
UINT32 R1
Definition: los_exc.h:82
UINT32 ULR
Definition: los_exc.h:80
UINT32 R9
Definition: los_exc.h:73
UINT32 R3
Definition: los_exc.h:84
UINT32 R7
Definition: los_exc.h:71
UINT64 LR
Definition: los_exc.h:61
UINT32 reserved
Definition: los_exc.h:78
UINT64 SP
Definition: los_exc.h:62
UINT32 R10
Definition: los_exc.h:74
UINT32 R5
Definition: los_exc.h:69
UINT32 PC
Definition: los_exc.h:87
UINT32 regCPSR
Definition: los_exc.h:88
UINT32 R8
Definition: los_exc.h:72
UINT32 USP
Definition: los_exc.h:79
UINT32 R4
Definition: los_exc.h:68
UINT32 R11
Definition: los_exc.h:75
UINT32 R6
Definition: los_exc.h:70
UINT32 R0
Definition: los_exc.h:81
UINT64 SPSR
Definition: los_exc.h:64
UINT32 R12
Definition: los_exc.h:85
UINT32 SP
Definition: los_exc.h:77
UINT32 R2
Definition: los_exc.h:83
UINT16 reserved
Definition: los_exc.h:103
UINT16 type
Definition: los_exc.h:101
UINT16 phase
Definition: los_exc.h:100
UINT16 nestCnt
Definition: los_exc.h:102
ExcContext * context
Definition: los_exc.h:104