From 5b5c5ed856ff453f04cebbb4b3daace1329d53e7 Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Sun, 6 Apr 2025 22:17:55 +0800 Subject: [PATCH] Fix nanomips decoding of jalrc (#2672) --- arch/Mips/MipsDisassembler.c | 8 ++++---- tests/issues/issues.yaml | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/Mips/MipsDisassembler.c b/arch/Mips/MipsDisassembler.c index 683c1f06..d83fb0dd 100644 --- a/arch/Mips/MipsDisassembler.c +++ b/arch/Mips/MipsDisassembler.c @@ -1498,7 +1498,9 @@ static DecodeStatus getInstruction(MCInst *Instr, uint64_t *Size, const uint8_t Result = readInstruction16(Bytes, BytesLen, Address, Size, &Insn, IsBigEndian); if (Result != MCDisassembler_Fail) { - Result = decodeInstruction_2(DecoderTableNanoMips_Conflict_Space16, + // Calling the auto-generated decoder function for NanoMips + // 16-bit instructions. + Result = decodeInstruction_2(DecoderTableNanoMips16, Instr, Insn, Address, NULL); if (Result != MCDisassembler_Fail) { @@ -1506,9 +1508,7 @@ static DecodeStatus getInstruction(MCInst *Instr, uint64_t *Size, const uint8_t return Result; } - // Calling the auto-generated decoder function for NanoMips - // 16-bit instructions. - Result = decodeInstruction_2(DecoderTableNanoMips16, + Result = decodeInstruction_2(DecoderTableNanoMips_Conflict_Space16, Instr, Insn, Address, NULL); if (Result != MCDisassembler_Fail) { diff --git a/tests/issues/issues.yaml b/tests/issues/issues.yaml index 0aefd77d..aa60142f 100644 --- a/tests/issues/issues.yaml +++ b/tests/issues/issues.yaml @@ -6092,4 +6092,12 @@ test_cases: - asm_text: "bgezc $v1, 4" - asm_text: "bltzc $v1, 8" - + - input: + name: "Test nanomips jalrc rd rt is not beqc rd rt 0" + bytes: [ 0xd9, 0x90 ] + arch: "CS_ARCH_MIPS" + options: [ CS_MODE_NANOMIPS, CS_MODE_BIG_ENDIAN ] + address: 0x0 + expected: + insns: + - asm_text: "jalrc $ra, $t0"