diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-05-27 09:54:05 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2021-06-08 14:01:39 +0000 |
| commit | 848e84b0948e3cf60cd118e3d2f507f20920e06c (patch) | |
| tree | 4bd869f57284425a94b7b711a27c4c230d77d424 | |
| parent | apply "black" formatting (diff) | |
| download | subv-848e84b0948e3cf60cd118e3d2f507f20920e06c.tar.gz subv-848e84b0948e3cf60cd118e3d2f507f20920e06c.zip | |
fix jalr immediate slice, update example stage results
| -rwxr-xr-x | elf.py | 7 | ||||
| -rw-r--r-- | ex.elf | bin | 8228 -> 8228 bytes | |||
| -rw-r--r-- | ex.format | 23 | ||||
| -rw-r--r-- | ex.pack | 16 | ||||
| -rw-r--r-- | ex.survey | 16 | ||||
| -rwxr-xr-x | format.py | 5 | ||||
| -rwxr-xr-x | survey.py | 13 |
7 files changed, 62 insertions, 18 deletions
@@ -91,16 +91,17 @@ def elf(iter): segments = [] segment = None for _, line in iter: - if line["type"] == "segment": + type = line["type"] + if type == "segment": (name, addr) = line["segment"] segment = {"name": name, "addr": addr, "content": []} segments.append(segment) - elif line["type"] == "instr": + elif type == "instr": if segment == None: raise ValueError("label or code outside of segment!") segment["content"] += line["instr"] - else: + elif type != "empty": raise ValueError("elf input should contain only segments and data!") c = write_elf_header(segments) Binary files differ@@ -4,13 +4,20 @@ main: # load 0x10010000 (UART0) into t0 37/7 05/5 10010/20 # store 0x48 (H) in UART0+0 -13/7 06/5 00/3 00/5 48/12 -23/7 00/5 02/3 05/5 06/5 00/7 +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 00/3 00/5 69/12 -23/7 00/5 02/3 05/5 06/5 00/7 +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 00/3 00/5 0a/12 -23/7 00/5 02/3 05/5 06/5 00/7 -# jump back up to the top -6f/7 00/5 main/8/off21>>12 main/1/off21>>11 main/10/off21>>1 main/1/off21>>20 +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 (three versions): +# a) jal 21bit relative (with 0th bit forced to 0) +# 6f/jal 0/rd/x0 main/off21 +# b) auipc+jalr 32bit relative (note label offset) +17/7 07/5 main/off32/[31:12] +67/7 00/5 0/3 07/5 main+4/off32/[11:0] +# c) lui+jalr 32bit absolute +# 37/lui 7/rd/t2 main/imm32 +# 67/jalr 0/subop 0/rd/x0 7/rs/t2 main/imm32 @@ -1,9 +1,23 @@ == 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 -6f f0 5f fe +# jump back up to the top (three versions): +# a) jal 21bit relative (with 0th bit forced to 0) +# 6f/jal 0/rd/x0 main/off21 +# b) auipc+jalr 32bit relative (note label offset) +97 f3 ff ff +67 80 43 fe +# c) lui+jalr 32bit absolute +# 37/lui 7/rd/t2 main/imm32 +# 67/jalr 0/subop 0/rd/x0 7/rs/t2 main/imm32 @@ -1,9 +1,23 @@ == 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 00/3 00/5 48/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x69 (i) in UART0+0 13/7 06/5 00/3 00/5 69/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x0a (\n) in UART0+0 13/7 06/5 00/3 00/5 0a/12 23/7 00/5 02/3 05/5 06/5 00/7 -6f/7 00/5 ff/8 01/1 3f2/10 01/1 +# jump back up to the top (three versions): +# a) jal 21bit relative (with 0th bit forced to 0) +# 6f/jal 0/rd/x0 main/off21 +# b) auipc+jalr 32bit relative (note label offset) +17/7 07/5 fffff/20 +67/7 00/5 00/3 07/5 fe4/12 +# c) lui+jalr 32bit absolute +# 37/lui 7/rd/t2 main/imm32 +# 67/jalr 0/subop 0/rd/x0 7/rs/t2 main/imm32 @@ -148,10 +148,7 @@ def pack_i(instr): rd = bits.u(subv.untag(rd, "rd"), 5) rs = bits.u(subv.untag(rs, "rs"), 5) if subv.is_reference(imm): - if op_tag == "jalr": - imm = bits.ref(imm, slice(12, 1)) - else: - imm = bits.ref(imm, slice(11, 0)) + imm = bits.ref(imm, slice(11, 0)) else: imm = bits.i(subv.untag(imm, "imm12"), 12) @@ -31,19 +31,28 @@ Resolves label references and substitutes them with literal values. ... 6f/7 00/5 main/off21/[19:12] main/off21/[11:11] main/off21/[10:1] main/off21/[20:20] ... '''[1:-1])))) == code 0x80000000 +# main: +# load 0x10010000 (UART0) into t0 37/7 05/5 10010/20 +# store 0x48 (H) in UART0+0 13/7 06/5 00/3 00/5 48/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x65 (e) in UART0+0 13/7 06/5 00/3 00/5 65/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x6c (l) in UART0+0 13/7 06/5 00/3 00/5 6c/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x6c (l) in UART0+0 13/7 06/5 00/3 00/5 6c/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x6f (o) in UART0+0 13/7 06/5 00/3 00/5 6f/12 23/7 00/5 02/3 05/5 06/5 00/7 +# store 0x0a (\\n) in UART0+0 13/7 06/5 00/3 00/5 0a/12 23/7 00/5 02/3 05/5 06/5 00/7 +# jump back up to the top 6f/7 00/5 ff/8 1/1 3e6/10 1/1 """ import subv @@ -151,7 +160,9 @@ def survey(iter): instr.append(observed) line[type] = instr yield subv.format(line) - elif type == "segment": + elif type == "label": + yield "# {}".format(line["raw"]) + else: yield line["raw"] except Exception as e: msg = "failed to survey line" |
