csr_mmode.asm
1 li x15, 5 # this many instructions will raise an exception 2 la x6, exception_handler 3 csrw mtvec, x6 # set-up handler 4 # test read-only CSRs 5 csrw mvendorid, 1 6 csrw marchid, 1 7 csrw mimpid, 1 8 csrw mhartid, 1 9 csrw 0xf15, 1 # csrw mconfigptr, 1 10 csrr x1, mvendorid 11 csrr x2, marchid 12 csrr x3, mimpid 13 csrr x4, mhartid 14 csrr x5, 0xf15 # csrr x5, mconfigptr 15 # test writable CSRs 16 csrw mscratch, 4 17 csrr x6, mscratch 18 infloop: 19 j infloop 20 21 exception_handler: 22 addi x15, x15, -1 # count exceptions 23 24 csrr x31, mepc # resume program execution, 25 addi x31, x31, 4 # but skip unimplemented instruction 26 csrw mepc, x31 27 mret