* po/Make-in (install-info): New target.
[deliverable/binutils-gdb.git] / opcodes / v850-dis.c
index 77bf51d11cc5e72483f1925a5014273c95444d39..c43f6dbea7047d51a66fabbcdc2c5364de56d01f 100644 (file)
@@ -26,11 +26,15 @@ static const char *const v850_reg_names[] =
 { "r0", "r1", "r2", "sp", "gp", "r5", "r6", "r7", 
   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 
   "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 
-  "r24", "r25", "r26", "r27", "r28", "r29", "ep", "r31" };
+  "r24", "r25", "r26", "r27", "r28", "r29", "ep", "lp" };
 
 static const char *const v850_sreg_names[] =
 { "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7", 
-  "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15", 
+  "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
+/* start-sanitize-v850e */
+  "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23", 
+  "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
+/* end-sanitize-v850e */
   "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23", 
   "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31" };
 
@@ -49,22 +53,43 @@ disassemble (memaddr, info, insn)
   int                           match = 0;
   int                          short_op = ((insn & 0x0600) != 0x0600);
   int                          bytes_read;
-
-
+  int                          target_processor;
+  
+/* start-sanitize-v850e */
   /* Special case: 32 bit MOV */
   if ((insn & 0xffe0) == 0x0620)
     short_op = true;
-      
+/* end-sanitize-v850e */
+  
   bytes_read = short_op ? 2 : 4;
   
   /* If this is a two byte insn, then mask off the high bits. */
   if (short_op)
     insn &= 0xffff;
 
+  switch (info->mach)
+    {
+    case 0:
+    default:
+      target_processor = PROCESSOR_V850;
+      break;
+
+/* start-sanitize-v850e */
+    case bfd_mach_v850e:
+      target_processor = PROCESSOR_V850E;
+      break;
+
+    case bfd_mach_v850eq: 
+      target_processor = PROCESSOR_V850EQ;
+      break;
+/* end-sanitize-v850e */
+    }
+  
   /* Find the opcode.  */
   while (op->name)
     {
-      if ((op->mask & insn) == op->opcode)
+      if ((op->mask & insn) == op->opcode
+         && (op->processors & target_processor))
        {
          const unsigned char * opindex_ptr;
          unsigned int          opnum;
@@ -98,17 +123,20 @@ disassemble (memaddr, info, insn)
              bfd_byte  buffer[ 4 ];
              
              operand = &v850_operands[*opindex_ptr];
-
+             
              if (operand->extract)
                value = (operand->extract) (insn, 0);
-             else if (operand->bits == -1)
-               value = (insn & operand->shift);
              else
-               value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
+               {
+                 if (operand->bits == -1)
+                   value = (insn & operand->shift);
+                 else
+                   value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
 
-             if (operand->flags & V850_OPERAND_SIGNED)
-               value = ((long)(value << (32 - operand->bits))
-                         >> (32 - operand->bits));
+                 if (operand->flags & V850_OPERAND_SIGNED)
+                   value = ((long)(value << (32 - operand->bits))
+                            >> (32 - operand->bits));
+               }
 
              /* The first operand is always output without any
                 special handling.
@@ -143,7 +171,6 @@ disassemble (memaddr, info, insn)
              flag = operand->flags;
              flag &= ~ V850_OPERAND_SIGNED;
              flag &= ~ V850_OPERAND_RELAX;
-             flag &= ~ V850_OPERAND_ADJUST_SHORT_MEMORY;
              flag &= - flag;
              
              switch (flag)
@@ -152,53 +179,109 @@ disassemble (memaddr, info, insn)
                case V850_OPERAND_SRG:  info->fprintf_func (info->stream, "%s", v850_sreg_names[value]); break;
                case V850_OPERAND_CC:   info->fprintf_func (info->stream, "%s", v850_cc_names[value]); break;
                case V850_OPERAND_EP:   info->fprintf_func (info->stream, "ep"); break;
-               case V850_OPERAND_DISP: info->print_address_func (value + memaddr, info); break;
                default:                info->fprintf_func (info->stream, "%d", value); break;
+               case V850_OPERAND_DISP:
+                 {
+                   bfd_vma addr = value + memaddr;
+                   
+                   /* On the v850 the top 8 bits of an address are used by an overlay manager.
+                      Thus it may happen that when we are looking for a symbol to match
+                      against an address with some of its top bits set, the search fails to
+                      turn up an exact match.  In this case we try to find an exact match
+                      against a symbol in the lower address space, and if we find one, we
+                      use that address.   We only do this for JARL instructions however, as
+                      we do not want to misinterpret branch instructions.  */
+                   if (operand->bits == 22)
+                     {
+                       if ( ! info->symbol_at_address_func (addr, info)
+                           && ((addr & 0xFF000000) != 0)
+                           && info->symbol_at_address_func (addr & 0x00FFFFFF, info))
+                         {
+                           addr &= 0x00FFFFFF;
+                         }
+                     }
+                   info->print_address_func (addr, info);
+                   break;
+                 }
+                   
 /* start-sanitize-v850e */
                case V850E_PUSH_POP:
                  {
-                   static int list12_regs[32] = { 30,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
-/* start-sanitize-v850eq */
+                   static int list12_regs[32]   = { 30,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
                    static int list18_h_regs[32] = { 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
                    static int list18_l_regs[32] = {  3,  2,  1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 14, 15, 13, 12,  7,  6,  5,  4, 11, 10,  9,  8 };
-/* end-sanitize-v850eq */
-                   int *      regs;
-                   int        i;
-                   int        shown_one = false;
+                   int *             regs;
+                   int               i;
+                   unsigned long int mask = 0;
+                   int               pc   = false;
+                   int               sr   = false;
+                   
                    
                    switch (operand->shift)
                      {
                      case 0xffe00001: regs = list12_regs; break;
-/* start-sanitize-v850eq */
                      case 0xfff8000f: regs = list18_h_regs; break;
                      case 0xfff8001f: regs = list18_l_regs; value &= ~0x10; break;  /* Do not include magic bit */
-/* end-sanitize-v850eq */
                      default:
                        fprintf (stderr, "unknown operand shift: %x\n", operand->shift );                   
                        abort();
                      }
 
-                   info->fprintf_func (info->stream, "{");
                    for (i = 0; i < 32; i++)
                      {
                        if (value & (1 << i))
                          {
-                           if (shown_one)
-                             info->fprintf_func (info->stream, ",");
-                           else
-                             shown_one = true;
-                             
                            switch (regs[ i ])
                              {
-                             default: info->fprintf_func (info->stream, "%s", v850_reg_names[regs[ i ]]); break;
-/* start-sanitize-v850eq */
+                             default: mask |= (1 << regs[ i ]); break;
                              case 0:  fprintf (stderr, "unknown pop reg: %d\n", i ); abort();
-                             case -1: info->fprintf_func (info->stream, "PC "); break;
-                             case -2: info->fprintf_func (info->stream, "SR"); break;
-/* end-sanitize-v850eq */
+                             case -1: pc = true; break;
+                             case -2: sr = true; break;
                              }
                          }
                      }
+
+                   info->fprintf_func (info->stream, "{");
+                   
+                   if (mask || pc || sr)
+                     {
+                       if (mask)
+                         {
+                           unsigned int bit;
+                           int          shown_one = false;
+                           
+                           for (bit = 0; bit < 32; bit++)
+                             if (mask & (1 << bit))
+                               {
+                                 unsigned long int first = bit;
+                                 unsigned long int last;
+
+                                 if (shown_one)
+                                   info->fprintf_func (info->stream, ", ");
+                                 else
+                                   shown_one = true;
+                                 
+                                 info->fprintf_func (info->stream, v850_reg_names[first]);
+                                 
+                                 for (bit++; bit < 32; bit++)
+                                   if ((mask & (1 << bit)) == 0)
+                                     break;
+
+                                 last = bit;
+
+                                 if (last > first + 1)
+                                   {
+                                     info->fprintf_func (info->stream, " - %s", v850_reg_names[ last - 1 ]);
+                                   }
+                               }
+                         }
+                       
+                       if (pc)
+                         info->fprintf_func (info->stream, "%sPC", mask ? ", " : "");
+                       if (sr)
+                         info->fprintf_func (info->stream, "%sSR", (mask || pc) ? ", " : "");
+                     }
+                   
                    info->fprintf_func (info->stream, "}");
                  }
                break;
@@ -301,5 +384,3 @@ print_insn_v850 (memaddr, info)
   /* Make sure we tell our caller how many bytes we consumed.  */
   return disassemble (memaddr, info, insn);
 }
-
-
This page took 0.028004 seconds and 4 git commands to generate.