[PATCH 02/28] aarch64: Check profile for non-alias opcodes
Alice Carlotti
alice.carlotti@arm.com
Wed Nov 4 18:41:27 GMT 2026
For alias opcodes, we already check whether the opcode is available only
in the wrong profile (A-profile vs. R-profile). Add the check for
non-alias opcodes as well.
Additionally, replace gotos in aarch64_opcode_decode with immediate
returns.
diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index 4d5fcc5a5645e533ce932cbb98582b68d765250d..efadc39ccb01d9421a99545ad918b07e39f18c73 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -3732,11 +3732,18 @@ aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
/* Clear inst. */
memset (inst, '\0', sizeof (aarch64_inst));
+ /* Check for opcodes from the wrong profile (A-profile vs. R-profile). */
+ if (!AARCH64_CPU_HAS_ALL_FEATURES (arch_variant, *opcode->avariant))
+ {
+ DEBUG_TRACE ("skip opcode from wrong profile");
+ return false;
+ }
+
/* Check the base opcode. */
if ((code & opcode->mask) != (opcode->opcode & opcode->mask))
{
DEBUG_TRACE ("base opcode match FAIL");
- goto decode_fail;
+ return false;
}
inst->opcode = opcode;
@@ -3756,7 +3763,7 @@ aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
if (opcode_has_special_coder (opcode) && do_special_decoding (inst) == 0)
{
DEBUG_TRACE ("opcode flag-based decoder FAIL");
- goto decode_fail;
+ return false;
}
/* Possibly use the instruction class to determine the correct
@@ -3764,7 +3771,7 @@ aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
if (!aarch64_decode_variant_using_iclass (inst))
{
DEBUG_TRACE ("iclass-based decoder FAIL");
- goto decode_fail;
+ return false;
}
/* Call operand decoders. */
@@ -3782,7 +3789,7 @@ aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
errors)))
{
DEBUG_TRACE ("operand decoder FAIL at operand %d", i);
- goto decode_fail;
+ return false;
}
}
@@ -3791,29 +3798,26 @@ aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
&& opcode->verifier (inst, code, 0, false, errors, NULL) != ERR_OK)
{
DEBUG_TRACE ("operand verifier FAIL");
- goto decode_fail;
+ return false;
}
/* Match the qualifiers. */
- if (aarch64_match_operands_constraint (inst, NULL) == 1)
- {
- /* Arriving here, the CODE has been determined as a valid instruction
- of OPCODE and *INST has been filled with information of this OPCODE
- instruction. Before the return, check if the instruction has any
- alias and should be disassembled in the form of its alias instead.
- If the answer is yes, *INST will be updated. */
- if (!noaliases_p)
- determine_disassembling_preference (inst, errors);
- DEBUG_TRACE ("SUCCESS");
- return true;
- }
- else
+ if (aarch64_match_operands_constraint (inst, NULL) != 1)
{
DEBUG_TRACE ("constraint matching FAIL");
+ return false;
}
- decode_fail:
- return false;
+ /* Arriving here, the CODE has been determined as a valid instruction
+ of OPCODE and *INST has been filled with information of this OPCODE
+ instruction. Before the return, check if the instruction has any
+ alias and should be disassembled in the form of its alias instead.
+ If the answer is yes, *INST will be updated. */
+ if (!noaliases_p)
+ determine_disassembling_preference (inst, errors);
+
+ DEBUG_TRACE ("SUCCESS");
+ return true;
}
/* This does some user-friendly fix-up to *INST. It is currently focus on
More information about the Binutils
mailing list