diff options
| author | cheapie <cheapiephp@gmail.com> | 2026-06-19 22:38:28 -0500 |
|---|---|---|
| committer | cheapie <cheapiephp@gmail.com> | 2026-06-19 22:38:28 -0500 |
| commit | 33e4744d1c73c9f5512abb4010e4cc81763ab3a2 (patch) | |
| tree | f690b968f5feeb6e905aa1265c9b4b3584e6a668 /assembly/timer-test/timer-test.S | |
| parent | 569bc33a90282d039a9d1701bee7d9cd5919a24e (diff) | |
| download | rvcontroller-33e4744d1c73c9f5512abb4010e4cc81763ab3a2.tar rvcontroller-33e4744d1c73c9f5512abb4010e4cc81763ab3a2.tar.gz rvcontroller-33e4744d1c73c9f5512abb4010e4cc81763ab3a2.tar.bz2 rvcontroller-33e4744d1c73c9f5512abb4010e4cc81763ab3a2.tar.xz rvcontroller-33e4744d1c73c9f5512abb4010e4cc81763ab3a2.zip | |
Add machine timer interrupt
Diffstat (limited to 'assembly/timer-test/timer-test.S')
| -rw-r--r-- | assembly/timer-test/timer-test.S | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/assembly/timer-test/timer-test.S b/assembly/timer-test/timer-test.S new file mode 100644 index 0000000..e114f3f --- /dev/null +++ b/assembly/timer-test/timer-test.S @@ -0,0 +1,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: |
