From 3e4920f5d951f547d9a9a5fe353e64999da5133e Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Sat, 5 Jun 2021 15:24:40 +0200 Subject: [PATCH] [decoder] fixed bug when decoding add/sub instruction --- riscemu/decoder/decoder.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/riscemu/decoder/decoder.py b/riscemu/decoder/decoder.py index 5b198ad..9219055 100644 --- a/riscemu/decoder/decoder.py +++ b/riscemu/decoder/decoder.py @@ -39,16 +39,16 @@ def name_from_insn(ins: int): if isinstance(dec, str): return dec - fun = funct3(ins) - if fun not in dec: + fun3 = funct3(ins) + if fun3 not in dec: print_ins(ins) - raise RuntimeError(f"Invalid funct3: {fun:0x} in insn {ins:x}") + raise RuntimeError(f"Invalid funct3: {fun3:0x} in insn {ins:x}") - dec = dec[fun] + dec = dec[fun3] if isinstance(dec, str): return dec - if opcode == 0x1c and fun == 0: + if opcode == 0x1c and fun3 == 0: # we have ecall/ebreak token = imm110(ins) if token in dec: @@ -56,17 +56,13 @@ def name_from_insn(ins: int): print_ins(ins) raise RuntimeError(f"Invalid instruction in ebreak/ecall region: {ins:x}") - fun = funct7(ins) - if fun in dec: - if opcode == 0x0C or (opcode == 0x04 and fun == 5): - mode = imm110(ins) - dec = dec[fun] - if mode in dec: - return dec[mode] - print_ins(ins) - raise RuntimeError("Unknown instruction!") - - return dec[fun] + fun7 = funct7(ins) + if fun7 in dec: + if opcode == 0x0C or (opcode == 0x04 and fun3 == 5): + dec = dec[fun7] + return dec + print("unknown instruction?!") + return dec[fun7] print_ins(ins) raise RuntimeError(f"Invalid instruction: {ins:x}")