aboutsummaryrefslogtreecommitdiff
path: root/src/exc.c
blob: 9b7242b672beaa4a423a4eec2a035aa891afbec6 (plain) (blame)
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
#include <stdio.h>

#include "ch573/gpio.h"
#include "isr_vector.h"
#include "panic.h"
#include "risc-v.h"

#define GPIO_PORT_A ch573_gpio__gpio_port_a
#define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF

void delay();

struct exc_info {
  uint32_t mtval;
  uint32_t mepc;
  uint32_t mcause;
};

static inline void get_exc_info(struct exc_info* out)
{
  out->mtval = MTVAL;
  out->mepc = MEPC;
  out->mcause = MCAUSE;
}

IRQ(exc)
{
  struct exc_info ei;
  get_exc_info(&ei);

  printf("Hardware Exception Caught:\n");
  printf("  mcause: 0x%08x\n", ei.mcause);
  printf("    mepc: 0x%08x\n", ei.mepc);
  printf("   mtval: 0x%08x\n", ei.mtval);

  panic(ei.mcause);
}

IRQ(nmi)
{
  struct exc_info ei;
  get_exc_info(&ei);

  printf("Unhandled NMI Caught:\n");
  printf("  mcause: 0x%08x\n", ei.mcause);
  printf("    mepc: 0x%08x\n", ei.mepc);
  printf("   mtval: 0x%08x\n", ei.mtval);

  panic(ei.mcause);
}