bump env
[riscv-tests.git] / debug / programs / init.c
1 #include "init.h"
2 #include "encoding.h"
3
4 int main(void);
5
6 trap_handler_t trap_handler[NHARTS] = {0};
7
8 void set_trap_handler(trap_handler_t handler)
9 {
10 unsigned hartid = csr_read(mhartid);
11 trap_handler[hartid] = handler;
12 }
13
14 void enable_timer_interrupts()
15 {
16 set_csr(mie, MIP_MTIP);
17 set_csr(mstatus, MSTATUS_MIE);
18 }
19
20 void handle_trap(unsigned int mcause, void *mepc, void *sp)
21 {
22 unsigned hartid = csr_read(mhartid);
23 if (trap_handler[hartid]) {
24 trap_handler[hartid](hartid, mcause, mepc, sp);
25 return;
26 }
27
28 while (1)
29 ;
30 }
31
32 void _exit(int status)
33 {
34 // Make sure gcc doesn't inline _exit, so we can actually set a breakpoint
35 // on it.
36 volatile int i = 42;
37 while (i)
38 ;
39 // _exit isn't supposed to return.
40 while (1)
41 ;
42 }
43
44 void _init()
45 {
46 _exit(main());
47 }