• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2022-11-22
13  * Description: 异常模块的对外头文件。
14  */
15 #ifndef ARMV8_EXC_H
16 #define ARMV8_EXC_H
17 
18 #include "prt_typedef.h"
19 #include "prt_sys.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif /* __cpluscplus */
25 #endif /* __cpluscplus */
26 
27 /*
28  * OS使用的EL个数,EL1~EL3
29  */
30 #define OS_ELX_NUM      3
31 
32 /*
33  * 通用寄存器个数, x0~x30
34  */
35 #define XREGS_NUM       31
36 
37 /*
38  * 异常寄存器信息结构
39  */
40 struct ExcElxRegs {
41     uintptr_t esr;
42     uintptr_t far;
43     uintptr_t spsr;
44     uintptr_t elr;
45     uintptr_t sctlr;
46     uintptr_t sp;
47     uintptr_t vbar;
48     uintptr_t ttbr0;
49     uintptr_t tcr;
50     uintptr_t mair;
51 };
52 
53 struct ExcRegInfo {
54     uintptr_t ttbr0;
55     uintptr_t ttbr1;
56     uintptr_t tcr;
57     uintptr_t mair;
58     uintptr_t sctlr;
59     uintptr_t vbar;
60     uintptr_t currentEl;
61     uintptr_t sp;
62     // 以下字段的内存布局与TskContext保持一致
63     uintptr_t elr;                  // 返回地址
64     uintptr_t spsr;
65     uintptr_t far;
66     uintptr_t esr;
67     uintptr_t xzr;
68     uintptr_t xregs[XREGS_NUM];     // 0~30 : x30~x0
69 };
70 
71 /*
72  * CpuTick结构体类型。
73  *
74  * 用于记录64位的cycle计数值。
75  */
76 struct SreCpuTick {
77     U32 cntHi; /* cycle计数高32位 */
78     U32 cntLo; /* cycle计数低32位 */
79 };
80 
81 /*
82  * 异常信息结构体
83  */
84 struct ExcInfo {
85     // OS版本号
86     char osVer[OS_SYS_OS_VER_LEN];
87     // 产品版本号
88     char appVer[OS_SYS_APP_VER_LEN];
89     // 异常原因
90     U32 excCause;
91     // 异常前的线程类型
92     U32 threadType;
93     // 异常前的线程ID, 该ID组成threadID = LTID
94     U32 threadId;
95     // 字节序
96     U16 byteOrder;
97     // CPU类型
98     U16 cpuType;
99     // CPU ID
100     U32 coreId;
101     // CPU Tick
102     struct SreCpuTick cpuTick;
103     // 异常嵌套计数
104     U32 nestCnt;
105     // 致命错误码,发生致命错误时有效
106     U32 fatalErrNo;
107     // 异常前栈指针
108     uintptr_t sp;
109     // 异常前栈底
110     uintptr_t stackBottom;
111     // 异常发生时的核内寄存器上下文信息
112     struct ExcRegInfo regInfo;
113 };
114 
115 /*
116  * ARMV8异常具体类型:异常原因参见ESR寄存器。
117  */
118 #define OS_EXCEPT_ESR           0
119 
120 /*
121  * ARMV8异常具体类型:其他核异常。
122  */
123 #define OS_EXCEPT_OTHER_CORE    1
124 
125 /*
126  * ARMV8异常具体类型:致命错误异常。
127  */
128 #define OS_EXCEPT_FATALERROR    2
129 
130 /*
131  * ARMV8异常具体类型:栈越界异常。
132  */
133 #define OS_EXCEPT_STACKOVERFLOW 3
134 
135 /*
136  * ARMV8异常具体类型:非法指令异常。
137  */
138 #define OS_EXCEPT_UNDEF_INSTR   4
139 
140 /*
141  * ARMV8异常具体类型:数据中止异常。
142  */
143 #define OS_EXCEPT_DATA_ABORT    5
144 
145 /*
146  * ARMV8异常具体类型:快速中断异常。
147  */
148 #define OS_EXCEPT_FIQ           6
149 
150 /*
151  * ARMV8异常具体类型:pc非对齐异常。
152  */
153 #define OS_EXCEPT_PC_NOT_ALIGN  7
154 
155 /*
156  * ARMV8异常具体类型:sp非对齐异常。
157  */
158 #define OS_EXCEPT_SP_NOT_ALIGN  8
159 
160 #ifdef __cplusplus
161 #if __cplusplus
162 }
163 #endif /* __cpluscplus */
164 #endif /* __cpluscplus */
165 
166 #endif /* ARMV8_EXC_H */
167