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 | |
| 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')
| -rw-r--r-- | assembly/timer-test/Makefile | 24 | ||||
| l--------- | assembly/timer-test/rvcontroller.ld | 1 | ||||
| -rw-r--r-- | assembly/timer-test/timer-test.S | 36 | ||||
| -rwxr-xr-x | assembly/timer-test/timer-test.elf | bin | 0 -> 5352 bytes | |||
| -rw-r--r-- | assembly/timer-test/timer-test.hex | 7 | ||||
| -rw-r--r-- | assembly/timer-test/timer-test.o | bin | 0 -> 1324 bytes |
6 files changed, 68 insertions, 0 deletions
diff --git a/assembly/timer-test/Makefile b/assembly/timer-test/Makefile new file mode 100644 index 0000000..7989624 --- /dev/null +++ b/assembly/timer-test/Makefile @@ -0,0 +1,24 @@ +MARCH ?= rv32imacbzicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt + +.PHONY: all dump load clean + +all: timer-test.hex + +timer-test.o: timer-test.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o timer-test.o timer-test.S + +timer-test.elf: timer-test.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o timer-test.elf timer-test.o + +dump: timer-test.elf + riscv32-none-elf-objdump -d timer-test.elf + +timer-test.hex: timer-test.elf + riscv32-none-elf-objcopy -O ihex timer-test.elf timer-test.hex + +load: timer-test.hex + bash -c "wl-copy < timer-test.hex" + +clean: + rm -f timer-test.hex timer-test.elf timer-test.o + diff --git a/assembly/timer-test/rvcontroller.ld b/assembly/timer-test/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/timer-test/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file 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: diff --git a/assembly/timer-test/timer-test.elf b/assembly/timer-test/timer-test.elf Binary files differnew file mode 100755 index 0000000..729cb45 --- /dev/null +++ b/assembly/timer-test/timer-test.elf diff --git a/assembly/timer-test/timer-test.hex b/assembly/timer-test/timer-test.hex new file mode 100644 index 0000000..c909eb4 --- /dev/null +++ b/assembly/timer-test/timer-test.hex @@ -0,0 +1,7 @@ +:1000000097020000938202047390523093020040E2
+:1000100073B00231930200087390423097020000DF
+:10002000938202047390128003A32200150323A578
+:1000300062007360043073005010A9487300000020
+:100040007D5323A56200732520348548730000008A
+:0E0050002945AD487300000073002030010008
+:00000001FF
diff --git a/assembly/timer-test/timer-test.o b/assembly/timer-test/timer-test.o Binary files differnew file mode 100644 index 0000000..3f2e505 --- /dev/null +++ b/assembly/timer-test/timer-test.o |
