X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=opcodes%2Fd30v-dis.c;h=ba43731122d80f24995261377e7ba7763d69817f;hb=6bbb0c0595660e6bc7477126a5b1adaf5387d006;hp=2a2916eeccc46a674f1012b9f8e59e521e4a7065;hpb=0fd3a4776c8f607cc778cde80f9215089d36387e;p=deliverable%2Fbinutils-gdb.git diff --git a/opcodes/d30v-dis.c b/opcodes/d30v-dis.c index 2a2916eecc..ba43731122 100644 --- a/opcodes/d30v-dis.c +++ b/opcodes/d30v-dis.c @@ -1,26 +1,29 @@ /* Disassemble D30V instructions. - Copyright 1997, 1998, 2000, 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 1997-2020 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This file is part of the GNU opcodes library. + + This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; either version 3, or (at your option) + any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -#include #include "sysdep.h" +#include #include "opcode/d30v.h" -#include "dis-asm.h" +#include "disassemble.h" #include "opintl.h" +#include "libiberty.h" #define PC_MASK 0xFFFFFFFF @@ -31,7 +34,7 @@ static int lookup_opcode (struct d30v_insn *insn, long num, int is_long) { - int i = 0, index; + int i = 0, op_index; struct d30v_format *f; struct d30v_opcode *op = (struct d30v_opcode *) d30v_opcode_table; int op1 = (num >> 25) & 0x7; @@ -53,11 +56,11 @@ lookup_opcode (struct d30v_insn *insn, long num, int is_long) while (op->op1 == op1 && op->op2 == op2) { /* Scan through all the formats for the opcode. */ - index = op->format[i++]; + op_index = op->format[i++]; do { - f = (struct d30v_format *) &d30v_format_table[index]; - while (f->form == index) + f = (struct d30v_format *) &d30v_format_table[op_index]; + while (f->form == op_index) { if ((!is_long || f->form >= LONG) && (f->modifier == mod)) { @@ -69,7 +72,7 @@ lookup_opcode (struct d30v_insn *insn, long num, int is_long) if (insn->form) break; } - while ((index = op->format[i++]) != 0); + while ((op_index = op->format[i++]) != 0); if (insn->form) break; op++; @@ -87,11 +90,11 @@ lookup_opcode (struct d30v_insn *insn, long num, int is_long) } static int -extract_value (long long num, struct d30v_operand *oper, int is_long) +extract_value (uint64_t num, const struct d30v_operand *oper, int is_long) { - int val; + unsigned int val; int shift = 12 - oper->position; - int mask = (0xFFFFFFFF >> (32 - oper->bits)); + unsigned int mask = (0xFFFFFFFF >> (32 - oper->bits)); if (is_long) { @@ -115,14 +118,15 @@ extract_value (long long num, struct d30v_operand *oper, int is_long) static void print_insn (struct disassemble_info *info, bfd_vma memaddr, - long long num, + uint64_t num, struct d30v_insn *insn, int is_long, int show_ext) { - int val, opnum, need_comma = 0; - struct d30v_operand *oper; - int i, match, opind = 0, need_paren = 0, found_control = 0; + unsigned int val, opnum; + const struct d30v_operand *oper; + int i, match, need_comma = 0, need_paren = 0, found_control = 0; + unsigned int opind = 0; (*info->fprintf_func) (info->stream, "%s", insn->op->name); @@ -132,7 +136,7 @@ print_insn (struct disassemble_info *info, opind++; val = extract_value (num, - (struct d30v_operand *) &d30v_operand_table[insn->form->operands[0]], + &d30v_operand_table[insn->form->operands[0]], is_long); (*info->fprintf_func) (info->stream, "%s", d30v_cc_names[val]); } @@ -151,11 +155,12 @@ print_insn (struct disassemble_info *info, (*info->fprintf_func) (info->stream, "\t"); - while ((opnum = insn->form->operands[opind++]) != 0) + while (opind < ARRAY_SIZE (insn->form->operands) + && (opnum = insn->form->operands[opind++]) != 0) { int bits; - oper = (struct d30v_operand *) &d30v_operand_table[opnum]; + oper = &d30v_operand_table[opnum]; bits = oper->bits; if (oper->flags & OPERAND_SHIFT) bits += 3; @@ -205,8 +210,8 @@ print_insn (struct disassemble_info *info, match = 0; if (oper->flags & OPERAND_CONTROL) { - struct d30v_operand *oper3 = - (struct d30v_operand *) &d30v_operand_table[insn->form->operands[2]]; + const struct d30v_operand *oper3 + = &d30v_operand_table[insn->form->operands[2]]; int id = extract_value (num, oper3, is_long); found_control = 1; @@ -223,7 +228,9 @@ print_insn (struct disassemble_info *info, val |= OPERAND_FLAG; break; default: - fprintf (stderr, "illegal id (%d)\n", id); + /* xgettext: c-format */ + opcodes_error_handler (_("illegal id (%d)"), id); + abort (); } } else if (oper->flags & OPERAND_ACC) @@ -264,14 +271,10 @@ print_insn (struct disassemble_info *info, /* IMM6S3 is unsigned. */ if (oper->flags & OPERAND_SIGNED || bits == 32) { - long max; - max = (1 << (bits - 1)); - if (val & max) + unsigned int sign = 1u << (bits - 1); + if (val & sign) { - if (bits == 32) - val = -val; - else - val = -val & ((1 << bits) - 1); + val = -val & (sign + sign - 1); neg = 1; } } @@ -296,20 +299,20 @@ print_insn (struct disassemble_info *info, { if (oper->flags & OPERAND_SIGNED) { - int max = (1 << (bits - 1)); + unsigned int sign = 1u << (bits - 1); - if (val & max) + if (val & sign) { - val = -val; - if (bits < 32) - val &= ((1 << bits) - 1); + val = -val & (sign + sign - 1); (*info->fprintf_func) (info->stream, "-"); } } (*info->fprintf_func) (info->stream, "0x%x", val); } /* If there is another operand, then write a comma and space. */ - if (insn->form->operands[opind] && !(found_control && opind == 2)) + if (opind < ARRAY_SIZE (insn->form->operands) + && insn->form->operands[opind] + && !(found_control && opind == 2)) need_comma = 1; } if (need_paren) @@ -321,9 +324,9 @@ print_insn_d30v (bfd_vma memaddr, struct disassemble_info *info) { int status, result; bfd_byte buffer[12]; - unsigned long in1, in2; + uint32_t in1, in2; struct d30v_insn insn; - long long num; + uint64_t num; insn.form = NULL; @@ -344,9 +347,9 @@ print_insn_d30v (bfd_vma memaddr, struct disassemble_info *info) { info->bytes_per_line = 8; if (!(result = lookup_opcode (&insn, in1, 0))) - (*info->fprintf_func) (info->stream, ".long\t0x%lx", in1); + (*info->fprintf_func) (info->stream, ".long\t0x%x", in1); else - print_insn (info, memaddr, (long long) in1, &insn, 0, result); + print_insn (info, memaddr, (uint64_t) in1, &insn, 0, result); return 4; } in2 = bfd_getb32 (buffer); @@ -356,17 +359,17 @@ print_insn_d30v (bfd_vma memaddr, struct disassemble_info *info) /* LONG instruction. */ if (!(result = lookup_opcode (&insn, in1, 1))) { - (*info->fprintf_func) (info->stream, ".long\t0x%lx,0x%lx", in1, in2); + (*info->fprintf_func) (info->stream, ".long\t0x%x,0x%x", in1, in2); return 8; } - num = (long long) in1 << 32 | in2; + num = (uint64_t) in1 << 32 | in2; print_insn (info, memaddr, num, &insn, 1, result); } else { num = in1; if (!(result = lookup_opcode (&insn, in1, 0))) - (*info->fprintf_func) (info->stream, ".long\t0x%lx", in1); + (*info->fprintf_func) (info->stream, ".long\t0x%x", in1); else print_insn (info, memaddr, num, &insn, 0, result); @@ -387,7 +390,7 @@ print_insn_d30v (bfd_vma memaddr, struct disassemble_info *info) insn.form = NULL; num = in2; if (!(result = lookup_opcode (&insn, in2, 0))) - (*info->fprintf_func) (info->stream, ".long\t0x%lx", in2); + (*info->fprintf_func) (info->stream, ".long\t0x%x", in2); else print_insn (info, memaddr, num, &insn, 0, result); }