X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=opcodes%2Fns32k-dis.c;h=d505edd774267d4c3f93200917a9296792bd4b31;hb=384f368958f2a5bb083660e58e5f8a010e6ad429;hp=b29eccc90a0f4939f100b053b9c6e0f91f93b7c7;hpb=4b95cf5c0c75d6efc1b2f96af72317aecca079f1;p=deliverable%2Fbinutils-gdb.git diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c index b29eccc90a..d505edd774 100644 --- a/opcodes/ns32k-dis.c +++ b/opcodes/ns32k-dis.c @@ -1,5 +1,5 @@ /* Print National Semiconductor 32000 instructions. - Copyright (C) 1986-2014 Free Software Foundation, Inc. + Copyright (C) 1986-2020 Free Software Foundation, Inc. This file is part of the GNU opcodes library. @@ -20,7 +20,7 @@ #include "sysdep.h" #include "bfd.h" -#include "dis-asm.h" +#include "disassemble.h" #if !defined(const) && !defined(__STDC__) #define const #endif @@ -57,7 +57,7 @@ struct private bfd_byte *max_fetched; bfd_byte the_buffer[MAXLEN]; bfd_vma insn_start; - jmp_buf bailout; + OPCODES_SIGJMP_BUF bailout; }; @@ -82,7 +82,7 @@ fetch_data (struct disassemble_info *info, bfd_byte *addr) if (status != 0) { (*info->memory_error_func) (status, start, info); - longjmp (priv->bailout, 1); + OPCODES_SIGLONGJMP (priv->bailout, 1); } else priv->max_fetched = addr; @@ -262,9 +262,11 @@ list_search (int reg_value, const struct ns32k_option *optionP, char *result) static int bit_extract (bfd_byte *buffer, int offset, int count) { - int result; - int bit; + unsigned int result; + unsigned int bit; + if (offset < 0 || count < 0) + return 0; buffer += offset >> 3; offset &= 7; bit = 1; @@ -289,9 +291,11 @@ bit_extract (bfd_byte *buffer, int offset, int count) static int bit_extract_simple (bfd_byte *buffer, int offset, int count) { - int result; - int bit; + unsigned int result; + unsigned int bit; + if (offset < 0 || count < 0) + return 0; buffer += offset >> 3; offset &= 7; bit = 1; @@ -313,18 +317,18 @@ bit_extract_simple (bfd_byte *buffer, int offset, int count) static void bit_copy (bfd_byte *buffer, int offset, int count, char *to) { + if (offset < 0 || count < 0) + return; for (; count > 8; count -= 8, to++, offset += 8) *to = bit_extract (buffer, offset, 8); *to = bit_extract (buffer, offset, count); } static int -sign_extend (int value, int bits) +sign_extend (unsigned int value, unsigned int bits) { - value = value & ((1 << bits) - 1); - return (value & (1 << (bits - 1)) - ? value | (~((1 << bits) - 1)) - : value); + unsigned int sign = 1u << (bits - 1); + return ((value & (sign + sign - 1)) ^ sign) - sign; } static void @@ -343,9 +347,7 @@ flip_bytes (char *ptr, int count) } /* Given a character C, does it represent a general addressing mode? */ -#define Is_gen(c) \ - ((c) == 'F' || (c) == 'L' || (c) == 'B' \ - || (c) == 'W' || (c) == 'D' || (c) == 'A' || (c) == 'I' || (c) == 'Z') +#define Is_gen(c) (strchr ("FLBWDAIZf", (c)) != NULL) /* Adressing modes. */ #define Adrmod_index_byte 0x1c @@ -413,7 +415,7 @@ invalid_float (bfd_byte *p, int len) #else /* Assumes the bytes have been swapped to local order. */ typedef union -{ +{ double d; float f; struct { unsigned m:23, e:8, :1;} sf; @@ -472,6 +474,7 @@ print_insn_arg (int d, case 'f': /* A "gen" operand but 5 bits from the end of instruction. */ ioffset -= 5; + /* Fall through. */ case 'Z': case 'F': case 'L': @@ -618,7 +621,7 @@ print_insn_arg (int d, int bit_index; static const char *ind = "bwdq"; char *off; - + /* Scaled index basemode[R0 -- R7:B,W,D,Q]. */ bit_index = bit_extract (buffer, index_offset - 8, 3); print_insn_arg (d, index_offset, aoffsetp, buffer, addr, @@ -745,7 +748,7 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info) info->private_data = & priv; priv.max_fetched = priv.the_buffer; priv.insn_start = memaddr; - if (setjmp (priv.bailout) != 0) + if (OPCODES_SIGSETJMP (priv.bailout) != 0) /* Error return. */ return -1; @@ -794,7 +797,7 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info) /* 0 for operand A, 1 for operand B, greater for other args. */ int whicharg = 0; - + (*dis_info->fprintf_func)(dis_info->stream, "\t"); maxarg = 0; @@ -803,9 +806,10 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info) if we are using scaled indexed addressing mode, since the index bytes occur right after the basic instruction, not as part of the addressing extension. */ - if (Is_gen(d[1])) + if (Is_gen (d[1])) { - int addr_mode = bit_extract (buffer, ioffset - 5, 5); + int bitoff = d[1] == 'f' ? 10 : 5; + int addr_mode = bit_extract (buffer, ioffset - bitoff, 5); if (Adrmod_is_index (addr_mode)) { @@ -814,7 +818,7 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info) } } - if (d[2] && Is_gen(d[3])) + if (d[2] && Is_gen (d[3])) { int addr_mode = bit_extract (buffer, ioffset - 10, 5); @@ -835,8 +839,10 @@ print_insn_ns32k (bfd_vma memaddr, disassemble_info *info) memaddr, arg_bufs[argnum], index_offset[whicharg]); d++; - whicharg++; + if (whicharg++ >= 1) + break; } + for (argnum = 0; argnum <= maxarg; argnum++) { bfd_vma addr;