summaryrefslogtreecommitdiff
path: root/assembly/multiplatform/multiplatform.S
blob: 2c564e4cfa63fd277233ea4643d0b59b0be1a5e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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