From: Alice Carlotti Date: Mon, 10 Mar 2025 15:32:11 +0000 (+0000) Subject: aarch64: Add qualifier checks to aarch64-gen X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4355b37ca0864f3670a52ef68a64bf13e1c0cd4f;p=thirdparty%2Fbinutils-gdb.git aarch64: Add qualifier checks to aarch64-gen Add checks to verify that all qualifier sequences have the correct length. --- diff --git a/opcodes/aarch64-gen.c b/opcodes/aarch64-gen.c index 1988879da81..d989c557523 100644 --- a/opcodes/aarch64-gen.c +++ b/opcodes/aarch64-gen.c @@ -150,6 +150,11 @@ read_table (const struct aarch64_opcode* table) { bool match = false; + unsigned int operand_count = 0; + while (operand_count < ARRAY_SIZE (ent->operands) + && ent->operands[operand_count] != AARCH64_OPND_NIL) + operand_count++; + /* F_PSEUDO needs to be used together with F_ALIAS to indicate an alias opcode is a programmer friendly pseudo instruction available only in the assembly code (thus will not show up in the disassembly). */ @@ -189,6 +194,47 @@ read_table (const struct aarch64_opcode* table) ++errors; } + /* Check that the qualifier sequence lengths match the number of + operands. */ + bool qlf_end = false; + for (unsigned int i = 0; i < ARRAY_SIZE (ent->qualifiers_list); i++) + { + for (unsigned int j = 0; j < ARRAY_SIZE (ent->qualifiers_list[0]); j++) + { + if (j >= operand_count || qlf_end) + { + if (ent->qualifiers_list[i][j] != AARCH64_OPND_QLF_UNUSED) + { + fprintf (stderr, + "%s (%08x,%08x): Qualifier %u for sequence %u should be UNUSED.\n", + ent->name, ent->opcode, ent->mask, j, i); + ++errors; + } + } + else if (ent->qualifiers_list[i][j] == AARCH64_OPND_QLF_UNUSED) + { + if (j == 0) + { + qlf_end = true; + if (i == 0 && operand_count > 0) + { + fprintf (stderr, + "%s (%08x,%08x): No qualifiers specified.\n", + ent->name, ent->opcode, ent->mask); + ++errors; + } + } + else + { + fprintf (stderr, + "%s (%08x,%08x): Qualifier %u for sequence %u is missing.\n", + ent->name, ent->opcode, ent->mask, j, i); + ++errors; + } + } + } + } + if (ent->flags & F_SUBCLASS) iclass_has_subclasses_p[ent->iclass] = true;