diff options
Diffstat (limited to 'assembly/multiplatform/multiplatform.S')
| -rw-r--r-- | assembly/multiplatform/multiplatform.S | 62 |
1 files changed, 62 insertions, 0 deletions
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 |
