arc: Don't generate dynamic relocation for non SEC_ALLOC sections
[deliverable/binutils-gdb.git] / opcodes / nds32-dis.c
index 81ae124c1d64ecc773238a2ed901815c5233ac51..35e4ba029176cb4c832dbce82554ba1da3d0bc93 100644 (file)
@@ -1,5 +1,5 @@
 /* NDS32-specific support for 32-bit ELF.
 /* NDS32-specific support for 32-bit ELF.
-   Copyright (C) 2012-2018 Free Software Foundation, Inc.
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
    Contributed by Andes Technology Corporation.
 
    This file is part of BFD, the Binary File Descriptor library.
    Contributed by Andes Technology Corporation.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -72,10 +72,7 @@ extern struct nds32_opcode nds32_opcodes[];
 extern const field_t operand_fields[];
 extern keyword_t *keywords[];
 extern const keyword_t keyword_gpr[];
 extern const field_t operand_fields[];
 extern keyword_t *keywords[];
 extern const keyword_t keyword_gpr[];
-static void print_insn16 (bfd_vma pc, disassemble_info *info,
-                         uint32_t insn, uint32_t parse_mode);
-static void print_insn32 (bfd_vma pc, disassemble_info *info, uint32_t insn,
-                         uint32_t parse_mode);
+
 static uint32_t nds32_mask_opcode (uint32_t);
 static void nds32_special_opcode (uint32_t, struct nds32_opcode **);
 static int get_mapping_symbol_type (struct disassemble_info *, int,
 static uint32_t nds32_mask_opcode (uint32_t);
 static void nds32_special_opcode (uint32_t, struct nds32_opcode **);
 static int get_mapping_symbol_type (struct disassemble_info *, int,
@@ -83,18 +80,6 @@ static int get_mapping_symbol_type (struct disassemble_info *, int,
 static int is_mapping_symbol (struct disassemble_info *, int,
                              enum map_type *);
 
 static int is_mapping_symbol (struct disassemble_info *, int,
                              enum map_type *);
 
-/* define in objdump.c.  */
-struct objdump_disasm_info
-{
-  bfd *              abfd;
-  asection *         sec;
-  bfd_boolean        require_sec;
-  arelent **         dynrelbuf;
-  long               dynrelcount;
-  disassembler_ftype disassemble_fn;
-  arelent *          reloc;
-};
-
 /* Hash function for disassemble.  */
 
 static htab_t opcode_htab;
 /* Hash function for disassemble.  */
 
 static htab_t opcode_htab;
@@ -128,8 +113,8 @@ nds32_parse_audio_ext (const field_t *pfd,
   if (pfd->hw_res == HW_INT || pfd->hw_res == HW_UINT)
     {
       if (pfd->hw_res == HW_INT)
   if (pfd->hw_res == HW_INT || pfd->hw_res == HW_UINT)
     {
       if (pfd->hw_res == HW_INT)
-       int_value =
-         N32_IMMS ((insn >> pfd->bitpos), pfd->bitsize) << pfd->shift;
+       int_value = (unsigned) N32_IMMS (insn >> pfd->bitpos,
+                                        pfd->bitsize) << pfd->shift;
       else
        int_value = __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
 
       else
        int_value = __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
 
@@ -321,9 +306,9 @@ nds32_parse_opcode (struct nds32_opcode *opc, bfd_vma pc ATTRIBUTE_UNUSED,
              else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
                {
                  if (pfd->hw_res == HW_INT)
              else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
                {
                  if (pfd->hw_res == HW_INT)
-                   int_value =
-                     N32_IMMS ((insn >> pfd->bitpos),
-                           pfd->bitsize) << pfd->shift;
+                   int_value
+                     = (unsigned) N32_IMMS (insn >> pfd->bitpos,
+                                            pfd->bitsize) << pfd->shift;
                  else
                    int_value =
                      __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
                  else
                    int_value =
                      __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
@@ -411,8 +396,8 @@ nds32_parse_opcode (struct nds32_opcode *opc, bfd_vma pc ATTRIBUTE_UNUSED,
          else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
            {
              if (pfd->hw_res == HW_INT)
          else if ((pfd->hw_res == HW_INT) || (pfd->hw_res == HW_UINT))
            {
              if (pfd->hw_res == HW_INT)
-               int_value =
-                 N32_IMMS ((insn >> pfd->bitpos), pfd->bitsize) << pfd->shift;
+               int_value = (unsigned) N32_IMMS (insn >> pfd->bitpos,
+                                                pfd->bitsize) << pfd->shift;
              else
                int_value =
                  __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
              else
                int_value =
                  __GF (insn, pfd->bitpos, pfd->bitsize) << pfd->shift;
@@ -892,7 +877,7 @@ nds32_mask_opcode (uint32_t insn)
        }
       return MASK_OP (insn, 0x1f << 20);
     default:
        }
       return MASK_OP (insn, 0x1f << 20);
     default:
-      return (1 << 31);
+      return 1u << 31;
     }
 }
 
     }
 }
 
@@ -991,8 +976,8 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
   int status;
   bfd_byte buf[4];
   bfd_byte buf_data[16];
   int status;
   bfd_byte buf[4];
   bfd_byte buf_data[16];
-  long long given;
-  long long given1;
+  uint64_t given;
+  uint64_t given1;
   uint32_t insn;
   int n;
   int last_symbol_index = -1;
   uint32_t insn;
   int n;
   int last_symbol_index = -1;
@@ -1000,7 +985,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
   int is_data = FALSE;
   bfd_boolean found = FALSE;
   struct nds32_private_data *private_data;
   int is_data = FALSE;
   bfd_boolean found = FALSE;
   struct nds32_private_data *private_data;
-  unsigned int size = 16;
+  unsigned int size;
   enum map_type mapping_type = MAP_CODE;
 
   if (info->private_data == NULL)
   enum map_type mapping_type = MAP_CODE;
 
   if (info->private_data == NULL)
@@ -1078,6 +1063,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
 
       /* Fix corner case: there is no next mapping symbol,
         let mapping type decides size */
 
       /* Fix corner case: there is no next mapping symbol,
         let mapping type decides size */
+      size = 16;
       if (last_symbol_index + 1 >= info->symtab_size)
        {
          if (mapping_type == MAP_DATA0)
       if (last_symbol_index + 1 >= info->symtab_size)
        {
          if (mapping_type == MAP_DATA0)
@@ -1111,7 +1097,7 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
        size = (pc & 1) ? 1 : 2;
 
       /* Read bytes from BFD.  */
        size = (pc & 1) ? 1 : 2;
 
       /* Read bytes from BFD.  */
-      info->read_memory_func (pc, (bfd_byte *) buf_data, size, info);
+      info->read_memory_func (pc, buf_data, size, info);
       given = 0;
       given1 = 0;
       /* Start assembling data.  */
       given = 0;
       given1 = 0;
       /* Start assembling data.  */
@@ -1144,39 +1130,44 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
       info->bytes_per_line = 4;
 
       if (size == 16)
       info->bytes_per_line = 4;
 
       if (size == 16)
-       info->fprintf_func (info->stream, ".qword\t0x%016llx%016llx",
+       info->fprintf_func (info->stream, ".qword\t0x%016" PRIx64 "%016" PRIx64,
                            given, given1);
       else if (size == 8)
                            given, given1);
       else if (size == 8)
-       info->fprintf_func (info->stream, ".dword\t0x%016llx", given);
+       info->fprintf_func (info->stream, ".dword\t0x%016" PRIx64, given);
       else if (size == 4)
       else if (size == 4)
-       info->fprintf_func (info->stream, ".word\t0x%08llx", given);
+       info->fprintf_func (info->stream, ".word\t0x%08" PRIx64, given);
       else if (size == 2)
        {
          /* short */
          if (mapping_type == MAP_DATA0)
       else if (size == 2)
        {
          /* short */
          if (mapping_type == MAP_DATA0)
-           info->fprintf_func (info->stream, ".byte\t0x%02llx", given & 0xFF);
+           info->fprintf_func (info->stream, ".byte\t0x%02" PRIx64,
+                               given & 0xFF);
          else
          else
-           info->fprintf_func (info->stream, ".short\t0x%04llx", given);
+           info->fprintf_func (info->stream, ".short\t0x%04" PRIx64, given);
        }
       else
        {
          /* byte */
        }
       else
        {
          /* byte */
-         info->fprintf_func (info->stream, ".byte\t0x%02llx", given);
+         info->fprintf_func (info->stream, ".byte\t0x%02" PRIx64, given);
        }
 
       return size;
     }
 
        }
 
       return size;
     }
 
-  status = info->read_memory_func (pc, (bfd_byte *) buf, 4, info);
+  size = 4;
+  status = info->read_memory_func (pc, buf, 4, info);
   if (status)
     {
       /* For the last 16-bit instruction.  */
   if (status)
     {
       /* For the last 16-bit instruction.  */
-      status = info->read_memory_func (pc, (bfd_byte *) buf, 2, info);
+      size = 2;
+      status = info->read_memory_func (pc, buf, 2, info);
       if (status)
        {
       if (status)
        {
-         (*info->memory_error_func)(status, pc, info);
+         (*info->memory_error_func) (status, pc, info);
          return -1;
        }
          return -1;
        }
+      buf[2] = 0;
+      buf[3] = 0;
     }
 
   insn = bfd_getb32 (buf);
     }
 
   insn = bfd_getb32 (buf);
@@ -1188,11 +1179,12 @@ print_insn_nds32 (bfd_vma pc, disassemble_info *info)
     }
 
   /* 32-bit instructions.  */
     }
 
   /* 32-bit instructions.  */
+  if (size == 4)
+    print_insn32 (pc, info, insn, NDS32_PARSE_INSN32);
   else
   else
-    {
-      print_insn32 (pc, info, insn, NDS32_PARSE_INSN32);
-      return 4;
-    }
+    info->fprintf_func (info->stream,
+                       _("insufficient data to decode instruction"));
+  return 4;
 }
 
 /* Ignore disassembling unnecessary name.  */
 }
 
 /* Ignore disassembling unnecessary name.  */
This page took 0.037512 seconds and 4 git commands to generate.