aboutsummaryrefslogtreecommitdiff
path: root/src/exc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exc.c')
-rw-r--r--src/exc.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/exc.c b/src/exc.c
index 657ddb8..9b7242b 100644
--- a/src/exc.c
+++ b/src/exc.c
@@ -1,43 +1,50 @@
#include <stdio.h>
+#include "ch573/gpio.h"
#include "isr_vector.h"
#include "panic.h"
-
-#include "ch573/gpio.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();
-IRQ(exc)
+struct exc_info {
+ uint32_t mtval;
+ uint32_t mepc;
+ uint32_t mcause;
+};
+
+static inline void get_exc_info(struct exc_info* out)
{
- uint32_t mcause, mepc, mtval, *sp;
+ out->mtval = MTVAL;
+ out->mepc = MEPC;
+ out->mcause = MCAUSE;
+}
- asm volatile("csrr %0, mcause" : "=r"(mcause));
- asm volatile("csrr %0, mepc" : "=r"(mepc));
- asm volatile("csrr %0, mtval" : "=r"(mtval));
+IRQ(exc)
+{
+ struct exc_info ei;
+ get_exc_info(&ei);
printf("Hardware Exception Caught:\n");
- printf(" mcause: 0x%08x\n", mcause);
- printf(" mepc: 0x%08x\n", mepc);
- printf(" mtval: 0x%08x\n", mtval);
+ printf(" mcause: 0x%08x\n", ei.mcause);
+ printf(" mepc: 0x%08x\n", ei.mepc);
+ printf(" mtval: 0x%08x\n", ei.mtval);
- panic(mcause);
+ panic(ei.mcause);
}
IRQ(nmi)
{
- uint32_t mcause, mepc, mtval, *sp;
-
- asm volatile("csrr %0, mcause" : "=r"(mcause));
- asm volatile("csrr %0, mepc" : "=r"(mepc));
- asm volatile("csrr %0, mtval" : "=r"(mtval));
+ struct exc_info ei;
+ get_exc_info(&ei);
printf("Unhandled NMI Caught:\n");
- printf(" mcause: 0x%08x\n", mcause);
- printf(" mepc: 0x%08x\n", mepc);
- printf(" mtval: 0x%08x\n", mtval);
+ printf(" mcause: 0x%08x\n", ei.mcause);
+ printf(" mepc: 0x%08x\n", ei.mepc);
+ printf(" mtval: 0x%08x\n", ei.mtval);
- panic(mcause);
+ panic(ei.mcause);
}