2022-01-05 10:09:07 +00:00
|
|
|
bitmap_txt = """
|
|
|
|
0 0000 mmss load
|
|
|
|
0 0001 mmss store
|
|
|
|
0 0010 mmss push
|
|
|
|
0 0011 mmss pop
|
|
|
|
0 1ccc ttss compare
|
2022-01-20 05:55:29 +00:00
|
|
|
0 0000 00nn
|
2022-01-21 09:44:51 +00:00
|
|
|
0 0000 0000 noop
|
|
|
|
0 0000 0001 adjstk
|
|
|
|
0 0000 0010 constant
|
2022-02-06 03:20:17 +00:00
|
|
|
0 1011 otss udivops
|
2022-02-02 05:47:36 +00:00
|
|
|
0 1111 s0mm load64
|
|
|
|
0 1111 s1mm store64
|
|
|
|
0 1111 n000
|
2022-01-16 05:22:04 +00:00
|
|
|
|
2022-01-05 10:09:07 +00:00
|
|
|
1 0ooo ttss mathops
|
|
|
|
1 011r tuss shiftops
|
|
|
|
1 0110 o1oo string
|
|
|
|
1 1ccc t0ss compare2
|
2022-01-16 05:22:04 +00:00
|
|
|
1 1t00 ooss bitops
|
|
|
|
1 1001 01mm jump
|
|
|
|
1 1001 11mm call (return specified st->c)
|
|
|
|
1 1001 1100 return (size in st->c)
|
|
|
|
1 1010 t1ss scale
|
|
|
|
1 1010 t100 swizzle
|
|
|
|
1 1011 tooo vecops
|
2022-01-05 10:09:07 +00:00
|
|
|
1 1101 01oo move
|
|
|
|
1 1101 11oo memset
|
2022-01-16 10:32:47 +00:00
|
|
|
1 1101 c111 statef
|
2022-01-16 05:22:04 +00:00
|
|
|
1 1110 c1cc branch
|
2022-01-16 10:32:47 +00:00
|
|
|
1 1110 c111 stated
|
2022-01-16 05:22:04 +00:00
|
|
|
1 1111 00mm lea
|
|
|
|
1 1111 01td vecops2
|
2022-02-06 10:40:16 +00:00
|
|
|
1 1111 10oo fbitops
|
2022-01-16 10:32:47 +00:00
|
|
|
1 1111 1100 convert (conversion mode in st->b)
|
|
|
|
1 1111 1101 with (mode in st->a, value in st->b, reg in st->c)
|
|
|
|
1 1111 1110
|
2022-01-16 05:22:04 +00:00
|
|
|
1 1111 1111 hops
|
2022-01-05 10:09:07 +00:00
|
|
|
"""
|
|
|
|
|
2022-01-08 16:04:51 +00:00
|
|
|
import copy
|
|
|
|
|
2022-01-20 05:55:29 +00:00
|
|
|
address_mode = "ABCD"
|
|
|
|
address_types = [
|
|
|
|
"ev_void, ev_invalid",
|
|
|
|
"ev_entity, ev_field",
|
|
|
|
"ev_ptr, ev_short",
|
|
|
|
"ev_ptr, ev_int",
|
|
|
|
]
|
2022-01-20 07:33:04 +00:00
|
|
|
address_widths = [
|
|
|
|
[ "1, 0", "1, 1", "1, 0", "1, 1", ],
|
|
|
|
[ "2, 0", "1, 1", "1, 0", "1, 1", ],
|
|
|
|
[ "3, 0", "1, 1", "1, 0", "1, 1", ],
|
|
|
|
[ "4, 0", "1, 1", "1, 0", "1, 1", ],
|
|
|
|
[ "-1, 0", "1, 1", "1, 0", "1, 1", ],
|
|
|
|
]
|
2022-01-20 05:55:29 +00:00
|
|
|
#store, pop and lea
|
|
|
|
store_fmt = [
|
|
|
|
"%ga",
|
|
|
|
"%Ga.%Gb(%Ea)",
|
|
|
|
"*(%Ga + %sb)",
|
|
|
|
"*(%Ga + %Gb)",
|
|
|
|
]
|
|
|
|
# load and push
|
2022-01-06 02:51:38 +00:00
|
|
|
load_fmt = [
|
|
|
|
"*%Ga, %gc",
|
2022-01-20 05:55:29 +00:00
|
|
|
"%Ga.%Gb(%Ea)",
|
|
|
|
"*(%Ga + %sb)",
|
|
|
|
"*(%Ga + %Gb)",
|
2022-01-06 02:51:38 +00:00
|
|
|
]
|
|
|
|
branch_fmt = [
|
2022-01-06 13:27:09 +00:00
|
|
|
"branch %sa (%Oa)",
|
2022-01-05 10:09:07 +00:00
|
|
|
"*%Ga",
|
|
|
|
"%Ga[%sb]",
|
|
|
|
"%Ga[%Gb]",
|
|
|
|
]
|
2022-01-05 13:33:59 +00:00
|
|
|
compare_ccc = [ "eq", "lt", "gt", None, "ne", "ge", "le", None]
|
|
|
|
type_tt = ['I', 'F', 'L', 'D']
|
2022-01-18 04:21:06 +00:00
|
|
|
etype_tt = ["ev_int", "ev_float", "ev_long", "ev_double"]
|
|
|
|
unsigned_t = ["ev_uint", "ev_ulong"]
|
2022-01-05 13:33:59 +00:00
|
|
|
float_t = ["ev_float", "ev_double"]
|
2022-01-06 02:51:38 +00:00
|
|
|
|
2022-01-21 09:44:51 +00:00
|
|
|
adjstk_formats = {
|
|
|
|
"opcode": "OP_ADJSTK",
|
|
|
|
"mnemonic": "adjstk",
|
|
|
|
"opname": "adjstk",
|
|
|
|
"format": "%sa, %sb",
|
|
|
|
"widths": "0, 0, 0",
|
|
|
|
"types": "ev_short, ev_short, ev_invalid",
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
bitops_formats = {
|
2022-01-13 05:24:11 +00:00
|
|
|
"opcode": "OP_{op_bit[oo].upper()}_{bit_type[t]}_{ss+1}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"mnemonic": "{op_bit[oo]}",
|
|
|
|
"opname": "{op_bit[oo]}",
|
|
|
|
"format": "{bit_fmt[oo]}",
|
2022-01-27 01:21:48 +00:00
|
|
|
"widths": "{ss+1}, { oo < 3 and ss+1 or 0}, {ss+1}",
|
|
|
|
"types": "{bit_types[t]}, {oo < 3 and bit_types[t] or 'ev_invalid'}, {bit_types[t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-07 12:48:02 +00:00
|
|
|
"op_bit": ["bitand", "bitor", "bitxor", "bitnot"],
|
2022-01-13 05:24:11 +00:00
|
|
|
"bit_type": ["I", "L"],
|
2022-01-18 04:21:06 +00:00
|
|
|
"bit_types": ["ev_int", "ev_long"],
|
2022-01-05 10:09:07 +00:00
|
|
|
"bit_fmt": [
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %gc",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
branch_formats = {
|
2022-01-16 05:22:04 +00:00
|
|
|
"opcode": "OP_{op_cond[c*4+cc].upper()}",
|
|
|
|
"mnemonic": "{op_cond[c*4+cc]}",
|
|
|
|
"opname": "{op_cond[c*4+cc]}",
|
|
|
|
"format": "{cond_fmt[c*4+cc]}{branch_fmt[0]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "0, 0, 1",
|
2022-01-20 04:02:12 +00:00
|
|
|
"types": "ev_short, ev_invalid, ev_int",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"op_mode": "ABCD",
|
2022-01-16 05:22:04 +00:00
|
|
|
"op_cond": ["ifz", "ifb", "ifa", None,
|
|
|
|
"ifnz", "ifae", "ifbe", None],
|
2022-01-05 10:09:07 +00:00
|
|
|
"branch_fmt": branch_fmt,
|
2022-01-08 16:07:23 +00:00
|
|
|
"cond_fmt": ["%Gc ", "%Gc ", "%Gc ", "", "%Gc ", "%Gc ", "%Gc ", ""],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-10 02:38:21 +00:00
|
|
|
call_formats = {
|
|
|
|
"opcode": "OP_CALL_{op_mode[mm]}",
|
|
|
|
"mnemonic": "call",
|
|
|
|
"opname": "call",
|
|
|
|
"format": "{call_fmt[mm]}",
|
2022-01-21 04:50:21 +00:00
|
|
|
"widths": "{call_widths[mm]}, -1",
|
2022-01-21 01:07:35 +00:00
|
|
|
"types": "{call_types[mm]}, ev_void",
|
2022-01-10 02:38:21 +00:00
|
|
|
"args": {
|
|
|
|
"op_mode": ".BCD",
|
|
|
|
"call_fmt": [
|
|
|
|
None, # return handled seprately
|
|
|
|
"%Ga, %gc",
|
|
|
|
"%Ga[%sb], %gc",
|
|
|
|
"%Ga[%Gb], %gc",
|
|
|
|
],
|
2022-01-21 01:07:35 +00:00
|
|
|
"call_types": [
|
|
|
|
None,
|
|
|
|
"ev_void, ev_invalid",
|
|
|
|
"ev_ptr, ev_short",
|
|
|
|
"ev_ptr, ev_int",
|
|
|
|
],
|
2022-01-20 08:27:56 +00:00
|
|
|
"call_widths": [ None, "1, 0", "1, 0", "1, 1" ]
|
2022-01-10 02:38:21 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
compare_formats = {
|
|
|
|
"opcode": "OP_{op_cmp[ccc].upper()}_{cmp_type[tt]}_{ss+1}",
|
|
|
|
"mnemonic": "{op_cmp[ccc]}.{cmp_type[tt]}",
|
|
|
|
"opname": "{op_cmp[ccc]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, {ss+1}, {ss+1}",
|
2022-01-18 04:21:06 +00:00
|
|
|
"types": "{cmp_types[tt]}, {cmp_types[tt]}, ev_int",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"op_cmp": compare_ccc,
|
2022-01-07 12:48:02 +00:00
|
|
|
"cmp_type": type_tt,
|
|
|
|
"cmp_types": etype_tt,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
compare2_formats = {
|
|
|
|
"opcode": "OP_{op_cmp[ccc].upper()}_{cmp_type[t]}_{ss+1}",
|
|
|
|
"mnemonic": "{op_cmp[ccc]}.{cmp_type[t]}",
|
|
|
|
"opname": "{op_cmp[ccc]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, {ss+1}, {ss+1}",
|
2022-01-18 04:21:06 +00:00
|
|
|
"types": "{cmp_types[t]}, {cmp_types[t]}, ev_int",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"op_cmp": compare_ccc,
|
2022-01-07 12:48:02 +00:00
|
|
|
"cmp_type": ['u', 'U'],
|
|
|
|
"cmp_types": unsigned_t,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-21 09:44:51 +00:00
|
|
|
constant_formats = {
|
|
|
|
"opcode": "OP_LDCONST",
|
|
|
|
"mnemonic": "ldconst",
|
|
|
|
"opname": "ldconst",
|
|
|
|
"format": "%sa, %sb, %gc",
|
|
|
|
"widths": "0, 0, -1",
|
|
|
|
"types": "ev_short, ev_short, ev_void",
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
convert_formats = {
|
2022-01-10 02:53:57 +00:00
|
|
|
"opcode": "OP_CONV",
|
|
|
|
"mnemonic": "conv",
|
2022-01-05 10:09:07 +00:00
|
|
|
"opname": "conv",
|
2022-01-10 02:53:57 +00:00
|
|
|
"format": "%Ga %Cb %gc",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "-1, 0, -1",
|
2022-01-10 02:53:57 +00:00
|
|
|
"types": "ev_void, ev_short, ev_void",
|
2022-01-05 10:09:07 +00:00
|
|
|
}
|
2022-02-06 10:40:16 +00:00
|
|
|
fbitops_formats = {
|
|
|
|
"opcode": "OP_{op_fbit[oo].upper()}_F",
|
|
|
|
"mnemonic": "{op_fbit[oo]}.f",
|
|
|
|
"opname": "{op_fbit[oo]}",
|
|
|
|
"format": "{fbit_fmt[oo]}",
|
|
|
|
"widths": "1, 1, 1",
|
|
|
|
"types": "{fbit_types[0]}, {fbit_types[oo==3]}, {fbit_types[0]}",
|
|
|
|
"args": {
|
|
|
|
"op_fbit": ["bitand", "bitor", "bitxor", "bitnot"],
|
|
|
|
"fbit_types": ["ev_float", "ev_invalid"],
|
|
|
|
"fbit_fmt": [
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %gc",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
2022-01-16 05:22:04 +00:00
|
|
|
hops_formats = {
|
|
|
|
"opcode": "OP_HOPS",
|
|
|
|
"mnemonic": "hops",
|
|
|
|
"opname": "hops",
|
|
|
|
"format": "%Ga %Hb %gc",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "-1, 0, 1",
|
2022-01-16 05:22:04 +00:00
|
|
|
"types": "ev_void, ev_short, ev_void",
|
|
|
|
}
|
|
|
|
jump_formats = {
|
|
|
|
"opcode": "OP_JUMP_{op_mode[mm]}",
|
|
|
|
"mnemonic": "jump",
|
|
|
|
"opname": "jump",
|
2022-01-20 04:02:12 +00:00
|
|
|
"format": "{jump_fmt[mm]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "{jump_widths[mm]}, 0",
|
2022-01-20 04:02:12 +00:00
|
|
|
"types": "{jump_types[mm]}",
|
2022-01-16 05:22:04 +00:00
|
|
|
"args": {
|
|
|
|
"op_mode": "ABCD",
|
2022-01-20 04:02:12 +00:00
|
|
|
"jump_fmt": branch_fmt,
|
|
|
|
"jump_types": [
|
|
|
|
"ev_short, ev_invalid, ev_invalid",
|
2022-01-30 13:34:40 +00:00
|
|
|
"ev_void, ev_int, ev_invalid",
|
2022-01-20 04:02:12 +00:00
|
|
|
"ev_ptr, ev_short, ev_invalid",
|
|
|
|
"ev_ptr, ev_int, ev_invalid",
|
|
|
|
],
|
2022-01-30 13:34:40 +00:00
|
|
|
"jump_widths": [ "0, 0", "1, 1", "1, 0", "1, 1" ]
|
2022-01-16 05:22:04 +00:00
|
|
|
},
|
|
|
|
}
|
2022-02-02 05:47:36 +00:00
|
|
|
load64_formats = {
|
|
|
|
"opcode": "OP_LOAD64_{op_mode[mm]}_{s+3}",
|
|
|
|
"mnemonic": "load64",
|
|
|
|
"opname": "load64",
|
|
|
|
"format": "{load_fmt[mm]}, %gc",
|
|
|
|
"widths": "{load_widths[s+2][mm]}, {s+3}",
|
|
|
|
"types": "{load_types[mm]}, ev_void",
|
|
|
|
"args": {
|
|
|
|
"op_mode": address_mode,
|
|
|
|
"load_fmt": load_fmt,
|
|
|
|
"load_types": address_types,
|
|
|
|
"load_widths": address_widths,
|
|
|
|
},
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
lea_formats = {
|
|
|
|
"opcode": "OP_LEA_{op_mode[mm]}",
|
|
|
|
"mnemonic": "lea",
|
|
|
|
"opname": "lea",
|
2022-01-20 05:55:29 +00:00
|
|
|
"format": "{lea_fmt[mm]}, %gc",
|
2022-01-20 07:33:04 +00:00
|
|
|
"widths": "{lea_widths[mm]}, 1",
|
2022-01-20 05:55:29 +00:00
|
|
|
"types": "{lea_types[mm]}, ev_ptr",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-20 05:55:29 +00:00
|
|
|
"op_mode": address_mode,
|
|
|
|
"lea_fmt": store_fmt,
|
|
|
|
"lea_types": address_types,
|
2022-01-20 07:33:04 +00:00
|
|
|
"lea_widths": address_widths[4],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
load_formats = {
|
|
|
|
"opcode": "OP_LOAD_{op_mode[mm]}_{ss+1}",
|
|
|
|
"mnemonic": "load",
|
|
|
|
"opname": "load",
|
2022-01-20 05:55:29 +00:00
|
|
|
"format": "{load_fmt[mm]}, %gc",
|
2022-01-20 07:33:04 +00:00
|
|
|
"widths": "{load_widths[ss][mm]}, {ss+1}",
|
2022-01-20 05:55:29 +00:00
|
|
|
"types": "{load_types[mm]}, ev_void",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-20 05:55:29 +00:00
|
|
|
"op_mode": address_mode,
|
2022-01-06 02:51:38 +00:00
|
|
|
"load_fmt": load_fmt,
|
2022-01-20 05:55:29 +00:00
|
|
|
"load_types": address_types,
|
2022-01-20 07:33:04 +00:00
|
|
|
"load_widths": address_widths,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
mathops_formats = {
|
|
|
|
"opcode": "OP_{op_math[ooo].upper()}_{math_type[tt]}_{ss+1}",
|
|
|
|
"mnemonic": "{op_math[ooo]}.{math_type[tt]}",
|
|
|
|
"opname": "{op_math[ooo]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, {ss+1}, {ss+1}",
|
|
|
|
"types": "{math_types[tt]}, {math_types[tt]}, {math_types[tt]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"op_math": ["mul", "div", "rem", "mod", "add", "sub", None, None],
|
2022-01-07 12:48:02 +00:00
|
|
|
"math_type": type_tt,
|
2022-01-05 13:33:59 +00:00
|
|
|
"math_types": etype_tt,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
memset_formats = {
|
|
|
|
"opcode": "OP_MEMSET_{op_memset[oo].upper()}",
|
|
|
|
"mnemonic": "memset.{op_memset[oo]}",
|
2022-01-29 08:05:10 +00:00
|
|
|
"opname": "memset{suff_memset[oo]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"format": "{memset_fmt[oo]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "{memset_widths[oo]}",
|
2022-01-26 03:26:12 +00:00
|
|
|
"types": "{memset_types[oo]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-16 05:22:04 +00:00
|
|
|
"op_memset": ["i", "p", "pi", None],
|
2022-01-29 08:05:10 +00:00
|
|
|
"suff_memset": ["", "p", "p", None],
|
2022-01-16 05:22:04 +00:00
|
|
|
"memset_fmt": ["%Ga, %sb, %gc", "%Ga, %Gb, %Gc", "%Ga, %sb, %Gc", None],
|
2022-01-20 08:27:56 +00:00
|
|
|
"memset_widths": [
|
|
|
|
"1, 0, -1",
|
|
|
|
"1, 1, 1",
|
|
|
|
"1, 0, 1",
|
|
|
|
None,
|
|
|
|
],
|
2022-01-26 03:26:12 +00:00
|
|
|
"memset_types": [
|
2022-01-29 08:05:10 +00:00
|
|
|
"ev_int, ev_short, ev_void",
|
|
|
|
"ev_int, ev_int, ev_ptr",
|
|
|
|
"ev_int, ev_short, ev_ptr",
|
2022-01-26 03:26:12 +00:00
|
|
|
],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
move_formats = {
|
|
|
|
"opcode": "OP_MOVE_{op_move[oo].upper()}",
|
2022-01-26 03:26:12 +00:00
|
|
|
"mnemonic": "move.{op_move[oo]}",
|
|
|
|
"opname": "move{suff_move[oo]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"format": "{move_fmt[oo]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "{move_widths[oo]}",
|
2022-01-26 03:26:12 +00:00
|
|
|
"types": "{move_types[oo]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-16 05:22:04 +00:00
|
|
|
"op_move": ["i", "p", "pi", None],
|
2022-01-26 03:26:12 +00:00
|
|
|
"suff_move": ["", "p", "p", None],
|
2022-01-16 05:22:04 +00:00
|
|
|
"move_fmt": ["%Ga, %sb, %gc", "%Ga, %Gb, %Gc", "%Ga, %sb, %Gc", None],
|
2022-01-20 08:27:56 +00:00
|
|
|
"move_widths": [
|
|
|
|
"-1, 0, -1",
|
|
|
|
"1, 1, 1",
|
|
|
|
"1, 0, 1",
|
|
|
|
None,
|
|
|
|
],
|
2022-01-26 03:26:12 +00:00
|
|
|
"move_types": [
|
|
|
|
"ev_void, ev_short, ev_void",
|
|
|
|
"ev_ptr, ev_int, ev_ptr",
|
|
|
|
"ev_ptr, ev_short, ev_ptr",
|
|
|
|
],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-21 09:44:51 +00:00
|
|
|
noop_formats = {
|
|
|
|
"opcode": "OP_NOP",
|
|
|
|
"mnemonic": "nop",
|
|
|
|
"opname": "nop",
|
|
|
|
"format": "there were plums...",
|
|
|
|
"widths": "0, 0, 0",
|
|
|
|
"types": "ev_invalid, ev_invalid, ev_invalid",
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
push_formats = {
|
|
|
|
"opcode": "OP_PUSH_{op_mode[mm]}_{ss+1}",
|
|
|
|
"mnemonic": "push",
|
|
|
|
"opname": "push",
|
|
|
|
"format": "{push_fmt[mm]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, 0, 0",
|
2022-01-20 05:55:29 +00:00
|
|
|
"types": "{push_types[mm]}, ev_invalid",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-20 05:55:29 +00:00
|
|
|
"op_mode": address_mode,
|
|
|
|
"push_fmt": load_fmt,
|
|
|
|
"push_types": address_types,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
pop_formats = {
|
|
|
|
"opcode": "OP_POP_{op_mode[mm]}_{ss+1}",
|
|
|
|
"mnemonic": "pop",
|
|
|
|
"opname": "pop",
|
|
|
|
"format": "{pop_fmt[mm]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, 0, 0",
|
2022-01-20 05:55:29 +00:00
|
|
|
"types": "{pop_types[mm]}, ev_invalid",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-20 05:55:29 +00:00
|
|
|
"op_mode": address_mode,
|
|
|
|
"pop_fmt": store_fmt,
|
|
|
|
"pop_types": address_types,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
scale_formats = {
|
|
|
|
"opcode": "OP_SCALE_{scale_type[t]}_{ss+1}",
|
|
|
|
"mnemonic": "scale.{scale_type[t]}",
|
|
|
|
"opname": "scale",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, 1, {ss+1}",
|
|
|
|
"types": "{scale_types[t]}, {scale_types[t]}, {scale_types[t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-05 13:33:59 +00:00
|
|
|
"scale_type": ['F', 'D'],
|
|
|
|
"scale_types": float_t,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
shiftops_formats = {
|
2022-01-30 13:37:03 +00:00
|
|
|
"opcode": "OP_{mn_shift[u*2+r].upper()}_{shift_type[u*2+t]}_{ss+1}",
|
|
|
|
"mnemonic": "{mn_shift[u*2+r]}.{shift_type[u*2+t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"opname": "{op_shift[u*2+r]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{ss+1}, {ss+1}, {ss+1}",
|
|
|
|
"types": "{shift_types[t][u]}, {shift_types[t][0]}, {shift_types[t][u]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-30 13:37:03 +00:00
|
|
|
"mn_shift": ["shl", "asr", "shl", "shr"],
|
|
|
|
"op_shift": ["shl", "shr", "shl", "shr"],
|
2022-01-05 13:33:59 +00:00
|
|
|
"shift_type": ['I', 'L', 'u', 'U'],
|
|
|
|
"shift_types": [
|
2022-01-18 04:21:06 +00:00
|
|
|
["ev_int", "ev_uint"],
|
2022-01-05 13:33:59 +00:00
|
|
|
["ev_long", "ev_ulong"],
|
|
|
|
],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-16 10:32:47 +00:00
|
|
|
statef_formats = {
|
|
|
|
"opcode": "OP_STATE_{state[c]}",
|
|
|
|
"mnemonic": "state.{state[c]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"opname": "state",
|
2022-01-16 10:32:47 +00:00
|
|
|
"format": "{state_fmt[c]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "1, 1, {c}",
|
2022-01-16 10:32:47 +00:00
|
|
|
"types": "ev_float, ev_func, {state_types[c]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"state": ["ft", "ftt"],
|
|
|
|
"state_fmt": ["%Ga, %Gb", "%Ga, %Gb, %Gc"],
|
2022-01-05 13:33:59 +00:00
|
|
|
"state_types": ["ev_invalid", "ev_float"],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-16 10:32:47 +00:00
|
|
|
stated_formats = {
|
|
|
|
"opcode": "OP_STATE_{state[c]}",
|
|
|
|
"mnemonic": "state.{state[c]}",
|
|
|
|
"opname": "state",
|
|
|
|
"format": "{state_fmt[c]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "1, 1, {c}",
|
2022-01-29 09:48:05 +00:00
|
|
|
"types": "ev_int, ev_func, {state_types[c]}",
|
2022-01-16 10:32:47 +00:00
|
|
|
"args": {
|
|
|
|
"state": ["dt", "dtt"],
|
|
|
|
"state_fmt": ["%Ga, %Gb", "%Ga, %Gb, %Gc"],
|
|
|
|
"state_types": ["ev_invalid", "ev_double"],
|
|
|
|
},
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
store_formats = {
|
|
|
|
"opcode": "OP_STORE_{op_mode[mm]}_{ss+1}",
|
2022-01-20 04:02:12 +00:00
|
|
|
"mnemonic": "{store_op[mm]}",
|
|
|
|
"opname": "{store_op[mm]}",
|
2022-01-20 05:55:29 +00:00
|
|
|
"format": "%Gc, {store_fmt[mm]}",
|
2022-01-20 07:33:04 +00:00
|
|
|
"widths": "{store_widths[ss][mm]}, {ss+1}",
|
2022-01-20 05:55:29 +00:00
|
|
|
"types": "{store_types[mm]}, ev_void",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-20 05:55:29 +00:00
|
|
|
"op_mode": address_mode,
|
|
|
|
"store_fmt": store_fmt,
|
2022-01-20 04:02:12 +00:00
|
|
|
"store_op": ["assign", "store", "store", "store"],
|
2022-01-20 05:55:29 +00:00
|
|
|
"store_types": address_types,
|
2022-01-20 07:33:04 +00:00
|
|
|
"store_widths": address_widths,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-02-02 05:47:36 +00:00
|
|
|
store64_formats = {
|
|
|
|
"opcode": "OP_STORE64_{op_mode[mm]}_{s+3}",
|
|
|
|
"mnemonic": "{store_op[mm]}64",
|
|
|
|
"opname": "{store_op[mm]}64",
|
|
|
|
"format": "%Gc, {store_fmt[mm]}",
|
|
|
|
"widths": "{store_widths[s+2][mm]}, {s+3}",
|
|
|
|
"types": "{store_types[mm]}, ev_void",
|
|
|
|
"args": {
|
|
|
|
"op_mode": address_mode,
|
|
|
|
"store_fmt": store_fmt,
|
|
|
|
"store_op": ["assign", "store", "store", "store"],
|
|
|
|
"store_types": address_types,
|
|
|
|
"store_widths": address_widths,
|
|
|
|
},
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
string_formats = {
|
|
|
|
"opcode": "OP_{op_str[o*4+oo].upper()}_S",
|
|
|
|
"mnemonic": "{op_str[o*4+oo]}.s",
|
|
|
|
"opname": "{op_str[o*4+oo]}",
|
|
|
|
"format": "{str_fmt[o*4+oo]}",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "1, {(o*4+oo)<7 and 1 or 0}, 1",
|
2022-01-05 13:33:59 +00:00
|
|
|
"types": "{str_types[o*4+oo]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
|
|
|
"op_str": ["eq", "lt", "gt", "add", "cmp", "ge", "le", "not"],
|
|
|
|
"str_fmt": [
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %Gb, %gc",
|
|
|
|
"%Ga, %gc",
|
|
|
|
],
|
2022-01-05 13:33:59 +00:00
|
|
|
"str_types": [
|
2022-01-18 04:21:06 +00:00
|
|
|
"ev_string, ev_string, ev_int",
|
|
|
|
"ev_string, ev_string, ev_int",
|
|
|
|
"ev_string, ev_string, ev_int",
|
2022-01-05 13:33:59 +00:00
|
|
|
"ev_string, ev_string, ev_string",
|
2022-01-18 04:21:06 +00:00
|
|
|
"ev_string, ev_string, ev_int",
|
|
|
|
"ev_string, ev_string, ev_int",
|
|
|
|
"ev_string, ev_string, ev_int",
|
|
|
|
"ev_string, ev_invalid, ev_int",
|
2022-01-05 13:33:59 +00:00
|
|
|
],
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
swizzle_formats = {
|
|
|
|
"opcode": "OP_SWIZZLE_{swiz_type[t]}",
|
|
|
|
"mnemonic": "swizzle.{swiz_type[t]}",
|
|
|
|
"opname": "swizzle",
|
|
|
|
"format": "%Ga %sb %gc",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "4, 0, 4",
|
|
|
|
"types": "{swizzle_types[t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-05 13:33:59 +00:00
|
|
|
"swiz_type": ['F', 'D'],
|
|
|
|
"swizzle_types": float_t,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return_formats = {
|
2022-01-10 02:38:21 +00:00
|
|
|
"opcode": "OP_RETURN",
|
2022-01-05 10:09:07 +00:00
|
|
|
"mnemonic": "return",
|
|
|
|
"opname": "return",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "-1, -1, 0", # width specified by st->c
|
2022-01-27 04:29:38 +00:00
|
|
|
"format": "%Mc5",
|
2022-01-10 02:38:21 +00:00
|
|
|
"types": "ev_void, ev_void, ev_void",
|
2022-01-05 10:09:07 +00:00
|
|
|
}
|
2022-02-06 03:20:17 +00:00
|
|
|
udivops_formats = {
|
|
|
|
"opcode": "OP_{op_udiv[o].upper()}_{udiv_type[t]}_{ss+1}",
|
|
|
|
"mnemonic": "{op_udiv[o]}.{udiv_type[t]}",
|
|
|
|
"opname": "{op_udiv[o]}",
|
|
|
|
"widths": "{ss+1}, {ss+1}, {ss+1}",
|
|
|
|
"types": "{udiv_types[t]}, {udiv_types[t]}, {udiv_types[t]}",
|
|
|
|
"args": {
|
|
|
|
"op_udiv": ["div", "rem"],
|
|
|
|
"udiv_type": ['u', 'U'],
|
|
|
|
"udiv_types": ["ev_uint", "ev_ulong"],
|
|
|
|
},
|
|
|
|
}
|
2022-01-05 10:09:07 +00:00
|
|
|
vecops_formats = {
|
|
|
|
"opcode": "OP_{op_vop[ooo].upper()}_{vop_type[t]}",
|
|
|
|
"mnemonic": "{op_vop[ooo]}.{vop_type[t]}",
|
|
|
|
"opname": "{op_vop[ooo]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "{vec_widths[ooo]}",
|
|
|
|
"types": "{vec_types[t]}, {vec_types[t]}, {vec_types[t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-10 02:16:55 +00:00
|
|
|
"op_vop": ["cross", "cdot", "vdot", "qdot",
|
2022-01-05 10:09:07 +00:00
|
|
|
"cmul", "qvmul", "vqmul", "qmul"],
|
|
|
|
"vop_type": ['F', 'D'],
|
2022-01-05 13:33:59 +00:00
|
|
|
"vec_widths": [
|
2022-01-30 05:11:41 +00:00
|
|
|
"3, 3, 3",
|
2022-01-05 13:33:59 +00:00
|
|
|
"2, 2, 2",
|
|
|
|
"3, 3, 3",
|
|
|
|
"4, 4, 4",
|
|
|
|
"2, 2, 2",
|
|
|
|
"4, 3, 3",
|
|
|
|
"3, 4, 3",
|
|
|
|
"4, 4, 4",
|
|
|
|
],
|
|
|
|
"vec_types": float_t,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
vecops2_formats = {
|
2022-01-16 05:22:04 +00:00
|
|
|
"opcode": "OP_{op_vop[d].upper()}_{vop_type[t]}",
|
|
|
|
"mnemonic": "{op_vop[d]}.{vop_type[t]}",
|
|
|
|
"opname": "{op_vop[d]}",
|
2022-01-05 13:33:59 +00:00
|
|
|
"widths": "4, 4, 4",
|
|
|
|
"types": "{vec_types[t]}, {vec_types[t]}, {vec_types[t]}",
|
2022-01-05 10:09:07 +00:00
|
|
|
"args": {
|
2022-01-16 05:22:04 +00:00
|
|
|
"op_vop": ["qv4mul", "v4qmul"],
|
2022-01-05 10:09:07 +00:00
|
|
|
"vop_type": ['F', 'D'],
|
2022-01-05 13:33:59 +00:00
|
|
|
"vec_types": float_t,
|
2022-01-05 10:09:07 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
with_formats = {
|
|
|
|
"opcode": "OP_WITH",
|
|
|
|
"mnemonic": "with",
|
|
|
|
"opname": "with",
|
2022-01-06 13:27:09 +00:00
|
|
|
"format": "%sa, %sb, %sc",
|
2022-01-20 08:27:56 +00:00
|
|
|
"widths": "0, -1, 0",
|
|
|
|
"types": "ev_short, ev_void, ev_short",
|
2022-01-05 10:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
group_map = {
|
2022-01-21 09:44:51 +00:00
|
|
|
"adjstk": adjstk_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"bitops": bitops_formats,
|
|
|
|
"branch": branch_formats,
|
2022-01-10 02:38:21 +00:00
|
|
|
"call": call_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"compare": compare_formats,
|
|
|
|
"compare2": compare2_formats,
|
2022-01-21 09:44:51 +00:00
|
|
|
"constant": constant_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"convert": convert_formats,
|
2022-02-06 10:40:16 +00:00
|
|
|
"fbitops": fbitops_formats,
|
2022-01-16 05:22:04 +00:00
|
|
|
"hops": hops_formats,
|
|
|
|
"jump": jump_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"lea": lea_formats,
|
|
|
|
"load": load_formats,
|
2022-02-02 05:47:36 +00:00
|
|
|
"load64": load64_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"mathops": mathops_formats,
|
|
|
|
"memset": memset_formats,
|
|
|
|
"move": move_formats,
|
2022-01-21 09:44:51 +00:00
|
|
|
"noop": noop_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"push": push_formats,
|
|
|
|
"pop": pop_formats,
|
|
|
|
"scale": scale_formats,
|
|
|
|
"shiftops": shiftops_formats,
|
2022-01-16 10:32:47 +00:00
|
|
|
"statef": statef_formats,
|
|
|
|
"stated": stated_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"store": store_formats,
|
2022-02-02 05:47:36 +00:00
|
|
|
"store64": store64_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"string": string_formats,
|
|
|
|
"swizzle": swizzle_formats,
|
|
|
|
"return": return_formats,
|
2022-02-06 03:20:17 +00:00
|
|
|
"udivops": udivops_formats,
|
2022-01-05 10:09:07 +00:00
|
|
|
"vecops": vecops_formats,
|
|
|
|
"vecops2": vecops2_formats,
|
|
|
|
"with": with_formats,
|
|
|
|
}
|
|
|
|
|
|
|
|
def parse_bits(bit_string):
|
|
|
|
bits = [""]
|
|
|
|
isbit = bit_string[0] in ['0', '1']
|
|
|
|
lastbit = bit_string[0]
|
|
|
|
while bit_string:
|
|
|
|
bit = bit_string[0]
|
|
|
|
bit_string = bit_string[1:]
|
|
|
|
if isbit and bit in ['0', '1']:
|
|
|
|
bits[-1] = bits[-1] + bit
|
|
|
|
elif lastbit == bit:
|
|
|
|
bits[-1] = bits[-1] + bit
|
|
|
|
else:
|
|
|
|
bits.append(bit)
|
|
|
|
lastbit = bit
|
|
|
|
isbit = bit in ['0', '1']
|
|
|
|
return bits
|
|
|
|
|
|
|
|
opcodes = [None] * 512
|
|
|
|
|
|
|
|
def expand_opcodes(bits, group, num=0):
|
|
|
|
if not bits:
|
|
|
|
opcodes[num] = group
|
|
|
|
return
|
|
|
|
block = bits[0]
|
|
|
|
bits = bits[1:]
|
|
|
|
num <<= len(block)
|
|
|
|
if block[0] in ['0', '1']:
|
|
|
|
num |= int(block, 2)
|
|
|
|
expand_opcodes(bits, group, num)
|
|
|
|
else:
|
|
|
|
for n in range(1<<len(block)):
|
|
|
|
if group is not None:
|
|
|
|
expand_opcodes(bits, group + f",{block}={n}", num | n)
|
|
|
|
else:
|
|
|
|
expand_opcodes(bits, group, num | n)
|
|
|
|
|
|
|
|
|
|
|
|
def process_opcode(opcode, group):
|
|
|
|
data = group.split(',')
|
|
|
|
params = {}
|
|
|
|
for d in data[1:]:
|
|
|
|
p = d.split('=')
|
|
|
|
params[p[0]] = int(p[1])
|
|
|
|
gm = group_map[data[0]]
|
|
|
|
if "args" in gm:
|
|
|
|
params.update(gm["args"])
|
|
|
|
inst = {}
|
|
|
|
opcodes[opcode] = inst
|
2022-01-16 05:22:04 +00:00
|
|
|
#print(f"{opcode:03x}", group)
|
2022-01-05 10:09:07 +00:00
|
|
|
inst["op"] = eval(f'''f"{gm['opcode']}"''', params)
|
|
|
|
mn = eval(f'''f"{gm['mnemonic']}"''', params)
|
|
|
|
inst["mn"] = f'"{mn}"'
|
|
|
|
on = eval(f'''f"{gm['opname']}"''', params)
|
|
|
|
inst["on"] = f'"{on}"'
|
|
|
|
fmt = "%Ga, %Gb, %gc"
|
|
|
|
if "format" in gm:
|
|
|
|
if gm["format"] is not None:
|
|
|
|
fmt = eval(f'''f"{gm['format']}"''', params)
|
|
|
|
else:
|
|
|
|
fmt = None
|
|
|
|
if fmt is None:
|
|
|
|
fmt = "0"
|
|
|
|
else:
|
|
|
|
fmt = f'"{fmt}"'
|
|
|
|
inst["fmt"] = fmt
|
2022-01-05 13:33:59 +00:00
|
|
|
inst["wd"] = "{%s}" % eval(f'''f"{gm['widths']}"''', params)
|
|
|
|
inst["ty"] = "{%s}" % eval(f'''f"{gm['types']}"''', params)
|
2022-01-05 10:09:07 +00:00
|
|
|
|
2022-01-08 16:04:51 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if len (sys.argv) < 2 or sys.argv[1] not in ["enum", "table"]:
|
|
|
|
sys.stderr.write ("specify output type: enum or table\n")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2022-01-05 10:09:07 +00:00
|
|
|
lines = bitmap_txt.split('\n')
|
|
|
|
for l in lines:
|
2022-01-10 02:38:21 +00:00
|
|
|
l = l.strip()
|
|
|
|
if not l or l[0] == '#':
|
2022-01-05 10:09:07 +00:00
|
|
|
continue
|
|
|
|
c = l.split(' ')
|
|
|
|
bits = "".join(c[0:3])
|
|
|
|
group = c[3:] and c[3] or None
|
|
|
|
descr = ' '.join(c[4:])
|
|
|
|
#print(bits, group, descr)
|
|
|
|
#print(parse_bits(bits))
|
|
|
|
expand_opcodes(parse_bits(bits), group)
|
|
|
|
for i, group in enumerate(opcodes):
|
|
|
|
if group is not None:
|
|
|
|
process_opcode (i, group)
|
2022-01-08 16:04:51 +00:00
|
|
|
if sys.argv[1] == "enum":
|
|
|
|
N = 4
|
|
|
|
W = 15
|
|
|
|
for i in range(len(opcodes)//N):
|
|
|
|
row = opcodes[i * N:i * N + N]
|
|
|
|
#row = map(lambda op: (op and op["op"] or f"OP_spare_{i}"), row)
|
|
|
|
row = [(op and op["op"] or f"OP_spare_{i*N+x}")
|
|
|
|
for x, op in enumerate(row)]
|
|
|
|
row = map(lambda op: f"%-{W}.{W}s" % (op + ','), row)
|
|
|
|
if sys.argv[2:3] == ["debug"]:
|
|
|
|
print("%03x" % (i << 3), " ".join(row))
|
|
|
|
else:
|
|
|
|
print(" ".join(row))
|
|
|
|
elif sys.argv[1] == "table":
|
|
|
|
for i, group in enumerate(opcodes):
|
|
|
|
if group is not None:
|
|
|
|
print(eval('f"[{op}] = {{\\n'
|
|
|
|
'\\t.opname = {on},\\n'
|
|
|
|
'\\t.mnemonic = {mn},\\n'
|
|
|
|
'\\t.widths = {wd},\\n'
|
|
|
|
'\\t.types = {ty},\\n'
|
|
|
|
'\\t.fmt = {fmt},\\n'
|
|
|
|
'}},"', group))
|