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
|
la t0,handler
csrw mtvec,t0 # Set trap handler address and mode (0/direct)
li t0,0x400
csrc mstatush,t0 # Enable trap handler
li t0,0x80
csrw mie,t0 # Enable machine timer interrupt and disable others
la t0,mmio
csrw 0x801,t0 # Set up MMIO base address
lw t1,2(t0) # Read current time
addi t1,t1,5
sw t1,10(t0) # Set mtimecmp to 5 seconds in the future
csrsi mstatus,8 # Enable interrupts globally
wfi # Wait for the interrupt to trigger
li a7,10 # Exit program
ecall
.balign 4
handler:
li t1,-1
sw t1,10(t0) # Set mtimecmp to the distant future
csrr a0,mcause
li a7,1 # Print integer
ecall
li a0,'\n'
li a7,11 # Print character
ecall
mret
mmio:
|