git.s-ol.nu subv / a9192c6
remove 0x prefix s-ol 20 days ago
5 changed file(s) with 13 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
113113 read:
114114 # read a C-string into a0
115115 # load 0x10000000 (UART0) into t0
116 37/lui 5/rd/t0 0x10000/imm20
116 37/lui 5/rd/t0 10000/imm20
117117 # load 0x0a (\n) into t1
118118 13/opi 6/rd/t1 0/subop/add 0/rs/x0 0a/imm12
119119
1616
1717 print:
1818 # load 0x10000000 (UART0) into t0
19 37/lui 5/rd/t0 0x10000/imm20
19 37/lui 5/rd/t0 10000/imm20
2020 print:loop:
2121 # load unsigned byte at a0
2222 03/load 6/rd/t1 4/width/bu a/rs/a0 0/imm12
11 import bits
22
33 white = re.compile(r"[ \t\.\n]+")
4 hex = re.compile(r"^\-?(0x)?[0-9a-f]+$")
4 hex = re.compile(r"^\-?[0-9a-f]+$")
55 num = re.compile(r"^\d+$")
66 ref_re = re.compile(r"^([^\[+-]+)(?:([+-]\d+))?$")
77 immediate_re = re.compile(r"^(imm|off|csr)(\d+)(hi|lo)?$")
1515 (0,)
1616 >>> parse_part('00')
1717 (0,)
18 >>> parse_part('0x00')
19 (0,)
2018
2119 >>> parse_part('12')
2220 (18,)
23 >>> parse_part('0x12')
24 (18,)
2521
2622 >>> parse_part('-12')
27 (-18,)
28 >>> parse_part('-0x12')
2923 (-18,)
3024
3125 >>> parse_part('00/with/tag')
3226 (0, 'with', 'tag')
3327 >>> parse_part('-12/and/tag')
3428 (-18, 'and', 'tag')
29 >>> parse_part('cafe/and/tag')
30 (51966, 'and', 'tag')
3531
3632 >>> parse_part('label/tag*')
3733 ('label', 'tag*')
6060 ... # repeatedly print "Hi\\\\n"
6161 ... main:
6262 ... # load 0x10010000 (UART0) into t0
63 ... 37/u 5/rd/t0 0x10010/imm20
63 ... 37/u 5/rd/t0 10010/imm20
6464 ... # store 0x48 (H) in UART0+0
6565 ... 13/i 0/subop/add 6/rd/t1 0/rs/x0 48/imm12
6666 ... 23/s 2/subop/word 5/rs/t0 6/rs/t1 0/off12
99 ... == code 0x80000000
1010 ... main:
1111 ... # load 0x10010000 (UART0) into t0
12 ... 37/lui 5/rd/t0 0x10010/imm20
12 ... 37/lui 5/rd/t0 10010/imm20
1313 ... # store 0x48 (H) in UART0+0
1414 ... 13/opi 6/rd/t1 0/subop/add 0/rs/x0 48/imm12
1515 ... 23/store 2/width/word 5/rs/t0 0/off12 6/rs/t1
346346 ]
347347
348348
349 def validate_csr(inputs):
349 def validate_system(inputs):
350350 """
351351 validate system operations.
352352
353 >>> validate_csr(subv.parse('73/system 0/dest/x0 1/subop/csrrw 5/rs/t0 afe/csr12')['instr'])
353 >>> validate_system(subv.parse('73/system 0/dest/x0 1/subop/csrrw 5/rs/t0 afe/csr12')['instr'])
354354 [(115, 'i'), (0, 'rd'), (1, 'funct3'), (5, 'rs'), (2814, 'imm12')]
355 >>> validate_csr(subv.parse('73/system 0/dest/x0 5/subop/csrrwi 7/imm5 afe/csr12')['instr'])
355 >>> validate_system(subv.parse('73/system 0/dest/x0 5/subop/csrrwi 7/imm5 afe/csr12')['instr'])
356356 [(115, 'i'), (0, 'rd'), (5, 'funct3'), (7, 'imm5'), (2814, 'imm12')]
357357
358 >>> validate_csr(subv.parse('73/system 0/dest/x0 1/subop/csrrw 7/imm5 afe/csr12')['instr'])
358 >>> validate_system(subv.parse('73/system 0/dest/x0 1/subop/csrrw 7/imm5 afe/csr12')['instr'])
359359 Traceback (most recent call last):
360360 ...
361361 ValueError: Expected a register with label rs/rs1/src
362 >>> validate_csr(subv.parse('73/system 0/dest/x0 5/subop/csrrwi 5/rs/t0 afe/csr12')['instr'])
362 >>> validate_system(subv.parse('73/system 0/dest/x0 5/subop/csrrwi 5/rs/t0 afe/csr12')['instr'])
363363 Traceback (most recent call last):
364364 ...
365365 ValueError: Expected an immediate with size 5
479479 "opr": (validate_opr, 0x33),
480480 "opi": (validate_i, 0x13),
481481 "jalr": (validate_jalr, 0x67),
482 "system": (validate_csr, 0x73),
482 "system": (validate_system, 0x73),
483483 "load": (validate_load, 0x03),
484484 "store": (validate_store, 0x23),
485485 "branch": (validate_branch, 0x63),