blob: 64e4bfcc68d5f1917f9bf7de0ebb905c4522ac6b (
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
|
#include "interrupt.h"
extern interrupt::vector_t vectors_exception[];
extern interrupt::vector_t vectors_clic[];
[[gnu::interrupt, gnu::aligned(64)]]
void riscv_interrupt_handler() {
uint32_t cause;
asm("csrr %0, mcause" : "=r"(cause));
uint32_t type = cause & 0x80000000;
uint32_t code = cause & 0x00000fff;
if(type) {
vectors_clic[code]();
} else {
vectors_exception[code]();
}
}
[[gnu::constructor(200)]]
void riscv_interrupt_init() {
asm volatile("csrw mtvec, %0" :: "r"(intptr_t(riscv_interrupt_handler) | 3));
asm volatile("csrrsi x0, mstatus, (1 << 3)");
}
|