diff --git a/README.rst b/README.rst index ed8ddd2..23da8ec 100644 --- a/README.rst +++ b/README.rst @@ -5,8 +5,8 @@ :: - $ hello_world.elf - $ ./qemu.sh hello_world.elf + $ examples/hello_world.elf + $ ./qemu.sh examples/hello_world.elf Pipeline -------- @@ -21,69 +21,69 @@ and now front to back with a little example:: - $ ./validate.py ex.valid - $ ./survey.py ex.survey - $ ./format.py ex.format - $ ./pack.py ex.pack - $ ./elf.py ex.elf + $ ./validate.py examples/ex.valid + $ ./survey.py examples/ex.survey + $ ./format.py examples/ex.format + $ ./pack.py examples/ex.pack + $ ./elf.py 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 @@ 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 @@ 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