summaryrefslogtreecommitdiff
path: root/bsp/thead-smart/drivers/trap_c.c
blob: 7df7cd1f9b24e575640a17bc2ece98329576adb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (C) 2017-2019 Alibaba Group Holding Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-20     zx.chen      source file for the trap process
 */

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <csi_config.h>
#include <csi_core.h>

void (*trap_c_callback)(void);

void trap_c(uint32_t *regs)
{
    int i;
    uint32_t vec = 0;

    vec = __get_MCAUSE() & 0x3FF;

    printf("CPU Exception: NO.%ld", vec);
    printf("\n");

    for (i = 0; i < 31; i++)
    {
        printf("x%d: %08lx\t", i + 1, regs[i]);

        if ((i % 4) == 3)
        {
            printf("\n");
        }
    }

    printf("\n");
    printf("mepc   : %08lx\n", regs[31]);
    printf("mstatus: %08lx\n", regs[32]);

    if (trap_c_callback)
    {
        trap_c_callback();
    }

    while (1);
}