summaryrefslogtreecommitdiff
path: root/software/shared/init.c
blob: ab790b2e0b86d6a57d25c9fcea58109d01381dd3 (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
// See LICENSE for license details.

#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>

#include "encoding.h"
#include "shared.h"

int main(void);

#ifdef USE_PLIC
extern void handle_m_ext_interrupt();
#endif


#ifdef USE_M_TIME
extern void handle_m_time_interrupt();
#endif


void _init(void)
{
  
  exit(main());
}

uintptr_t handle_trap(uintptr_t mcause, uintptr_t epc)
{
  if (0){
#ifdef USE_PLIC
  // External Machine-Level Interrupt from PLIC
 }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE)  == IRQ_M_EXT)) {
    handle_m_ext_interrupt();
#endif
#ifdef USE_M_TIME
  // External Machine-Level Interrupt from PLIC
 }else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE)  == IRQ_M_TIMER)) {
    handle_m_time_interrupt();
#endif
  }    
  else{
    write(1, "trap\n", 5);
    _exit(1 + mcause);
  }
  return epc;
}