git.s-ol.nu subv / dd0f115
examples: exit via SBI s-ol 20 days ago
3 changed file(s) with 76 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
44
55 ::
66
7 $ <hello_world.subv ./validate.py | ./survey.py | ./format.py | ./pack.py | ./elf.py >hello_world.elf
8 $ ./qemu.sh hello_world.elf
7 $ <examples/hello_world.subv ./validate.py | ./survey.py | ./format.py | ./pack.py | ./elf.py >examples/hello_world.elf
8 $ ./qemu.sh examples/hello_world.elf
99
1010 Pipeline
1111 --------
2020
2121 and now front to back with a little example::
2222
23 $ ./validate.py <ex.subv >ex.valid
24 $ ./survey.py <ex.valid >ex.survey
25 $ ./format.py <ex.survey >ex.format
26 $ ./pack.py <ex.format >ex.pack
27 $ ./elf.py <ex.pack >ex.elf
23 $ ./validate.py <examples/ex.subv >examples/ex.valid
24 $ ./survey.py <examples/ex.valid >examples/ex.survey
25 $ ./format.py <examples/ex.survey >examples/ex.format
26 $ ./pack.py <examples/ex.format >examples/ex.pack
27 $ ./elf.py <examples/ex.pack >examples/ex.elf
2828 $ ./qemu.sh ex.elf
2929
3030 ``ex.subv``: hand-writable::
3131
32 == code 0x80000000
33 # repeatedly print "Hi\n"
34 main:
35 # load 0x10010000 (UART0) into t0
36 37/lui 5/rd/t0 0x10010/imm20
37 # store 0x48 (H) in UART0+0
38 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12
39 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
40 # store 0x69 (i) in UART0+0
41 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12
42 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
43 # store 0x0a (\n) in UART0+0
44 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12
45 23/store 2/width/word 5/rs/t0 6/rs/t1 0/off12
46 # jump back up to the top
47 6f/jal 0/rd/x0 main/off21
32 == code 0x80400000
33 # repeatedly print "Hi\n"
34 main:
35 # load 0x10000000 (UART0) into t0
36 37/lui 5/rd/t0 10000/imm20
37 # store 0x48 (H) in UART0+0
38 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12
39 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
40 # store 0x69 (i) in UART0+0
41 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12
42 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
43 # store 0x0a (\n) in UART0+0
44 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12
45 23/store 0/width/byte 5/rs/t0 0/off12 6/rs/t1
46 # jump back up to the top
47 6f/jal 0/rd/x0 main/off21
4848
4949 ``ex.valid``: mnemonics validated and discarded::
5050
51 == code 0x80000000
52 # repeatedly print "Hi\n"
53 main:
54 # load 0x10010000 (UART0) into t0
55 37/u 5/rd 10010/imm20
56 # store 0x48 (H) in UART0+0
57 13/i 6/rd 0/funct3 0/rs 48/imm12
58 23/s 5/rs1 0/imm12 2/funct3 6/rs2
59 # store 0x69 (i) in UART0+0
60 13/i 6/rd 0/funct3 0/rs 69/imm12
61 23/s 5/rs1 0/imm12 2/funct3 6/rs2
62 # store 0x0a (\n) in UART0+0
63 13/i 6/rd 0/funct3 0/rs a/imm12
64 23/s 5/rs1 0/imm12 2/funct3 6/rs2
65 # jump back up to the top
66 6f/j 0/rd main/off21
51 == code 0x80400000
52 # repeatedly print "Hi\n"
53 main:
54 # load 0x10000000 (UART0) into t0
55 37/u 5/rd 10000/imm20
56 # store 0x48 (H) in UART0+0
57 13/i 6/rd 0/funct3 0/rs 48/imm12
58 23/s 0/funct3 5/rs1 0/imm12 6/rs2
59 # store 0x69 (i) in UART0+0
60 13/i 6/rd 0/funct3 0/rs 69/imm12
61 23/s 0/funct3 5/rs1 0/imm12 6/rs2
62 # store 0x0a (\n) in UART0+0
63 13/i 6/rd 0/funct3 0/rs a/imm12
64 23/s 0/funct3 5/rs1 0/imm12 6/rs2
65 # jump back up to the top
66 6f/j 0/rd main/off21
6767
6868 ``ex.survey``: references resolved and labels removed::
6969
70 == code 0x80000000
71 # repeatedly print "Hi\n"
72 # main:
73 # load 0x10010000 (UART0) into t0
74 37/u 5/rd 10010/imm20
75 # store 0x48 (H) in UART0+0
76 13/i 6/rd 0/funct3 0/rs 48/imm12
77 23/s 5/rs1 0/imm12 2/funct3 6/rs2
78 # store 0x69 (i) in UART0+0
79 13/i 6/rd 0/funct3 0/rs 69/imm12
80 23/s 5/rs1 0/imm12 2/funct3 6/rs2
81 # store 0x0a (\n) in UART0+0
82 13/i 6/rd 0/funct3 0/rs a/imm12
83 23/s 5/rs1 0/imm12 2/funct3 6/rs2
84 # jump back up to the top
85 6f/j 0/rd -1c/imm21
70 == code 0x80400000
71 # repeatedly print "Hi\n"
72 # main:
73 # load 0x10000000 (UART0) into t0
74 37/u 5/rd 10000/imm20
75 # store 0x48 (H) in UART0+0
76 13/i 6/rd 0/funct3 0/rs 48/imm12
77 23/s 0/funct3 5/rs1 0/imm12 6/rs2
78 # store 0x69 (i) in UART0+0
79 13/i 6/rd 0/funct3 0/rs 69/imm12
80 23/s 0/funct3 5/rs1 0/imm12 6/rs2
81 # store 0x0a (\n) in UART0+0
82 13/i 6/rd 0/funct3 0/rs a/imm12
83 23/s 0/funct3 5/rs1 0/imm12 6/rs2
84 # jump back up to the top
85 6f/j 0/rd -1c/imm21
8686
8787 ``ex.format``: arguments sliced and diced and put into the ISA order::
8888
4141 13/opi a/rd/a0 0/subop/add a/rs/a0 NICETOMEETU/imm12lo
4242 6f/jal 1/rd/ra print/off21
4343
44 # infinite loop
45 6f/jal 0/rd/x0 0/off21
44 exit:
45 # system reset (via SBI extension SRST)
46 # a7 = ext id, a6 = fid, a0 = 0, a1 = 0
47 37/lui 11/rd/a7 53525/imm20
48 13/opi 11/rd/a7 0/subop/add 11/rs/a7 354/imm12
49 33/opr 0/mode/norm 10/rd/a6 0/subop/add 0/rs/x0 0/rs/x0
50 33/opr 0/mode/norm a/rd/a0 0/subop/add 0/rs/x0 0/rs/x0
51 33/opr 0/mode/norm b/rd/a1 0/subop/add 0/rs/x0 0/rs/x0
52 # ECALL
53 73/system 0/subop/priv 0/funct12/ecall
4654
4755 init:
4856 # initialize UART0
1010 13/opi a/rd/a0 0/subop/add a/rs/a0 Message/imm12lo
1111 # call print
1212 6f/jal 1/rd/ra print/off21
13 loop:
14 # infinite loop
15 6f/jal 0/rd/x0 main/off21
13
14 exit:
15 # system reset (via SBI extension SRST)
16 # a7 = ext id, a6 = fid, a0 = 0, a1 = 0
17 37/lui 11/rd/a7 53525/imm20
18 13/opi 11/rd/a7 0/subop/add 11/rs/a7 354/imm12
19 33/opr 0/mode/norm 10/rd/a6 0/subop/add 0/rs/x0 0/rs/x0
20 33/opr 0/mode/norm a/rd/a0 0/subop/add 0/rs/x0 0/rs/x0
21 33/opr 0/mode/norm b/rd/a1 0/subop/add 0/rs/x0 0/rs/x0
22 # ECALL
23 73/system 0/subop/priv 0/funct12/ecall
1624
1725 print:
1826 # load 0x10000000 (UART0) into t0