From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 2B4833942013; Fri, 26 May 2023 07:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B4833942013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: use fixed-width type for codep and friends X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: 778415f5975f5acb7c7527770c07f5ec55145385 X-Git-Newrev: a4aa034a0abca9c93910c23fbe7ed5f07b4c4b0b Message-Id: <20230526075358.2B4833942013@sourceware.org> Date: Fri, 26 May 2023 07:53:58 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 May 2023 07:53:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da4aa034a0abc= a9c93910c23fbe7ed5f07b4c4b0b commit a4aa034a0abca9c93910c23fbe7ed5f07b4c4b0b Author: Jan Beulich Date: Fri May 26 09:53:01 2023 +0200 x86: use fixed-width type for codep and friends =20 This first of all removes a dependency on bfd_byte and unsigned char being the same types. It further eliminates the need to mask by 0xff when fetching values (which wasn't done fully consistently anyway), improving code legibility. =20 While there, where possible add const. Diff: --- opcodes/i386-dis.c | 112 ++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 07fcf3269f9..398be8b20c5 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -120,8 +120,8 @@ static void ATTRIBUTE_PRINTF_3 i386_dis_printf (const d= isassemble_info *, =20 struct dis_private { /* Points to first byte not fetched. */ - bfd_byte *max_fetched; - bfd_byte the_buffer[MAX_MNEM_SIZE]; + uint8_t *max_fetched; + uint8_t the_buffer[MAX_MNEM_SIZE]; bfd_vma insn_start; int orig_sizeflag; }; @@ -133,7 +133,7 @@ enum address_mode mode_64bit }; =20 -static const char *prefix_name (enum address_mode, int, int); +static const char *prefix_name (enum address_mode, uint8_t, int); =20 enum x86_64_isa { @@ -149,9 +149,9 @@ struct instr_info int prefixes; =20 /* REX prefix the current instruction. See below. */ - unsigned char rex; + uint8_t rex; /* Bits of REX we've already used. */ - unsigned char rex_used; + uint8_t rex_used; =20 bool need_modrm; bool need_vex; @@ -168,10 +168,10 @@ struct instr_info char obuf[MAX_OPERAND_BUFFER_SIZE]; char *obufp; char *mnemonicendp; - unsigned char *start_codep; - unsigned char *insn_codep; - unsigned char *codep; - unsigned char *end_codep; + const uint8_t *start_codep; + uint8_t *insn_codep; + uint8_t *codep; + const uint8_t *end_codep; signed char last_lock_prefix; signed char last_repz_prefix; signed char last_repnz_prefix; @@ -186,7 +186,7 @@ struct instr_info #define MAX_CODE_LENGTH 15 /* We can up to 14 ins->prefixes since the maximum instruction length is 15bytes. */ - unsigned char all_prefixes[MAX_CODE_LENGTH - 1]; + uint8_t all_prefixes[MAX_CODE_LENGTH - 1]; disassemble_info *info; =20 struct @@ -288,7 +288,7 @@ struct instr_info to ADDR (exclusive) are valid. Returns true for success, false on error. */ static bool -fetch_code (struct disassemble_info *info, bfd_byte *until) +fetch_code (struct disassemble_info *info, uint8_t *until) { int status =3D -1; struct dis_private *priv =3D info->private_data; @@ -8833,7 +8833,8 @@ static enum { } ckprefix (instr_info *ins) { - int newrex, i, length; + int i, length; + uint8_t newrex; =20 i =3D 0; length =3D 0; @@ -8843,7 +8844,7 @@ ckprefix (instr_info *ins) if (!fetch_code (ins->info, ins->codep + 1)) return ckp_fetch_error; newrex =3D 0; - switch (*ins->codep & 0xff) + switch (*ins->codep) { /* REX prefixes family. */ case 0x40: @@ -8863,7 +8864,7 @@ ckprefix (instr_info *ins) case 0x4e: case 0x4f: if (ins->address_mode =3D=3D mode_64bit) - newrex =3D *ins->codep & 0xff; + newrex =3D *ins->codep; else return ckp_okay; ins->last_rex_prefix =3D i; @@ -8943,8 +8944,8 @@ ckprefix (instr_info *ins) /* Rex is ignored when followed by another prefix. */ if (ins->rex) return ckp_bogus; - if ((*ins->codep & 0xff) !=3D FWAIT_OPCODE) - ins->all_prefixes[i++] =3D *ins->codep & 0xff; + if (*ins->codep !=3D FWAIT_OPCODE) + ins->all_prefixes[i++] =3D *ins->codep; ins->rex =3D newrex; ins->codep++; length++; @@ -8956,7 +8957,7 @@ ckprefix (instr_info *ins) prefix byte. */ =20 static const char * -prefix_name (enum address_mode mode, int pref, int sizeflag) +prefix_name (enum address_mode mode, uint8_t pref, int sizeflag) { static const char *rexes [16] =3D { @@ -9175,7 +9176,7 @@ get_valid_dis386 (const struct dis386 *dp, instr_info= *ins) case USE_3BYTE_TABLE: if (!fetch_code (ins->info, ins->codep + 2)) return &err_opcode; - vindex =3D *ins->codep++ & 0xff; + vindex =3D *ins->codep++; dp =3D &three_byte_table[dp->op[1].bytemode][vindex]; ins->end_codep =3D ins->codep; if (!fetch_modrm (ins)) @@ -9282,7 +9283,7 @@ get_valid_dis386 (const struct dis386 *dp, instr_info= *ins) } ins->need_vex =3D true; ins->codep++; - vindex =3D *ins->codep++ & 0xff; + vindex =3D *ins->codep++; dp =3D &xop_table[vex_table_index][vindex]; =20 ins->end_codep =3D ins->codep; @@ -9347,7 +9348,7 @@ get_valid_dis386 (const struct dis386 *dp, instr_info= *ins) } ins->need_vex =3D true; ins->codep++; - vindex =3D *ins->codep++ & 0xff; + vindex =3D *ins->codep++; dp =3D &vex_table[vex_table_index][vindex]; ins->end_codep =3D ins->codep; /* There is no MODRM byte for VEX0F 77. */ @@ -9382,7 +9383,7 @@ get_valid_dis386 (const struct dis386 *dp, instr_info= *ins) } ins->need_vex =3D true; ins->codep++; - vindex =3D *ins->codep++ & 0xff; + vindex =3D *ins->codep++; dp =3D &vex_table[dp->op[1].bytemode][vindex]; ins->end_codep =3D ins->codep; /* There is no MODRM byte for VEX 77. */ @@ -9474,7 +9475,7 @@ get_valid_dis386 (const struct dis386 *dp, instr_info= *ins) =20 ins->need_vex =3D true; ins->codep++; - vindex =3D *ins->codep++ & 0xff; + vindex =3D *ins->codep++; dp =3D &evex_table[vex_table_index][vindex]; ins->end_codep =3D ins->codep; if (!fetch_modrm (ins)) @@ -9821,11 +9822,10 @@ print_insn (bfd_vma pc, disassemble_info *info, int= intel_syntax) goto out; } =20 - ins.two_source_ops =3D ((*ins.codep & 0xff) =3D=3D 0x62 - || (*ins.codep & 0xff) =3D=3D 0xc8); + ins.two_source_ops =3D (*ins.codep =3D=3D 0x62 || *ins.codep =3D=3D 0xc8= ); =20 if ((ins.prefixes & PREFIX_FWAIT) - && ((*ins.codep & 0xff) < 0xd8 || (*ins.codep & 0xff) > 0xdf)) + && (*ins.codep < 0xd8 || *ins.codep > 0xdf)) { /* Handle ins.prefixes before fwait. */ for (i =3D 0; i < ins.fwait_prefix && ins.all_prefixes[i]; @@ -9838,22 +9838,22 @@ print_insn (bfd_vma pc, disassemble_info *info, int= intel_syntax) goto out; } =20 - if ((*ins.codep & 0xff) =3D=3D 0x0f) + if (*ins.codep =3D=3D 0x0f) { unsigned char threebyte; =20 ins.codep++; if (!fetch_code (info, ins.codep + 1)) goto fetch_error_out; - threebyte =3D *ins.codep & 0xff; + threebyte =3D *ins.codep; dp =3D &dis386_twobyte[threebyte]; ins.need_modrm =3D twobyte_has_modrm[threebyte]; ins.codep++; } else { - dp =3D &dis386[*ins.codep & 0xff]; - ins.need_modrm =3D onebyte_has_modrm[*ins.codep & 0xff]; + dp =3D &dis386[*ins.codep]; + ins.need_modrm =3D onebyte_has_modrm[*ins.codep]; ins.codep++; } =20 @@ -10553,9 +10553,7 @@ static bool dofloat (instr_info *ins, int sizeflag) { const struct dis386 *dp; - unsigned char floatop; - - floatop =3D ins->codep[-1] & 0xff; + unsigned char floatop =3D ins->codep[-1]; =20 if (ins->modrm.mod !=3D 3) { @@ -10576,7 +10574,7 @@ dofloat (instr_info *ins, int sizeflag) putop (ins, fgrps[dp->op[0].bytemode][ins->modrm.rm], sizeflag); =20 /* Instruction fnstsw is only one with strange arg. */ - if (floatop =3D=3D 0xdf && (ins->codep[-1] & 0xff) =3D=3D 0xe0) + if (floatop =3D=3D 0xdf && ins->codep[-1] =3D=3D 0xe0) strcpy (ins->op_out[0], att_names16[0] + ins->intel_syntax); } else @@ -11749,7 +11747,7 @@ get8s (instr_info *ins, bfd_vma *res) { if (!fetch_code (ins->info, ins->codep + 1)) return false; - *res =3D (((bfd_vma) *ins->codep++ & 0xff) ^ 0x80) - 0x80; + *res =3D ((bfd_vma) *ins->codep++ ^ 0x80) - 0x80; return true; } =20 @@ -11758,8 +11756,8 @@ get16 (instr_info *ins, bfd_vma *res) { if (!fetch_code (ins->info, ins->codep + 2)) return false; - *res =3D (bfd_vma) *ins->codep++ & 0xff; - *res |=3D ((bfd_vma) *ins->codep++ & 0xff) << 8; + *res =3D *ins->codep++; + *res |=3D (bfd_vma) *ins->codep++ << 8; return true; } =20 @@ -11777,10 +11775,10 @@ get32 (instr_info *ins, bfd_vma *res) { if (!fetch_code (ins->info, ins->codep + 4)) return false; - *res =3D *ins->codep++ & (bfd_vma) 0xff; - *res |=3D (*ins->codep++ & (bfd_vma) 0xff) << 8; - *res |=3D (*ins->codep++ & (bfd_vma) 0xff) << 16; - *res |=3D (*ins->codep++ & (bfd_vma) 0xff) << 24; + *res =3D *ins->codep++; + *res |=3D (bfd_vma) *ins->codep++ << 8; + *res |=3D (bfd_vma) *ins->codep++ << 16; + *res |=3D (bfd_vma) *ins->codep++ << 24; return true; } =20 @@ -11803,14 +11801,14 @@ get64 (instr_info *ins, uint64_t *res) =20 if (!fetch_code (ins->info, ins->codep + 8)) return false; - a =3D *ins->codep++ & 0xff; - a |=3D (*ins->codep++ & 0xff) << 8; - a |=3D (*ins->codep++ & 0xff) << 16; - a |=3D (*ins->codep++ & 0xffu) << 24; - b =3D *ins->codep++ & 0xff; - b |=3D (*ins->codep++ & 0xff) << 8; - b |=3D (*ins->codep++ & 0xff) << 16; - b |=3D (*ins->codep++ & 0xffu) << 24; + a =3D *ins->codep++; + a |=3D (unsigned int) *ins->codep++ << 8; + a |=3D (unsigned int) *ins->codep++ << 16; + a |=3D (unsigned int) *ins->codep++ << 24; + b =3D *ins->codep++; + b |=3D (unsigned int) *ins->codep++ << 8; + b |=3D (unsigned int) *ins->codep++ << 16; + b |=3D (unsigned int) *ins->codep++ << 24; *res =3D a + ((uint64_t) b << 32); return true; } @@ -12489,7 +12487,7 @@ OP_I (instr_info *ins, int bytemode, int sizeflag) case b_mode: if (!fetch_code (ins->info, ins->codep + 1)) return false; - op =3D *ins->codep++ & 0xff; + op =3D *ins->codep++; break; case v_mode: USED_REX (REX_W); @@ -12776,7 +12774,7 @@ OP_ESreg (instr_info *ins, int code, int sizeflag) { if (ins->intel_syntax) { - switch (ins->codep[-1] & 0xff) + switch (ins->codep[-1]) { case 0x6d: /* insw/insl */ intel_operand_size (ins, z_mode, sizeflag); @@ -12802,7 +12800,7 @@ OP_DSreg (instr_info *ins, int code, int sizeflag) { if (ins->intel_syntax) { - switch (ins->codep[-1] & 0xff) + switch (ins->codep[-1]) { case 0x6f: /* outsw/outsl */ intel_operand_size (ins, z_mode, sizeflag); @@ -13248,7 +13246,7 @@ OP_3DNowSuffix (instr_info *ins, int bytemode ATTRI= BUTE_UNUSED, place where an 8-bit immediate would normally go. ie. the last byte of the instruction. */ ins->obufp =3D ins->mnemonicendp; - mnemonic =3D Suffix3DNow[*ins->codep++ & 0xff]; + mnemonic =3D Suffix3DNow[*ins->codep++]; if (mnemonic) ins->obufp =3D stpcpy (ins->obufp, mnemonic); else @@ -13313,7 +13311,7 @@ CMP_Fixup (instr_info *ins, int bytemode ATTRIBUTE_= UNUSED, =20 if (!fetch_code (ins->info, ins->codep + 1)) return false; - cmp_type =3D *ins->codep++ & 0xff; + cmp_type =3D *ins->codep++; if (cmp_type < ARRAY_SIZE (simd_cmp_op)) { char suffix[3]; @@ -13763,7 +13761,7 @@ OP_REG_VexI4 (instr_info *ins, int bytemode, int si= zeflag ATTRIBUTE_UNUSED) =20 if (!fetch_code (ins->info, ins->codep + 1)) return false; - reg =3D *ins->codep++ & 0xff; + reg =3D *ins->codep++; =20 if (bytemode !=3D x_mode && bytemode !=3D scalar_mode) abort (); @@ -13807,7 +13805,7 @@ VPCMP_Fixup (instr_info *ins, int bytemode ATTRIBUT= E_UNUSED, =20 if (!fetch_code (ins->info, ins->codep + 1)) return false; - cmp_type =3D *ins->codep++ & 0xff; + cmp_type =3D *ins->codep++; /* There are aliases for immediates 0, 1, 2, 4, 5, 6. If it's the case, print suffix, otherwise - print the immediate. */ if (cmp_type < ARRAY_SIZE (simd_cmp_op) @@ -13862,7 +13860,7 @@ VPCOM_Fixup (instr_info *ins, int bytemode ATTRIBUT= E_UNUSED, =20 if (!fetch_code (ins->info, ins->codep + 1)) return false; - cmp_type =3D *ins->codep++ & 0xff; + cmp_type =3D *ins->codep++; if (cmp_type < ARRAY_SIZE (xop_cmp_op)) { char suffix[3]; @@ -13909,7 +13907,7 @@ PCLMUL_Fixup (instr_info *ins, int bytemode ATTRIBU= TE_UNUSED, =20 if (!fetch_code (ins->info, ins->codep + 1)) return false; - pclmul_type =3D *ins->codep++ & 0xff; + pclmul_type =3D *ins->codep++; switch (pclmul_type) { case 0x10: