diff options
| author | cheapie <cheapiephp@gmail.com> | 2026-05-30 08:58:29 -0500 |
|---|---|---|
| committer | cheapie <cheapiephp@gmail.com> | 2026-05-30 08:58:29 -0500 |
| commit | d609dcb35dafebeafced9c40d92ddd5da630aa54 (patch) | |
| tree | be5b1083f2f12173dbe936306e46a11cff4d62ea /assembly | |
| parent | 28be6fac111899c930c8072cd42bcbd7be6f5d40 (diff) | |
| download | rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.gz rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.bz2 rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.xz rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.zip | |
Organize files better and include binaries for assembly samples
Diffstat (limited to 'assembly')
36 files changed, 882 insertions, 0 deletions
diff --git a/assembly/fib/Makefile b/assembly/fib/Makefile new file mode 100644 index 0000000..da333af --- /dev/null +++ b/assembly/fib/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: fib.hex + +fib.o: fib.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o fib.o fib.S + +fib.elf: fib.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o fib.elf fib.o + +dump: fib.elf + riscv32-none-elf-objdump -d fib.elf + +fib.hex: fib.elf + riscv32-none-elf-objcopy -O ihex fib.elf fib.hex + +load: fib.hex + bash -c "wl-copy < fib.hex" + +clean: + rm -f fib.bin fib.elf fib.o + diff --git a/assembly/fib/fib.S b/assembly/fib/fib.S new file mode 100644 index 0000000..e43195d --- /dev/null +++ b/assembly/fib/fib.S @@ -0,0 +1,29 @@ +li t0,0 +li t1,1 +li t3,0x7fffffff +loop: +add t2,t1,t0 +mv t0,t1 +mv t1,t2 +li a7,1 +mv a0,t0 +ecall +li a7,11 +li a0,0x0a +ecall +bltu t2,t3,loop + +li a0,0xa +li a7,11 +ecall +li a7,1 +rdinstret a0 +ecall +la a0,instructions +li a7,4 +ecall + +li a7,10 +ecall + +instructions: .asciz " instructions\n" diff --git a/assembly/fib/fib.elf b/assembly/fib/fib.elf Binary files differnew file mode 100755 index 0000000..2ebaf85 --- /dev/null +++ b/assembly/fib/fib.elf diff --git a/assembly/fib/fib.hex b/assembly/fib/fib.hex new file mode 100644 index 0000000..38d958b --- /dev/null +++ b/assembly/fib/fib.hex @@ -0,0 +1,7 @@ +:1000000081420543370E00807D1EB30353009A8260
+:100010001E838548168573000000AD48294573008E
+:100020000000E3E4C3FF2945AD48730000008548A4
+:10003000732520C07300000017050000130545015B
+:10004000914873000000A9487300000020696E7396
+:0C0050007472756374696F6E730A0000AF
+:00000001FF
diff --git a/assembly/fib/fib.o b/assembly/fib/fib.o Binary files differnew file mode 100644 index 0000000..0e62572 --- /dev/null +++ b/assembly/fib/fib.o diff --git a/assembly/fib/rvcontroller.ld b/assembly/fib/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/fib/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file diff --git a/assembly/guessnum-random/Makefile b/assembly/guessnum-random/Makefile new file mode 100644 index 0000000..62eda18 --- /dev/null +++ b/assembly/guessnum-random/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: guessnum-random.hex + +guessnum-random.o: guessnum-random.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o guessnum-random.o guessnum-random.S + +guessnum-random.elf: guessnum-random.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o guessnum-random.elf guessnum-random.o + +dump: guessnum-random.elf + riscv32-none-elf-objdump -d guessnum-random.elf + +guessnum-random.hex: guessnum-random.elf + riscv32-none-elf-objcopy -O ihex guessnum-random.elf guessnum-random.hex + +load: guessnum-random.hex + bash -c "wl-copy < guessnum-random.hex" + +clean: + rm -f guessnum-random.bin guessnum-random.elf guessnum-random.o + diff --git a/assembly/guessnum-random/guessnum-random.S b/assembly/guessnum-random/guessnum-random.S new file mode 100644 index 0000000..0f890cd --- /dev/null +++ b/assembly/guessnum-random/guessnum-random.S @@ -0,0 +1,126 @@ +restart: +rdtime t3 # Get the time the program was started at + +li a7,11 # Print character +li a0,0xa # \n +ecall +li t0,0 # Number of guesses + +# Get a random number for the player to guess +li a7,128 # Get random integer +li a0,1 # Lower bound = 1 +li a1,99 # Upper bound = 99 +ecall +mv t1,a0 # Put the result in t1 where it's expected + +loop: +# Increment number of guesses +addi t0,t0,1 + +# Prompt player to enter their guess +li a7,4 # Write string +la a0,prompt # 'Enter your guess' prompt address +ecall + +# Read the player's guess +li a7,5 # Read integer +ecall +mv t2,a0 # Store it in t2 + +# Print it back out +li a7,1 # Write integer +ecall +li a7,11 # Write character +li a0,0xa # \n +ecall + +# Replace it with a random number +li a0,0 # Lower bound = 0 +li a1,100 # Upper bound = 100 +li a7,128 # Get random integer +ecall +mv t2,a0 + +# Too low? +blt t2,t1,toolow + +# Too high? +blt t1,t2,toohigh + +# Otherwise it must be right +j correct + +toolow: +# Show too low message +li a7,4 # Write string +la a0,toolowmsg +ecall +j loop # Go back for the next guess + +toohigh: +# Show too high message +li a7,4 # Write string +la a0,toohighmsg +ecall +j loop # Go back for the next guess + +correct: +# Show congratulations message +li a7,4 # Write string +la a0,correctmsg +ecall + +# Show number of guesses +mv a0,t0 # Get the number of guesses +li a7,1 # Write integer +ecall + +# Add proper suffix depending on whether it should be plural or not +li a7,4 # Write string +la a0,guessesmsg # "guess" +ecall +li t2,1 +beq t0,t2,playagain # Leave it singular if it was 1 +la a0,guessespluralize # "es" +ecall + +playagain: +li a7,11 # Write character +li a0,0xa # \n +ecall +# Show the number of seconds the player took +rdtime t4 # Get the current time +sub a0,t4,t3 # Subtract the start time +li a7,1 # Write integer +ecall +li a7,4 # Write string +la a0,seconds +ecall + +li a7,11 # Print character +li a0,0xa # \n +ecall + +# Ask the user if they want to play again +li a7,4 # Write string +la a0,playagainmsg +ecall +li a7,12 # Read character +ecall +li a7,11 # Write character +ecall +li t0,0x6e # n +bne a0,t0,restart + +li a7,10 # Exit program +ecall + + +prompt: .asciz "Enter your guess:\n> " +toolowmsg: .asciz "Too low! Try again\n" +toohighmsg: .asciz "Too high! Try again\n" +correctmsg: .asciz "Correct!\nYou got it in:\n" +guessesmsg: .asciz " guess" +guessespluralize: .asciz "es" +seconds: .asciz " seconds" +playagainmsg: .asciz "Play again? [Y/n]" diff --git a/assembly/guessnum-random/guessnum-random.elf b/assembly/guessnum-random/guessnum-random.elf Binary files differnew file mode 100755 index 0000000..7b75725 --- /dev/null +++ b/assembly/guessnum-random/guessnum-random.elf diff --git a/assembly/guessnum-random/guessnum-random.hex b/assembly/guessnum-random/guessnum-random.hex new file mode 100644 index 0000000..7d535d9 --- /dev/null +++ b/assembly/guessnum-random/guessnum-random.hex @@ -0,0 +1,26 @@ +:10000000732E10C0AD48294573000000814293084B
+:100010000008054593053006730000002A83850219
+:100020009148170500001305650E73000000954800
+:1000300073000000AA83854873000000AD4829457D
+:100040007300000001459305400693080008730003
+:100050000000AA8363C56300634B73000DA0914841
+:10006000170500001305D50B730000004DBF914824
+:10007000170500001305150C730000004DB79148DB
+:10008000170500001305650C7300000016858548F0
+:10009000730000009148170500001305950C7300CC
+:1000A0000000854363887200170500001305E50B07
+:1000B00073000000AD48294573000000F32E10C006
+:1000C0003385CE4185487300000091481705000034
+:1000D0001305D50973000000AD48294573000000E1
+:1000E0009148170500001305050973000000B14889
+:1000F00073000000AD48730000009302E006E311B6
+:1001000055F0A94873000000456E74657220796F40
+:1001100075722067756573733A0A3E2000546F6FDD
+:10012000206C6F77212054727920616761696E0AB3
+:1001300000546F6F206869676821205472792061CC
+:100140006761696E0A00436F7272656374210A59B0
+:100150006F7520676F7420697420696E3A0A0020F9
+:10016000677565737300657300207365636F6E64F4
+:100170007300506C617920616761696E3F205B5943
+:040180002F6E5D0081
+:00000001FF
diff --git a/assembly/guessnum-random/guessnum-random.o b/assembly/guessnum-random/guessnum-random.o Binary files differnew file mode 100644 index 0000000..757d611 --- /dev/null +++ b/assembly/guessnum-random/guessnum-random.o diff --git a/assembly/guessnum-random/rvcontroller.ld b/assembly/guessnum-random/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/guessnum-random/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file diff --git a/assembly/guessnum/Makefile b/assembly/guessnum/Makefile new file mode 100644 index 0000000..98b8d65 --- /dev/null +++ b/assembly/guessnum/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: guessnum.hex + +guessnum.o: guessnum.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o guessnum.o guessnum.S + +guessnum.elf: guessnum.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o guessnum.elf guessnum.o + +dump: guessnum.elf + riscv32-none-elf-objdump -d guessnum.elf + +guessnum.hex: guessnum.elf + riscv32-none-elf-objcopy -O ihex guessnum.elf guessnum.hex + +load: guessnum.hex + bash -c "wl-copy < guessnum.hex" + +clean: + rm -f guessnum.bin guessnum.elf guessnum.o + diff --git a/assembly/guessnum/guessnum.S b/assembly/guessnum/guessnum.S new file mode 100644 index 0000000..8d5b2fb --- /dev/null +++ b/assembly/guessnum/guessnum.S @@ -0,0 +1,119 @@ +restart: +rdtime t3 # Get the time the program was started at + +li a7,11 # Print character +li a0,0xa # \n +ecall +li t0,0 # Number of guesses + +# Get a random number for the player to guess +li a7,128 # Get random integer +li a0,1 # Lower bound = 1 +li a1,99 # Upper bound = 99 +ecall +mv t1,a0 # Put the result in t1 where it's expected + +loop: +# Increment number of guesses +addi t0,t0,1 + +# Prompt player to enter their guess +li a7,4 # Write string +la a0,prompt # 'Enter your guess' prompt address +ecall + +# Read the player's guess +li a7,5 # Read integer +ecall +mv t2,a0 # Store it in t2 + +# Print it back out +li a7,1 # Write integer +ecall +li a7,11 # Write character +li a0,0xa # \n +ecall + +# Too low? +blt t2,t1,toolow + +# Too high? +blt t1,t2,toohigh + +# Otherwise it must be right +j correct + +toolow: +# Show too low message +li a7,4 # Write string +la a0,toolowmsg +ecall +j loop # Go back for the next guess + +toohigh: +# Show too high message +li a7,4 # Write string +la a0,toohighmsg +ecall +j loop # Go back for the next guess + +correct: +# Show congratulations message +li a7,4 # Write string +la a0,correctmsg +ecall + +# Show number of guesses +mv a0,t0 # Get the number of guesses +li a7,1 # Write integer +ecall + +# Add proper suffix depending on whether it should be plural or not +li a7,4 # Write string +la a0,guessesmsg # "guess" +ecall +li t2,1 +beq t0,t2,playagain # Leave it singular if it was 1 +la a0,guessespluralize # "es" +ecall + +playagain: +li a7,11 # Write character +li a0,0xa # \n +ecall +# Show the number of seconds the player took +rdtime t4 # Get the current time +sub a0,t4,t3 # Subtract the start time +li a7,1 # Write integer +ecall +li a7,4 # Write string +la a0,seconds +ecall + +li a7,11 # Print character +li a0,0xa # \n +ecall + +# Ask the user if they want to play again +li a7,4 # Write string +la a0,playagainmsg +ecall +li a7,12 # Read character +ecall +li a7,11 # Write character +ecall +li t0,0x6e # n +bne a0,t0,restart + +li a7,10 # Exit program +ecall + + +prompt: .asciz "Enter your guess:\n> " +toolowmsg: .asciz "Too low! Try again\n" +toohighmsg: .asciz "Too high! Try again\n" +correctmsg: .asciz "Correct!\nYou got it in:\n" +guessesmsg: .asciz " guess" +guessespluralize: .asciz "es" +seconds: .asciz " seconds" +playagainmsg: .asciz "Play again? [Y/n]" diff --git a/assembly/guessnum/guessnum.elf b/assembly/guessnum/guessnum.elf Binary files differnew file mode 100755 index 0000000..e130c53 --- /dev/null +++ b/assembly/guessnum/guessnum.elf diff --git a/assembly/guessnum/guessnum.hex b/assembly/guessnum/guessnum.hex new file mode 100644 index 0000000..d15f60d --- /dev/null +++ b/assembly/guessnum/guessnum.hex @@ -0,0 +1,25 @@ +:10000000732E10C0AD48294573000000814293084B
+:100010000008054593053006730000002A83850219
+:100020009148170500001305650D73000000954801
+:1000300073000000AA83854873000000AD4829457D
+:100040007300000063C56300634B73000DA091480B
+:10005000170500001305D50B73000000C9B79148C0
+:10006000170500001305150C730000004DBF9148E3
+:10007000170500001305650C730000001685854800
+:10008000730000009148170500001305950C7300DC
+:100090000000854363887200170500001305E50B17
+:1000A00073000000AD48294573000000F32E10C016
+:1000B0003385CE4185487300000091481705000044
+:1000C0001305D50973000000AD48294573000000F1
+:1000D0009148170500001305050973000000B14899
+:1000E00073000000AD48730000009302E006E319BE
+:1000F00055F0A94873000000456E74657220796F51
+:1001000075722067756573733A0A3E2000546F6FED
+:10011000206C6F77212054727920616761696E0AC3
+:1001200000546F6F206869676821205472792061DC
+:100130006761696E0A00436F7272656374210A59C0
+:100140006F7520676F7420697420696E3A0A002009
+:10015000677565737300657300207365636F6E6404
+:100160007300506C617920616761696E3F205B5953
+:040170002F6E5D0091
+:00000001FF
diff --git a/assembly/guessnum/guessnum.o b/assembly/guessnum/guessnum.o Binary files differnew file mode 100644 index 0000000..18672aa --- /dev/null +++ b/assembly/guessnum/guessnum.o diff --git a/assembly/guessnum/rvcontroller.ld b/assembly/guessnum/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/guessnum/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file diff --git a/assembly/hello/Makefile b/assembly/hello/Makefile new file mode 100644 index 0000000..d7649e5 --- /dev/null +++ b/assembly/hello/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: hello.hex + +hello.o: hello.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o hello.o hello.S + +hello.elf: hello.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o hello.elf hello.o + +dump: hello.elf + riscv32-none-elf-objdump -d hello.elf + +hello.hex: hello.elf + riscv32-none-elf-objcopy -O ihex hello.elf hello.hex + +load: hello.hex + bash -c "wl-copy < hello.hex" + +clean: + rm -f hello.bin hello.elf hello.o + diff --git a/assembly/hello/hello.S b/assembly/hello/hello.S new file mode 100644 index 0000000..3eecf13 --- /dev/null +++ b/assembly/hello/hello.S @@ -0,0 +1,6 @@ +la a0,message +li a7,4 +ecall +li a7,10 +ecall +message: .asciz "Hello, world!\n" diff --git a/assembly/hello/hello.elf b/assembly/hello/hello.elf Binary files differnew file mode 100755 index 0000000..6aec39b --- /dev/null +++ b/assembly/hello/hello.elf diff --git a/assembly/hello/hello.hex b/assembly/hello/hello.hex new file mode 100644 index 0000000..f689ad4 --- /dev/null +++ b/assembly/hello/hello.hex @@ -0,0 +1,4 @@ +:100000001705000013054501914873000000A94839
+:100010007300000048656C6C6F2C20776F726C6405
+:04002000210A0000B1
+:00000001FF
diff --git a/assembly/hello/hello.o b/assembly/hello/hello.o Binary files differnew file mode 100644 index 0000000..2d0bfb3 --- /dev/null +++ b/assembly/hello/hello.o diff --git a/assembly/hello/rvcontroller.ld b/assembly/hello/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/hello/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file diff --git a/assembly/misa/Makefile b/assembly/misa/Makefile new file mode 100644 index 0000000..95095b6 --- /dev/null +++ b/assembly/misa/Makefile @@ -0,0 +1,26 @@ +# Intentionally less complete default march so that it's still compatible with RVController's minimum configuration +# (in case someone changed the misa value and wants to decode the new one) +MARCH ?= rv32ezicsr_zicond + +.PHONY: all dump load clean + +all: misa.hex + +misa.o: misa.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o misa.o misa.S + +misa.elf: misa.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o misa.elf misa.o + +dump: misa.elf + riscv32-none-elf-objdump -d misa.elf + +misa.hex: misa.elf + riscv32-none-elf-objcopy -O ihex misa.elf misa.hex + +load: misa.hex + bash -c "wl-copy < misa.hex" + +clean: + rm -f misa.bin misa.elf misa.o + diff --git a/assembly/misa/misa.S b/assembly/misa/misa.S new file mode 100644 index 0000000..a360c5e --- /dev/null +++ b/assembly/misa/misa.S @@ -0,0 +1,126 @@ +csrr t0,misa # Read misa + +li a5,11 # Print character +li a0,'R' +ecall +li a0,'V' +ecall +li a0,'3' +ecall +li a0,'2' +ecall + +li t1,1<<8 +and t1,t0,t1 +li a5,11 +li a0,'I' +czero.eqz a5,a5,t1 # Clear ecall function if bit isn't set +ecall + +li t1,1<<4 +and t1,t0,t1 +li a5,11 +li a0,'E' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<12 +and t1,t0,t1 +li a5,11 +li a0,'M' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<0 +and t1,t0,t1 +li a5,11 +li a0,'A' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<5 +and t1,t0,t1 +li a5,11 +li a0,'F' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<3 +and t1,t0,t1 +li a5,11 +li a0,'D' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<16 +and t1,t0,t1 +li a5,11 +li a0,'Q' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<11 +and t1,t0,t1 +li a5,11 +li a0,'L' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<2 +and t1,t0,t1 +li a5,11 +li a0,'C' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<1 +and t1,t0,t1 +li a5,11 +li a0,'B' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<9 +and t1,t0,t1 +li a5,11 +li a0,'J' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<19 +and t1,t0,t1 +li a5,11 +li a0,'T' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<15 +and t1,t0,t1 +li a5,11 +li a0,'P' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<21 +and t1,t0,t1 +li a5,11 +li a0,'V' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<7 +and t1,t0,t1 +li a5,11 +li a0,'H' +czero.eqz a5,a5,t1 +ecall + +li t1,1<<18 +and t1,t0,t1 +li a5,11 +li a0,'S' +czero.eqz a5,a5,t1 +ecall + +li a5,10 +ecall diff --git a/assembly/misa/misa.elf b/assembly/misa/misa.elf Binary files differnew file mode 100755 index 0000000..6f5e949 --- /dev/null +++ b/assembly/misa/misa.elf diff --git a/assembly/misa/misa.hex b/assembly/misa/misa.hex new file mode 100644 index 0000000..4f70427 --- /dev/null +++ b/assembly/misa/misa.hex @@ -0,0 +1,29 @@ +:10000000F32210309307B0001305200573000000A1
+:100010001305600573000000130530037300000032
+:1000200013052003730000001303001033F3620074
+:100030009307B00013059004B3D7670E7300000058
+:100040001303000133F362009307B000130550045B
+:10005000B3D7670E730000003713000033F362005C
+:100060009307B0001305D004B3D7670E73000000E8
+:100070001303100033F362009307B000130510045C
+:10008000B3D7670E730000001303000233F362005E
+:100090009307B00013056004B3D7670E7300000028
+:1000A0001303800033F362009307B000130540048C
+:1000B000B3D7670E730000003703010033F362000B
+:1000C0009307B00013051005B3D7670E7300000047
+:1000D000371300001303038033F362009307B0006B
+:1000E0001305C004B3D7670E73000000130340006C
+:1000F00033F362009307B00013053004B3D7670EE3
+:10010000730000001303200033F362009307B00074
+:1001100013052004B3D7670E7300000013030020FB
+:1001200033F362009307B0001305A004B3D7670E42
+:10013000730000003703080033F362009307B00038
+:1001400013054005B3D7670E730000003783000026
+:1001500033F362009307B00013050005B3D7670EB1
+:10016000730000003703200033F362009307B000F0
+:1001700013056005B3D7670E730000001303000872
+:1001800033F362009307B00013058004B3D7670E02
+:10019000730000003703040033F362009307B000DC
+:1001A00013053005B3D7670E730000009307A00056
+:0401B00073000000D8
+:00000001FF
diff --git a/assembly/misa/misa.o b/assembly/misa/misa.o Binary files differnew file mode 100644 index 0000000..a8b734a --- /dev/null +++ b/assembly/misa/misa.o diff --git a/assembly/misa/rvcontroller.ld b/assembly/misa/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/misa/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file diff --git a/assembly/rrxing/Makefile b/assembly/rrxing/Makefile new file mode 100644 index 0000000..1f19256 --- /dev/null +++ b/assembly/rrxing/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: rrxing.hex + +rrxing.o: rrxing.S + riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o rrxing.o rrxing.S + +rrxing.elf: rrxing.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o rrxing.elf rrxing.o + +dump: rrxing.elf + riscv32-none-elf-objdump -d rrxing.elf + +rrxing.hex: rrxing.elf + riscv32-none-elf-objcopy -O ihex rrxing.elf rrxing.hex + +load: rrxing.hex + bash -c "wl-copy < rrxing.hex" + +clean: + rm -f rrxing.bin rrxing.elf rrxing.o + diff --git a/assembly/rrxing/rrxing.S b/assembly/rrxing/rrxing.S new file mode 100644 index 0000000..61fb41c --- /dev/null +++ b/assembly/rrxing/rrxing.S @@ -0,0 +1,198 @@ +li a7,134 # Clear digilines buffer +ecall + +restart: +# Hardware initialization + +# Make sure light is off +li a7,129 # Send digilines message +la a0,lightchannel +la a1,lightoffmsg +ecall + +# Make sure bell is off +li a7,129 # Send digilines message +la a0,bellchannel +la a1,belloffmsg +ecall + +# Make sure gate is up +li a7,129 # Send digilines message +la a0,gatechannel +la a1,gateupmsg +ecall + +receiveloop: +li a7,133 # Get digilines buffer level +ecall +beq a0,x0,receiveloop # If no messages yet, restart the loop + +li a7,135 # Read digilines message +la a0,channelbuf +li a1,16 # Channel buffer size +la a2,msgbuf +li a3,16 # Message buffer size +ecall + +# Check if it's the right channel +la a0,channelbuf +la a1,detectchannel +call strcmp +beq a0,x0,receiveloop # Not the right channel, ignore it + +# Turn the light yellow +li a7,129 # Send digilines message +la a0,lightchannel +la a1,lightyellowmsg +ecall + +# Wait 1 second +li a0,1 +call sleep + +# Turn the bell on +li a7,129 # Send digilines message +la a0,bellchannel +la a1,bellonmsg +ecall + +# Wait 2 seconds +li a0,2 +call sleep + +# Turn the light red +li a7,129 # Send digilines message +la a0,lightchannel +la a1,lightredmsg +ecall + +# Wait 3 seconds +li a0,3 +call sleep + +# Lower the gate +li a7,129 # Send digilines message +la a0,gatechannel +la a1,gatedownmsg +ecall + +# Wait 5 seconds +li a0,5 +call sleep + +# Turn the bell off +li a7,129 # Send digilines message +la a0,bellchannel +la a1,belloffmsg +ecall + +waitlonger: + +# Wait 10 seconds +li a0,10 +call sleep + +# Check if any more trains have been detected +receiveloop2: +li a7,133 # Get digilines buffer level +ecall +beq a0,x0,raise # If no messages yet, go ahead with timing out + +# If there is a message, check if it's a train + +li a7,135 # Read digilines message +la a0,channelbuf +li a1,16 # Channel buffer size +la a2,msgbuf +li a3,16 # Message buffer size +ecall + +# Check if it's the right channel +la a0,channelbuf +la a1,detectchannel +call strcmp +beq a0,x0,receiveloop2 # Not the right channel, ignore this message and go on to the next + +# If it is the right channel, then get rid of the rest of the messages (if any) +li a7,134 # Clear digilines buffer +ecall + +j waitlonger # And go wait another 10 seconds + +raise: + +# Raise the gate +li a7,129 # Send digilines message +la a0,gatechannel +la a1,gateupmsg +ecall + +# Wait 2 seconds +li a0,2 +call sleep + +# Turn the light off +li a7,129 # Send digilines message +la a0,lightchannel +la a1,lightoffmsg +ecall + +# And go wait for the next train +j restart + +sleep: + # Expects a number of seconds in a0 + # Uses t0 + rdtime t0 + add a0,t0,a0 + sleep_loop: + rdtime t0 + bltu t0,a0,sleep_loop +ret + +strcmp: + # Expects string pointers in a0 and a1 + # Compares until a NUL is reached on the first string + # Uses t0, t1, and t2 + # Returns a0=1 if strings match, a0=0 otherwise + li t0,0 # t0 is the loop counter + strcmp_loop: + # Calculate addresses + add t1,a0,t0 # t1 is the pointer for the first string + add t2,a1,t0 # t2 is the pointer for the second string + + # Read the bytes from each string + lb t1,0(t1) + lb t2,0(t2) + + # Increment the loop counter + addi t0,t0,1 + + # And compare + bne t1,t2,strcmp_mismatch + + # Check if a terminator was reached yet, keep going otherwise + li t2,0 + bne t1,t2,strcmp_loop + + # If we got here they match + li a0,1 + ret + + strcmp_mismatch: + li a0,0 + ret + +channelbuf: .ascii " " +msgbuf: .ascii " " +lightchannel: .asciz "light" +bellchannel: .asciz "bell" +gatechannel: .asciz "gate" +lightoffmsg: .asciz "OFF" +lightyellowmsg: .asciz "YELLOW" +lightredmsg: .asciz "RED" +bellonmsg: .asciz "on" +belloffmsg: .asciz "off" +gateupmsg: .asciz "up" +gatedownmsg: .asciz "down" +detectchannel: .asciz "detect" diff --git a/assembly/rrxing/rrxing.elf b/assembly/rrxing/rrxing.elf Binary files differnew file mode 100755 index 0000000..cab0bf9 --- /dev/null +++ b/assembly/rrxing/rrxing.elf diff --git a/assembly/rrxing/rrxing.hex b/assembly/rrxing/rrxing.hex new file mode 100644 index 0000000..7283fa9 --- /dev/null +++ b/assembly/rrxing/rrxing.hex @@ -0,0 +1,35 @@ +:1000000093086008730000009308100817050000AB
+:100010001305A51D970500009385251E730000009C
+:1000200093081008170500001305851C97050000AC
+:100030009385C51D73000000930810081705000084
+:100040001305551B970500009385851C7300000060
+:10005000930850087300000065DD930870081705C9
+:10006000000013058516C145170600001306E616A5
+:10007000C14673000000170500001305051597051C
+:10008000000093856519292A61D593081008170582
+:10009000000013058515970500009385451673002C
+:1000A00000000545F520930810081705000013050A
+:1000B0002514970500009385351573000000094548
+:1000C000C1289308100817050000130505129705AD
+:1000D000000093853513730000000D4555289308E3
+:1000E0001008170500001305F5109705000093850B
+:1000F0005512730000001545612893081008170574
+:1001000000001305E50E9705000093852510730088
+:1001100000002945B528930850087300000015CD4C
+:1001200093087008170500001305250AC145170636
+:1001300000001306860AC146730000001705000080
+:100140001305A508970500009385050D912861D535
+:1001500093086008730000006DBF9308100817052E
+:10016000000013053509970500009385650A7300A3
+:1001700000000945312893081008170500001305F1
+:10018000C506970500009385450773000000ADBDC7
+:10019000F32210C01695F32210C0E3EEA2FE828077
+:1001A000814233035500B383550003030300838367
+:1001B00003008502631773008143E31473FE054552
+:1001C00082800145828020202020202020202020A5
+:1001D000202020202020202020202020202020201F
+:1001E0002020202020206C696768740062656C6C98
+:1001F0000067617465004F46460059454C4C4F57A7
+:1002000000524544006F6E006F66660075700064B2
+:0C0210006F776E00646574656374000015
+:00000001FF
diff --git a/assembly/rrxing/rrxing.o b/assembly/rrxing/rrxing.o Binary files differnew file mode 100644 index 0000000..09193ef --- /dev/null +++ b/assembly/rrxing/rrxing.o diff --git a/assembly/rrxing/rvcontroller.ld b/assembly/rrxing/rvcontroller.ld new file mode 120000 index 0000000..bc01402 --- /dev/null +++ b/assembly/rrxing/rvcontroller.ld @@ -0,0 +1 @@ +../../rvcontroller.ld
\ No newline at end of file |
