1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2020-08-20     zx.chen      source file for the trap process
9  */
10 
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <csi_config.h>
15 #include <csi_core.h>
16 
17 void (*trap_c_callback)(void);
18 
trap_c(uint32_t * regs)19 void trap_c(uint32_t *regs)
20 {
21     int i;
22     uint32_t vec = 0;
23 
24     vec = __get_MCAUSE() & 0x3FF;
25 
26     printf("CPU Exception: NO.%ld", vec);
27     printf("\n");
28 
29     for (i = 0; i < 31; i++)
30     {
31         printf("x%d: %08lx\t", i + 1, regs[i]);
32 
33         if ((i % 4) == 3)
34         {
35             printf("\n");
36         }
37     }
38 
39     printf("\n");
40     printf("mepc   : %08lx\n", regs[31]);
41     printf("mstatus: %08lx\n", regs[32]);
42 
43     if (trap_c_callback)
44     {
45         trap_c_callback();
46     }
47 
48     while (1);
49 }
50 
51