summaryrefslogtreecommitdiff
path: root/assembly/multiplatform
diff options
context:
space:
mode:
authorcheapie <cheapiephp@gmail.com>2026-09-05 14:43:50 -0500
committercheapie <cheapiephp@gmail.com>2026-09-05 14:43:50 -0500
commit6656c9b277324caf1ecd90cbf4c83e14a8608a33 (patch)
tree3978ca653ea49dfc29628869e054fcc7dc8d4622 /assembly/multiplatform
parentf4ca429185eef4083a4ea3c013cd148a74aaee75 (diff)
downloadrvcontroller-6656c9b277324caf1ecd90cbf4c83e14a8608a33.tar
rvcontroller-6656c9b277324caf1ecd90cbf4c83e14a8608a33.tar.gz
rvcontroller-6656c9b277324caf1ecd90cbf4c83e14a8608a33.tar.bz2
rvcontroller-6656c9b277324caf1ecd90cbf4c83e14a8608a33.tar.xz
rvcontroller-6656c9b277324caf1ecd90cbf4c83e14a8608a33.zip
Add multi-platform demo
Diffstat (limited to 'assembly/multiplatform')
-rw-r--r--assembly/multiplatform/Makefile26
-rw-r--r--assembly/multiplatform/README.txt8
-rw-r--r--assembly/multiplatform/multiplatform.S62
-rwxr-xr-xassembly/multiplatform/multiplatform.binbin0 -> 216 bytes
4 files changed, 96 insertions, 0 deletions
diff --git a/assembly/multiplatform/Makefile b/assembly/multiplatform/Makefile
new file mode 100644
index 0000000..205af78
--- /dev/null
+++ b/assembly/multiplatform/Makefile
@@ -0,0 +1,26 @@
+MARCH ?= rv64im_zicond_zifencei
+
+.PHONY: all dump clean load
+
+all: multiplatform.bin multiplatform.hex multiplatform.elf
+
+multiplatform.o: multiplatform.S
+ riscv64-linux-gnu-as -I../rvcontroller-libraries -march=${MARCH} -o multiplatform.o multiplatform.S
+
+multiplatform.elf: multiplatform.o
+ riscv64-linux-gnu-ld -o multiplatform.elf multiplatform.o
+
+dump: multiplatform.elf
+ riscv64-linux-gnu-objdump -d multiplatform.elf
+
+multiplatform.bin: multiplatform.elf
+ riscv64-linux-gnu-objcopy -O binary multiplatform.elf multiplatform.bin
+
+multiplatform.hex: multiplatform.elf
+ riscv64-linux-gnu-objcopy -O ihex multiplatform.elf multiplatform.hex
+
+load: multiplatform.hex
+ bash -c "wl-copy < multiplatform.hex"
+
+clean:
+ rm -f multiplatform.bin multiplatform.hex multiplatform.elf multiplatform.o
diff --git a/assembly/multiplatform/README.txt b/assembly/multiplatform/README.txt
new file mode 100644
index 0000000..21b6305
--- /dev/null
+++ b/assembly/multiplatform/README.txt
@@ -0,0 +1,8 @@
+This demo is a bit different, this one assembles once and then runs on RVController, on riscv64 Linux, and on LBPHacker's R4 computer[1], no modification needed.
+
+You will need a riscv64-linux-gnu toolchain to build this. Your distro might ship one, check there before building your own. If you do build your own, you probably just need binutils.
+
+Platform-specific notes:
+R4: Load it at any address you want, nothing special needed, terminal base address is assumed to be 0x10000000
+RVController: At least for me it wants to link at 0x100b0, you can relocate it or just add a bit of extra RAM and use setpc before starting
+riscv64 Linux: No special handling needed
diff --git a/assembly/multiplatform/multiplatform.S b/assembly/multiplatform/multiplatform.S
new file mode 100644
index 0000000..2c564e4
--- /dev/null
+++ b/assembly/multiplatform/multiplatform.S
@@ -0,0 +1,62 @@
+_start:
+# Determine RV32/RV64
+li t0,2
+slli t0,t0,31 # This shift is out of bounds on RV32 but not RV64
+bnez t0,is_rv64
+
+# Detect R4
+div t0,zero,zero # div works on RVController but is decoded as mul by R4
+beqz t0,is_r4 # R4 outputs 0*0 = 0
+j is_rvcontroller # RVController outputs 0/0 = -1
+
+is_rv64:
+# RV64 platform of some sort, only supported one of those is Linux, output message to stdout
+li a7,0x40 # write()
+li a0,1 # stdout
+la a1,linux_message
+li a2,13 # count
+ecall
+
+li a7,0x5d # exit
+li a0,0 # return code
+ecall
+
+is_r4:
+li t0,0x10000014 # terminal color
+li t1,0xF # white on black
+sw t1,0(t0)
+
+li t0,0x10000004 # terminal hrange
+li t1,0x160 # 0-11
+sw t1,0(t0)
+
+li t0,0x10000008 # terminal vrange
+li t1,0xe0 # 0-7
+sw t1,0(t0)
+
+li t0,0x10000204 # terminal scrollprint
+la t2,r4_message
+loop:
+lb t1,0(t2) # read a character of the message
+beqz t1,done # check for end
+sw t1,0(t0) # print it
+addi t2,t2,1 # next character
+j loop
+
+done:
+ebreak
+
+
+is_rvcontroller:
+# RVController, output message to stdout
+li a7,4 # Print string
+la a0,rvc_message
+ecall
+li a7,10 # Exit program
+ecall
+
+linux_message: .ascii "Hello Linux!\n"
+r4_message: .asciz "Hello R4!"
+rvc_message: .asciz "Hello RVController!"
+
+.globl _start
diff --git a/assembly/multiplatform/multiplatform.bin b/assembly/multiplatform/multiplatform.bin
new file mode 100755
index 0000000..7c3337f
--- /dev/null
+++ b/assembly/multiplatform/multiplatform.bin
Binary files differ