From c299060bc82e4e198891f4abeb293619cda75090 Mon Sep 17 00:00:00 2001 From: s-ol Date: Tue, 6 Jul 2021 14:38:21 +0200 Subject: reorganize, add ask_name example --- .gitignore | 4 +- ex.elf | Bin 8224 -> 0 bytes ex.format | 16 ------- ex.pack | 16 ------- ex.subv | 16 ------- ex.survey | 16 ------- ex.valid | 16 ------- examples/.gitignore | 2 + examples/ask_name.subv | 104 ++++++++++++++++++++++++++++++++++++++++++++++ examples/ex.elf | Bin 0 -> 8224 bytes examples/ex.format | 16 +++++++ examples/ex.pack | 16 +++++++ examples/ex.subv | 16 +++++++ examples/ex.survey | 16 +++++++ examples/ex.valid | 16 +++++++ examples/hello_world.subv | 42 +++++++++++++++++++ hello_world.subv | 42 ------------------- 17 files changed, 230 insertions(+), 124 deletions(-) delete mode 100644 ex.elf delete mode 100644 ex.format delete mode 100644 ex.pack delete mode 100644 ex.subv delete mode 100644 ex.survey delete mode 100644 ex.valid create mode 100644 examples/.gitignore create mode 100644 examples/ask_name.subv create mode 100644 examples/ex.elf create mode 100644 examples/ex.format create mode 100644 examples/ex.pack create mode 100644 examples/ex.subv create mode 100644 examples/ex.survey create mode 100644 examples/ex.valid create mode 100644 examples/hello_world.subv delete mode 100644 hello_world.subv 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/ex.elf b/ex.elf deleted file mode 100644 index a509aaf..0000000 Binary files a/ex.elf and /dev/null differ diff --git a/ex.format b/ex.format deleted file mode 100644 index 6727dd1..0000000 --- a/ex.format +++ /dev/null @@ -1,16 +0,0 @@ -== code 0x80000000 -# repeatedly print "Hi\n" -# main: -# load 0x10010000 (UART0) into t0 -37/7 05/5 10010/20 -# store 0x48 (H) in UART0+0 -13/7 06/5 0/3 00/5 048/12 -23/7 00/5 2/3 05/5 06/5 00/7 -# store 0x69 (i) in UART0+0 -13/7 06/5 0/3 00/5 069/12 -23/7 00/5 2/3 05/5 06/5 00/7 -# store 0x0a (\n) in UART0+0 -13/7 06/5 0/3 00/5 00a/12 -23/7 00/5 2/3 05/5 06/5 00/7 -# jump back up to the top -6f/7 00/5 ff/8 1/1 3f2/10 1/1 diff --git a/ex.pack b/ex.pack deleted file mode 100644 index e0cb8b9..0000000 --- a/ex.pack +++ /dev/null @@ -1,16 +0,0 @@ -== code 0x80000000 -# repeatedly print "Hi\n" -# main: -# load 0x10010000 (UART0) into t0 -b7 02 01 10 -# store 0x48 (H) in UART0+0 -13 03 80 04 -23 a0 62 00 -# store 0x69 (i) in UART0+0 -13 03 90 06 -23 a0 62 00 -# store 0x0a (\n) in UART0+0 -13 03 a0 00 -23 a0 62 00 -# jump back up to the top -6f f0 5f fe diff --git a/ex.subv b/ex.subv deleted file mode 100644 index 408dabb..0000000 --- a/ex.subv +++ /dev/null @@ -1,16 +0,0 @@ -== 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 diff --git a/ex.survey b/ex.survey deleted file mode 100644 index e30860c..0000000 --- a/ex.survey +++ /dev/null @@ -1,16 +0,0 @@ -== 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 diff --git a/ex.valid b/ex.valid deleted file mode 100644 index 1652954..0000000 --- a/ex.valid +++ /dev/null @@ -1,16 +0,0 @@ -== 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 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/examples/ex.elf b/examples/ex.elf new file mode 100644 index 0000000..a509aaf Binary files /dev/null and b/examples/ex.elf differ diff --git a/examples/ex.format b/examples/ex.format new file mode 100644 index 0000000..6727dd1 --- /dev/null +++ b/examples/ex.format @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +# main: +# load 0x10010000 (UART0) into t0 +37/7 05/5 10010/20 +# store 0x48 (H) in UART0+0 +13/7 06/5 0/3 00/5 048/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# store 0x69 (i) in UART0+0 +13/7 06/5 0/3 00/5 069/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# store 0x0a (\n) in UART0+0 +13/7 06/5 0/3 00/5 00a/12 +23/7 00/5 2/3 05/5 06/5 00/7 +# jump back up to the top +6f/7 00/5 ff/8 1/1 3f2/10 1/1 diff --git a/examples/ex.pack b/examples/ex.pack new file mode 100644 index 0000000..e0cb8b9 --- /dev/null +++ b/examples/ex.pack @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +# main: +# load 0x10010000 (UART0) into t0 +b7 02 01 10 +# store 0x48 (H) in UART0+0 +13 03 80 04 +23 a0 62 00 +# store 0x69 (i) in UART0+0 +13 03 90 06 +23 a0 62 00 +# store 0x0a (\n) in UART0+0 +13 03 a0 00 +23 a0 62 00 +# jump back up to the top +6f f0 5f fe diff --git a/examples/ex.subv b/examples/ex.subv new file mode 100644 index 0000000..408dabb --- /dev/null +++ b/examples/ex.subv @@ -0,0 +1,16 @@ +== 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 diff --git a/examples/ex.survey b/examples/ex.survey new file mode 100644 index 0000000..e30860c --- /dev/null +++ b/examples/ex.survey @@ -0,0 +1,16 @@ +== 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 diff --git a/examples/ex.valid b/examples/ex.valid new file mode 100644 index 0000000..1652954 --- /dev/null +++ b/examples/ex.valid @@ -0,0 +1,16 @@ +== 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 diff --git a/examples/hello_world.subv b/examples/hello_world.subv new file mode 100644 index 0000000..579a0e6 --- /dev/null +++ b/examples/hello_world.subv @@ -0,0 +1,42 @@ +== code 0x80000000 + # trap all but first Hart (a0 = mhartid) + 63/branch 1/subop/!= a/rs/a0 0/rs/x0 0/off13 + +main: + # a0 = &message + # . load high bits + 37/lui a/rd/a0 Message/imm20hi + # . add low bits + 13/opi 0/subop/add a/rd/a0 a/rs/a0 Message/imm12lo + # call print + 6f/jal 1/rd/ra print/off21 +loop: + # infinite loop + 6f/jal 0/rd/x0 loop/off21 + +print: + # load 0x10010000 (UART0) into t0 + 37/lui 5/rd/t0 0x10010/imm20 +print:loop: + # load unsigned byte at a0 + 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 + 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 + +== data 0x80500000 +Message: + # "Hello World!\n\0" + 48/8 65/8 6c/8 6c/8 6f/8 20/8 77/8 6f/8 72/8 6c/8 64/8 21/8 0a/8 00/8 diff --git a/hello_world.subv b/hello_world.subv deleted file mode 100644 index 579a0e6..0000000 --- a/hello_world.subv +++ /dev/null @@ -1,42 +0,0 @@ -== code 0x80000000 - # trap all but first Hart (a0 = mhartid) - 63/branch 1/subop/!= a/rs/a0 0/rs/x0 0/off13 - -main: - # a0 = &message - # . load high bits - 37/lui a/rd/a0 Message/imm20hi - # . add low bits - 13/opi 0/subop/add a/rd/a0 a/rs/a0 Message/imm12lo - # call print - 6f/jal 1/rd/ra print/off21 -loop: - # infinite loop - 6f/jal 0/rd/x0 loop/off21 - -print: - # load 0x10010000 (UART0) into t0 - 37/lui 5/rd/t0 0x10010/imm20 -print:loop: - # load unsigned byte at a0 - 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 - 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 - -== data 0x80500000 -Message: - # "Hello World!\n\0" - 48/8 65/8 6c/8 6c/8 6f/8 20/8 77/8 6f/8 72/8 6c/8 64/8 21/8 0a/8 00/8 -- cgit v1.2.3