forth-riscv

My forth
git clone git://git.electrosoup.com/forth-riscv
Log | Files | Refs

trap.s (4034B)


      1 .altmacro
      2 
      3 .global trap_table
      4 .weak trap_s_software_interrupt
      5 .weak trap_m_software_interrupt
      6 .weak trap_s_timer_interrupt
      7 .weak trap_m_timer_interrupt
      8 .weak trap_s_external_interrupt
      9 .weak trap_m_external_interrupt
     10 
     11 #define w a0
     12 #define x a1
     13 #define y a2
     14 #define psp sp
     15 #define rsp s2
     16 
     17 trap_exception:
     18     csrr t0, mscratch
     19     sw w, 0*4(t0)
     20     sw x, 1*4(t0)
     21     sw y, 2*4(t0)
     22     sw psp, 3*4(t0)
     23     sw rsp, 4*4(t0)
     24     csrw mscratch, t0
     25 
     26     mv psp, t0
     27     addi rsp, psp, -256
     28 
     29     la w, _exception_str_table
     30     csrr x, mcause
     31     slli x, x, 3
     32     add w, w, x
     33     lw x, 0(w)
     34     lw w, 4(w)
     35     jal uart_put_string
     36 
     37     la w, abort
     38     csrw mepc, w
     39 
     40     csrr t0, mscratch
     41     lw w, 0*4(t0)
     42     lw x, 1*4(t0)
     43     lw y, 2*4(t0)
     44     lw psp, 3*4(t0)
     45     lw rsp, 4*4(t0)
     46     csrw mscratch, t0
     47 
     48     mret
     49 
     50 .balign 4
     51 trap_table:
     52     jal trap_exception
     53     jal trap_s_software_interrupt
     54     .int 0
     55     jal trap_m_software_interrupt
     56     .int 0
     57     jal trap_s_timer_interrupt
     58     .int 0
     59     jal trap_m_timer_interrupt
     60     .int 0
     61     jal trap_s_external_interrupt
     62     .int 0
     63     jal trap_m_external_interrupt
     64 
     65 trap_s_software_interrupt:
     66 trap_m_software_interrupt:
     67 trap_s_timer_interrupt:
     68 trap_m_timer_interrupt:
     69 trap_s_external_interrupt:
     70 trap_m_external_interrupt:
     71 trap_interrupt:
     72     mret
     73 
     74 .section ".rodata"
     75 _exception_0_str:
     76     .ascii "instruction address misaligned\n"
     77 _exception_0_len = (. - _exception_0_str)
     78 _exception_1_str:
     79     .ascii "instruction access fault\n"
     80 _exception_1_len = (. - _exception_1_str)
     81 _exception_2_str:
     82     .ascii "illegal instruction\n"
     83 _exception_2_len = (. - _exception_2_str)
     84 _exception_3_str:
     85     .ascii "breakpoint\n"
     86 _exception_3_len = (. - _exception_3_str)
     87 _exception_4_str:
     88     .ascii "load address misaligned\n"
     89 _exception_4_len = (. - _exception_4_str)
     90 _exception_5_str:
     91     .ascii "load access fault\n"
     92 _exception_5_len = (. - _exception_5_str)
     93 _exception_6_str:
     94     .ascii "store/amo address misaligned\n"
     95 _exception_6_len = (. - _exception_6_str)
     96 _exception_7_str:
     97     .ascii "store/amo access fault\n"
     98 _exception_7_len = (. - _exception_7_str)
     99 _exception_8_str:
    100     .ascii "environment call from u-mode\n"
    101 _exception_8_len = (. - _exception_8_str)
    102 _exception_9_str:
    103     .ascii "environment call from s-mode\n"
    104 _exception_9_len = (. - _exception_9_str)
    105 _exception_11_str:
    106     .ascii "environment call from m-mode\n"
    107 _exception_11_len = (. - _exception_11_str)
    108 _exception_12_str:
    109     .ascii "instruction page fault\n"
    110 _exception_12_len = (. - _exception_12_str)
    111 _exception_13_str:
    112     .ascii "load page fault\n"
    113 _exception_13_len = (. - _exception_13_str)
    114 _exception_15_str:
    115     .ascii "store/amo page fault\n"
    116 _exception_15_len = (. - _exception_15_str)
    117 _exception_16_str:
    118     .ascii "double trap\n"
    119 _exception_16_len = (. - _exception_16_str)
    120 _exception_18_str:
    121     .ascii "software check\n"
    122 _exception_18_len = (. - _exception_18_str)
    123 _exception_19_str:
    124     .ascii "hardware error\n"
    125 _exception_19_len = (. - _exception_19_str)
    126 _exception_reserved_str:
    127     .ascii "reserved\n"
    128 _exception_reserved_len = (. - _exception_reserved_str)
    129 
    130 _exception_str_table:
    131     .int _exception_0_len, _exception_0_str
    132     .int _exception_1_len, _exception_1_str
    133     .int _exception_2_len, _exception_2_str
    134     .int _exception_3_len, _exception_3_str
    135     .int _exception_4_len, _exception_4_str
    136     .int _exception_5_len, _exception_5_str
    137     .int _exception_6_len, _exception_6_str
    138     .int _exception_7_len, _exception_7_str
    139     .int _exception_8_len, _exception_8_str
    140     .int _exception_9_len, _exception_9_str
    141     .int _exception_reserved_len, _exception_reserved_str
    142     .int _exception_11_len, _exception_11_str
    143     .int _exception_12_len, _exception_12_str
    144     .int _exception_13_len, _exception_13_str
    145     .int _exception_reserved_len, _exception_reserved_str
    146     .int _exception_15_len, _exception_15_str
    147     .int _exception_16_len, _exception_16_str
    148     .int _exception_reserved_len, _exception_reserved_str
    149     .int _exception_18_len, _exception_18_str
    150     .int _exception_19_len, _exception_19_str
    151