Skip to content

Commit dc213e8

Browse files
committed
arc: add readable exception handlers
Signed-off-by: Yuguo Zou <[email protected]>
1 parent fb5c7e6 commit dc213e8

File tree

3 files changed

+260
-4
lines changed

3 files changed

+260
-4
lines changed

arc/arc_exception.c

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,250 @@
5757
*
5858
*/
5959

60+
#ifdef CONFIG_ARC_EXCEPTION_DEBUG
61+
/* For EV_ProtV, the numbering/semantics of the parameter are consistent across
62+
* several codes, although not all combination will be reported.
63+
*
64+
* These codes and parameters do not have associated* names in
65+
* the technical manual, just switch on the values in Table 6-5
66+
*/
67+
static void dump_protv_access_err(uint32_t parameter)
68+
{
69+
switch (parameter) {
70+
case 0x1:
71+
EMBARC_PRINTF("code protection scheme");
72+
break;
73+
case 0x2:
74+
EMBARC_PRINTF("stack checking scheme");
75+
break;
76+
case 0x4:
77+
EMBARC_PRINTF("MPU");
78+
break;
79+
case 0x8:
80+
EMBARC_PRINTF("MMU");
81+
break;
82+
case 0x10:
83+
EMBARC_PRINTF("NVM");
84+
break;
85+
case 0x24:
86+
EMBARC_PRINTF("Secure MPU");
87+
break;
88+
case 0x44:
89+
EMBARC_PRINTF("Secure MPU with SID mismatch");
90+
break;
91+
default:
92+
EMBARC_PRINTF("unknown parameter");
93+
break;
94+
}
95+
}
96+
97+
static void dump_protv_exception(uint32_t cause, uint32_t parameter)
98+
{
99+
switch (cause) {
100+
case 0x0:
101+
EMBARC_PRINTF("Instruction fetch violation: ");
102+
dump_protv_access_err(parameter);
103+
break;
104+
case 0x1:
105+
EMBARC_PRINTF("Memory read protection violation: ");
106+
dump_protv_access_err(parameter);
107+
break;
108+
case 0x2:
109+
EMBARC_PRINTF("Memory write protection violation: ");
110+
dump_protv_access_err(parameter);
111+
break;
112+
case 0x3:
113+
EMBARC_PRINTF("Memory read-modify-write violation: ");
114+
dump_protv_access_err(parameter);
115+
break;
116+
case 0x10:
117+
EMBARC_PRINTF("Normal vector table in secure memory");
118+
break;
119+
case 0x11:
120+
EMBARC_PRINTF("NS handler code located in S memory");
121+
break;
122+
case 0x12:
123+
EMBARC_PRINTF("NSC Table Range Violation");
124+
break;
125+
default:
126+
EMBARC_PRINTF("unknown cause");
127+
break;
128+
}
129+
}
130+
131+
static void dump_machine_check_exception(uint32_t cause, uint32_t parameter)
132+
{
133+
switch (cause) {
134+
case 0x0:
135+
EMBARC_PRINTF("double fault");
136+
break;
137+
case 0x1:
138+
EMBARC_PRINTF("overlapping TLB entries");
139+
break;
140+
case 0x2:
141+
EMBARC_PRINTF("fatal TLB error");
142+
break;
143+
case 0x3:
144+
EMBARC_PRINTF("fatal cache error");
145+
break;
146+
case 0x4:
147+
EMBARC_PRINTF("internal memory error on instruction fetch");
148+
break;
149+
case 0x5:
150+
EMBARC_PRINTF("internal memory error on data fetch");
151+
break;
152+
case 0x6:
153+
EMBARC_PRINTF("illegal overlapping MPU entries");
154+
if (parameter == 0x1) {
155+
EMBARC_PRINTF(" (jump and branch target)");
156+
}
157+
break;
158+
case 0x10:
159+
EMBARC_PRINTF("secure vector table not located in secure memory");
160+
break;
161+
case 0x11:
162+
EMBARC_PRINTF("NSC jump table not located in secure memory");
163+
break;
164+
case 0x12:
165+
EMBARC_PRINTF("secure handler code not located in secure memory");
166+
break;
167+
case 0x13:
168+
EMBARC_PRINTF("NSC target address not located in secure memory");
169+
break;
170+
case 0x80:
171+
EMBARC_PRINTF("uncorrectable ECC or parity error in vector memory");
172+
break;
173+
default:
174+
EMBARC_PRINTF("unknown cause");
175+
break;
176+
}
177+
}
178+
179+
static void dump_privilege_exception(uint32_t cause, uint32_t parameter)
180+
{
181+
switch (cause) {
182+
case 0x0:
183+
EMBARC_PRINTF("Privilege violation");
184+
break;
185+
case 0x1:
186+
EMBARC_PRINTF("disabled extension");
187+
break;
188+
case 0x2:
189+
EMBARC_PRINTF("action point hit");
190+
break;
191+
case 0x10:
192+
switch (parameter) {
193+
case 0x1:
194+
EMBARC_PRINTF("N to S return using incorrect return mechanism");
195+
break;
196+
case 0x2:
197+
EMBARC_PRINTF("N to S return with incorrect operating mode");
198+
break;
199+
case 0x3:
200+
EMBARC_PRINTF("IRQ/exception return fetch from wrong mode");
201+
break;
202+
case 0x4:
203+
EMBARC_PRINTF("attempt to halt secure processor in NS mode");
204+
break;
205+
case 0x20:
206+
EMBARC_PRINTF("attempt to access secure resource from normal mode");
207+
break;
208+
case 0x40:
209+
EMBARC_PRINTF("SID violation on resource access (APEX/UAUX/key NVM)");
210+
break;
211+
default:
212+
EMBARC_PRINTF("unknown parameter");
213+
break;
214+
}
215+
break;
216+
case 0x13:
217+
switch (parameter) {
218+
case 0x20:
219+
EMBARC_PRINTF("attempt to access secure APEX feature from NS mode");
220+
break;
221+
case 0x40:
222+
EMBARC_PRINTF("SID violation on access to APEX feature");
223+
break;
224+
default:
225+
EMBARC_PRINTF("unknown parameter");
226+
break;
227+
}
228+
break;
229+
default:
230+
EMBARC_PRINTF("unknown cause");
231+
break;
232+
}
233+
}
234+
235+
static void dump_exception_info(uint32_t vector, uint32_t cause, uint32_t param)
236+
{
237+
if (vector >= 0x10 && vector <= 0xFF) {
238+
EMBARC_PRINTF("interrupt %d\n", vector);
239+
return;
240+
}
241+
242+
/* Names are exactly as they appear in Designware ARCv2 ISA
243+
* Programmer's reference manual for easy searching
244+
*/
245+
switch (vector) {
246+
case EXC_NO_RESET:
247+
EMBARC_PRINTF("Reset");
248+
break;
249+
case EXC_NO_MEM_ERR:
250+
EMBARC_PRINTF("Memory Error");
251+
break;
252+
case EXC_NO_INS_ERR:
253+
EMBARC_PRINTF("Instruction Error");
254+
break;
255+
case EXC_NO_MAC_CHK:
256+
EMBARC_PRINTF("EV_MachineCheck: ");
257+
dump_machine_check_exception(cause, param);
258+
break;
259+
case EXC_NO_TLB_MISS_I:
260+
EMBARC_PRINTF("EV_TLBMissI");
261+
break;
262+
case EXC_NO_TLB_MISS_D:
263+
EMBARC_PRINTF("EV_TLBMissD");
264+
break;
265+
case EXC_NO_PRO_VIO:
266+
EMBARC_PRINTF("EV_ProtV: ");
267+
dump_protv_exception(cause, param);
268+
break;
269+
case EXC_NO_PRI_VIO:
270+
EMBARC_PRINTF("EV_PrivilegeV: ");
271+
dump_privilege_exception(cause, param);
272+
break;
273+
case EXC_NO_SWI:
274+
EMBARC_PRINTF("EV_SWI");
275+
break;
276+
case EXC_NO_TRAP:
277+
EMBARC_PRINTF("EV_Trap");
278+
break;
279+
case EXC_NO_EXT:
280+
EMBARC_PRINTF("EV_Extension");
281+
break;
282+
case EXC_NO_DIV_ZER0:
283+
EMBARC_PRINTF("EV_DivZero");
284+
break;
285+
case EXC_NO_DC_ERR:
286+
EMBARC_PRINTF("EV_DCError");
287+
break;
288+
case EXC_NO_MAL_ALIGN:
289+
EMBARC_PRINTF("EV_Misaligned");
290+
break;
291+
case EXC_NO_VEC_UNIT:
292+
EMBARC_PRINTF("EV_VecUnit");
293+
break;
294+
default:
295+
EMBARC_PRINTF("unknown exception vector");
296+
break;
297+
}
298+
299+
EMBARC_PRINTF("\n");
300+
}
301+
302+
#endif /* CONFIG_ARC_EXCEPTION_DEBUG */
303+
60304
/**
61305
* \ingroup ARC_HAL_EXCEPTION_CPU
62306
* \brief default cpu exception handler
@@ -67,14 +311,21 @@ static void exc_handler_default(void *p_excinf)
67311
uint32_t excpt_cause_reg = 0;
68312
uint32_t excpt_ret_reg = 0;
69313
uint32_t exc_no = 0;
314+
uint32_t exc_cause = 0;
315+
uint32_t exc_param = 0;
70316

71317
excpt_cause_reg = _arc_aux_read(AUX_ECR);
72318
excpt_ret_reg = _arc_aux_read(AUX_ERRET);
73319
exc_no = (excpt_cause_reg >> 16) & 0xff;
320+
exc_cause = (excpt_cause_reg >> 8) & 0xff;
321+
exc_param = (excpt_cause_reg >> 0) & 0xff;
74322

75323
dbg_printf(DBG_LESS_INFO, "default cpu exception handler\r\n");
76324
dbg_printf(DBG_LESS_INFO, "exc_no:%d, last sp:0x%08x, ecr:0x%08x, eret:0x%08x\r\n",
77325
exc_no, (uint32_t)p_excinf, excpt_cause_reg, excpt_ret_reg);
326+
#ifdef CONFIG_ARC_EXCEPTION_DEBUG
327+
dump_exception_info(exc_no, exc_cause, exc_param);
328+
#endif
78329
#if SECURESHIELD_VERSION == 2
79330
while (1);
80331
#else

inc/arc/arc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
#define EXC_NO_DIV_ZER0 (11) /*!< divide by zero */
6666
#define EXC_NO_DC_ERR (12) /*!< data cache consistency error */
6767
#define EXC_NO_MAL_ALIGN (13) /*!< misaligned data access */
68-
#define EXC_NO_RESERVE0 (14) /*!< reserved */
69-
#define EXC_NO_RESERVE1 (15) /*!< reserved */
68+
#define EXC_NO_VEC_UNIT (14) /*!< vector unit exception (Vector stack pointer check violation is detected in the vector unit.) */
69+
#define EXC_NO_RESERVE0 (15) /*!< reserved */
7070

7171
/* extension interrupts */
7272
#define EXC_NO_16 (16) /*!< interrupt vector 16 */
@@ -111,8 +111,8 @@
111111
#define EXC_VECTOR_DIV_ZER0 (0x2c) /*!< EXC_NO_DIV_ZER0 offset */
112112
#define EXC_VECTOR_DC_ERR (0x30) /*!< EXC_NO_DC_ERR offset */
113113
#define EXC_VECTOR_MAL_ALIGN (0x34) /*!< EXC_NO_MAL_ALIGN offset */
114-
#define EXC_VECTOR_RESERVE0 (0x38) /*!< EXC_NO_RESERVE0 offset */
115-
#define EXC_VECTOR_RESERVE1 (0x3c) /*!< EXC_NO_RESERVE1 offset */
114+
#define EXC_VECTOR_VEC_UNIT (0x38) /*!< EXC_NO_VEC_UNIT offset */
115+
#define EXC_VECTOR_RESERVE0 (0x3c) /*!< EXC_NO_RESERVE0 offset */
116116
/** @} */
117117

118118
/**

inc/embARC_debug.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
extern "C" {
4242
#endif
4343

44+
//comment this to disable exception readable dumping. By doing so could save some code space
45+
#ifndef CONFIG_ARC_EXCEPTION_DEBUG
46+
#define CONFIG_ARC_EXCEPTION_DEBUG
47+
#endif
48+
4449
#ifndef EMBARC_PRINTF
4550
#ifdef MID_COMMON
4651
#include "xprintf.h"

0 commit comments

Comments
 (0)