aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-07-06 12:38:21 +0000
committers-ol <s+removethis@s-ol.nu>2021-07-06 12:39:34 +0000
commitc299060bc82e4e198891f4abeb293619cda75090 (patch)
treebd609bc2fb7108e18070db9e79c6f3c2a94dde55
parentfix hello_world comments (diff)
downloadsubv-c299060bc82e4e198891f4abeb293619cda75090.tar.gz
subv-c299060bc82e4e198891f4abeb293619cda75090.zip
reorganize, add ask_name example
-rw-r--r--.gitignore4
-rw-r--r--examples/.gitignore2
-rw-r--r--examples/ask_name.subv104
-rw-r--r--examples/ex.elf (renamed from ex.elf)bin8224 -> 8224 bytes
-rw-r--r--examples/ex.format (renamed from ex.format)0
-rw-r--r--examples/ex.pack (renamed from ex.pack)0
-rw-r--r--examples/ex.subv (renamed from ex.subv)0
-rw-r--r--examples/ex.survey (renamed from ex.survey)0
-rw-r--r--examples/ex.valid (renamed from ex.valid)0
-rw-r--r--examples/hello_world.subv (renamed from hello_world.subv)0
10 files changed, 108 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 3ce5b6d..3a8b84d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
-*.elf
*.bin
*.pyc
__pycache__
-!ex.*
+*.elf
+.gdb_history
diff --git a/examples/.gitignore b/examples/.gitignore
new file mode 100644
index 0000000..6a15fd6
--- /dev/null
+++ b/examples/.gitignore
@@ -0,0 +1,2 @@
+*.elf
+!ex.*
diff --git a/examples/ask_name.subv b/examples/ask_name.subv
new file mode 100644
index 0000000..b9e54bc
--- /dev/null
+++ b/examples/ask_name.subv
@@ -0,0 +1,104 @@
+# ask for the user's name,
+# then print it back with a hello message.
+#
+# until I figure out how to enable STDIN properly,
+# requires running qemu like so:
+#
+# $ ./subv.sh examples/ask_.subv >examples/ask_.elf
+# $ cat 2>dev/null | ./qemu.sh examples/ask_.elf
+# What's your name?
+# > Sol
+# Hello Sol, nice to meet you!
+
+== code 0x80000000
+ # trap all but first Hart (a0 = mhartid)
+ 63/branch 1/subop/!= a/rs/a0 0/rs/x0 0/off13
+
+main:
+ # print HELLO_WHATSURNAME
+ 37/lui a/rd/a0 HELLO_WHATSURNAME/imm20hi
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 HELLO_WHATSURNAME/imm12lo
+ 6f/jal 1/rd/ra print/off21
+
+ 37/lui a/rd/a0 Name/imm20hi
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 Name/imm12lo
+ 6f/jal 1/rd/ra read/off21
+
+ # print HELLO_
+ 37/lui a/rd/a0 HELLO_/imm20hi
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 HELLO_/imm12lo
+ 6f/jal 1/rd/ra print/off21
+
+ # print Name
+ 37/lui a/rd/a0 Name/imm20hi
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 Name/imm12lo
+ 6f/jal 1/rd/ra print/off21
+
+ # print NICETOMEETU
+ 37/lui a/rd/a0 NICETOMEETU/imm20hi
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 NICETOMEETU/imm12lo
+ 6f/jal 1/rd/ra print/off21
+
+ # infinite loop
+ 6f/jal 0/rd/x0 0/off21
+
+print:
+# print a C-string from a0
+ # load 0x10010000 (UART0) into t0
+ 37/lui 5/rd/t0 0x10010/imm20
+print:loop:
+ # load unsigned byte at x4
+ 03/load 4/subop/byte 6/rd/t1 a/rs/a0 0/imm12
+ # break loop if zero
+ 63/branch 0/subop/== 6/rs/t1 0/rs/x0 print:break/off13
+print:spin:
+ # spin if FIFO is full (t2 sign bit is set)
+ 03/load 2/subop/word 7/rd/t2 5/rs/t0 0/imm12
+ 63/branch 4/subop/< 7/rs/t2 0/rs/x0 print:spin/off13
+ # print char
+ 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
+ # increment a0
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 1/imm12
+ # jump back up
+ 6f/jal 0/rd/x0 print:loop/off21
+print:break:
+ # return
+ 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12
+
+read:
+# read a C-string into a0
+ # load 0x10010004 (UART0+4) into t0
+ 37/lui 5/rd/t0 0x10010/imm20
+ 13/opi 0/subop/add 5/rd/t0 5/rs/t0 4/imm12
+ # load 0x0a (\n) into t1
+ 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12
+read:loop:
+ # load word at a0 into t0
+ 03/load 2/subop/word 7/rd/t2 5/rs/t0 0/imm12
+ # spin if FIFO is empty (t2 sign bit is set)
+ 63/branch 4/subop/< 7/rs/t2 0/rs/x0 read:loop/off13
+ # break loop if newline (t2 == t1)
+ 63/branch 0/subop/== 7/rs/t2 6/rs/t1 read:break/off13
+ # store char at a0
+ 23/store 2/width/word a/rs/a0 7/rs/t2 0/off12
+ # increment a0
+ 13/opi 0/subop/add a/rd/a0 a/rs/a0 1/imm12
+ # jump back up
+ 6f/jal 0/rd/x0 read:loop/off21
+read:break:
+ # return
+ 67/jalr 0/subop 0/rd/x0 1/rs/ra 0/off12
+
+
+== data 0x80500000
+HELLO_WHATSURNAME:
+ # "What's your name?\n\0"
+ 57/8 68/8 61/8 74/8 27/8 73/8 20/8 79/8 6f/8 75/8 72/8 20/8 6e/8 61/8 6d/8 65/8 3f/8 0a/8 00/8
+HELLO_:
+ # "Hello \0"
+ 48/8 65/8 6c/8 6c/8 6f/8 20/8 00/8
+NICETOMEETU:
+ # ", nice to meet you!\n\0"
+ 2c/8 20/8 6e/8 69/8 63/8 65/8 20/8 74/8 6f/8 20/8 6d/8 65/8 65/8 74/8 20/8 79/8 6f/8 75/8 21/8 0a/8 00/8
+Name:
+ 00/8
diff --git a/ex.elf b/examples/ex.elf
index a509aaf..a509aaf 100644
--- a/ex.elf
+++ b/examples/ex.elf
Binary files differ
diff --git a/ex.format b/examples/ex.format
index 6727dd1..6727dd1 100644
--- a/ex.format
+++ b/examples/ex.format
diff --git a/ex.pack b/examples/ex.pack
index e0cb8b9..e0cb8b9 100644
--- a/ex.pack
+++ b/examples/ex.pack
diff --git a/ex.subv b/examples/ex.subv
index 408dabb..408dabb 100644
--- a/ex.subv
+++ b/examples/ex.subv
diff --git a/ex.survey b/examples/ex.survey
index e30860c..e30860c 100644
--- a/ex.survey
+++ b/examples/ex.survey
diff --git a/ex.valid b/examples/ex.valid
index 1652954..1652954 100644
--- a/ex.valid
+++ b/examples/ex.valid
diff --git a/hello_world.subv b/examples/hello_world.subv
index 579a0e6..579a0e6 100644
--- a/hello_world.subv
+++ b/examples/hello_world.subv