aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-07-09 14:36:47 +0000
committers-ol <s+removethis@s-ol.nu>2021-07-09 14:39:04 +0000
commitdd0f115ef08293623236b25810a770cd42be5bca (patch)
tree9d901e2b05521de105499b9feac9ede1fbf62eaf
parentvalidate opi, system (diff)
downloadsubv-dd0f115ef08293623236b25810a770cd42be5bca.tar.gz
subv-dd0f115ef08293623236b25810a770cd42be5bca.zip
examples: exit via SBI
-rw-r--r--README.rst110
-rw-r--r--examples/ask_name.subv12
-rw-r--r--examples/hello_world.subv14
3 files changed, 76 insertions, 60 deletions
diff --git a/README.rst b/README.rst
index ed8ddd2..23da8ec 100644
--- a/README.rst
+++ b/README.rst
@@ -5,8 +5,8 @@ This is a wip clone of SubX_ for the RISC-V RV32I base ISA.
::
- $ <hello_world.subv ./validate.py | ./survey.py | ./format.py | ./pack.py | ./elf.py >hello_world.elf
- $ ./qemu.sh hello_world.elf
+ $ <examples/hello_world.subv ./validate.py | ./survey.py | ./format.py | ./pack.py | ./elf.py >examples/hello_world.elf
+ $ ./qemu.sh examples/hello_world.elf
Pipeline
--------
@@ -21,69 +21,69 @@ back to front:
and now front to back with a little example::
- $ ./validate.py <ex.subv >ex.valid
- $ ./survey.py <ex.valid >ex.survey
- $ ./format.py <ex.survey >ex.format
- $ ./pack.py <ex.format >ex.pack
- $ ./elf.py <ex.pack >ex.elf
+ $ ./validate.py <examples/ex.subv >examples/ex.valid
+ $ ./survey.py <examples/ex.valid >examples/ex.survey
+ $ ./format.py <examples/ex.survey >examples/ex.format
+ $ ./pack.py <examples/ex.format >examples/ex.pack
+ $ ./elf.py <examples/ex.pack >examples/ex.elf
$ ./qemu.sh ex.elf
``ex.subv``: hand-writable::
- == code 0x80000000
- # repeatedly print "Hi\n"
- main:
- # load 0x10010000 (UART0) into t0
- 37/lui 5/rd/t0 0x10010/imm20
- # store 0x48 (H) in UART0+0
- 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12
- 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
- # store 0x69 (i) in UART0+0
- 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12
- 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
- # store 0x0a (\n) in UART0+0
- 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12
- 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
- # jump back up to the top
- 6f/jal 0/rd/x0 main/off21
+ == code 0x80400000
+ # repeatedly print "Hi\n"
+ main:
+ # load 0x10000000 (UART0) into t0
+ 37/lui 5/rd/t0 10000/imm20
+ # store 0x48 (H) in UART0+0
+ 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12
+ 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
+ # store 0x69 (i) in UART0+0
+ 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12
+ 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
+ # store 0x0a (\n) in UART0+0
+ 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12
+ 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
+ # jump back up to the top
+ 6f/jal 0/rd/x0 main/off21
``ex.valid``: mnemonics validated and discarded::
- == code 0x80000000
- # repeatedly print "Hi\n"
- main:
- # load 0x10010000 (UART0) into t0
- 37/u 5/rd 10010/imm20
- # store 0x48 (H) in UART0+0
- 13/i 6/rd 0/funct3 0/rs 48/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # store 0x69 (i) in UART0+0
- 13/i 6/rd 0/funct3 0/rs 69/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # store 0x0a (\n) in UART0+0
- 13/i 6/rd 0/funct3 0/rs a/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # jump back up to the top
- 6f/j 0/rd main/off21
+ == code 0x80400000
+ # repeatedly print "Hi\n"
+ main:
+ # load 0x10000000 (UART0) into t0
+ 37/u 5/rd 10000/imm20
+ # store 0x48 (H) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs 48/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # store 0x69 (i) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs 69/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # store 0x0a (\n) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs a/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # jump back up to the top
+ 6f/j 0/rd main/off21
``ex.survey``: references resolved and labels removed::
- == code 0x80000000
- # repeatedly print "Hi\n"
- # main:
- # load 0x10010000 (UART0) into t0
- 37/u 5/rd 10010/imm20
- # store 0x48 (H) in UART0+0
- 13/i 6/rd 0/funct3 0/rs 48/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # store 0x69 (i) in UART0+0
- 13/i 6/rd 0/funct3 0/rs 69/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # store 0x0a (\n) in UART0+0
- 13/i 6/rd 0/funct3 0/rs a/imm12
- 23/s 5/rs1 0/imm12 2/funct3 6/rs2
- # jump back up to the top
- 6f/j 0/rd -1c/imm21
+ == code 0x80400000
+ # repeatedly print "Hi\n"
+ # main:
+ # load 0x10000000 (UART0) into t0
+ 37/u 5/rd 10000/imm20
+ # store 0x48 (H) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs 48/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # store 0x69 (i) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs 69/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # store 0x0a (\n) in UART0+0
+ 13/i 6/rd 0/funct3 0/rs a/imm12
+ 23/s 0/funct3 5/rs1 0/imm12 6/rs2
+ # jump back up to the top
+ 6f/j 0/rd -1c/imm21
``ex.format``: arguments sliced and diced and put into the ISA order::
diff --git a/examples/ask_name.subv b/examples/ask_name.subv
index f411bfc..dfd5a7a 100644
--- a/examples/ask_name.subv
+++ b/examples/ask_name.subv
@@ -42,8 +42,16 @@ main:
13/opi a/rd/a0 0/subop/add a/rs/a0 NICETOMEETU/imm12lo
6f/jal 1/rd/ra print/off21
- # infinite loop
- 6f/jal 0/rd/x0 0/off21
+exit:
+# system reset (via SBI extension SRST)
+ # a7 = ext id, a6 = fid, a0 = 0, a1 = 0
+ 37/lui 11/rd/a7 53525/imm20
+ 13/opi 11/rd/a7 0/subop/add 11/rs/a7 354/imm12
+ 33/opr 0/mode/norm 10/rd/a6 0/subop/add 0/rs/x0 0/rs/x0
+ 33/opr 0/mode/norm a/rd/a0 0/subop/add 0/rs/x0 0/rs/x0
+ 33/opr 0/mode/norm b/rd/a1 0/subop/add 0/rs/x0 0/rs/x0
+ # ECALL
+ 73/system 0/subop/priv 0/funct12/ecall
init:
# initialize UART0
diff --git a/examples/hello_world.subv b/examples/hello_world.subv
index d25aa83..b85739d 100644
--- a/examples/hello_world.subv
+++ b/examples/hello_world.subv
@@ -11,9 +11,17 @@ main:
13/opi a/rd/a0 0/subop/add a/rs/a0 Message/imm12lo
# call print
6f/jal 1/rd/ra print/off21
-loop:
- # infinite loop
- 6f/jal 0/rd/x0 main/off21
+
+exit:
+# system reset (via SBI extension SRST)
+ # a7 = ext id, a6 = fid, a0 = 0, a1 = 0
+ 37/lui 11/rd/a7 53525/imm20
+ 13/opi 11/rd/a7 0/subop/add 11/rs/a7 354/imm12
+ 33/opr 0/mode/norm 10/rd/a6 0/subop/add 0/rs/x0 0/rs/x0
+ 33/opr 0/mode/norm a/rd/a0 0/subop/add 0/rs/x0 0/rs/x0
+ 33/opr 0/mode/norm b/rd/a1 0/subop/add 0/rs/x0 0/rs/x0
+ # ECALL
+ 73/system 0/subop/priv 0/funct12/ecall
print:
# load 0x10000000 (UART0) into t0