import insight-2000-02-04 snapshot (2nd try)
[external/binutils.git] / opcodes / h8300-dis.c
index c9d2353..57753a9 100644 (file)
@@ -1,5 +1,5 @@
 /* Disassemble h8300 instructions.
-   Copyright (C) 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1998 Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -13,13 +13,14 @@ 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #define DEFINE_TABLE
 
 #define h8_opcodes h8ops
 #include "opcode/h8300.h"
 #include "dis-asm.h"
+#include "opintl.h"
 
 
 /* Run through the opcodes and sort them into order to make them easy
@@ -64,10 +65,10 @@ bfd_h8_disassemble_init ()
 
 
 unsigned int
-bfd_h8_disassemble (addr, info, hmode)
+bfd_h8_disassemble (addr, info, mode)
      bfd_vma addr;
      disassemble_info *info;
-     int hmode;
+     int mode;
 {
   /* Find the first entry in the table for this opcode */
   static CONST char *regnames[] =
@@ -92,11 +93,14 @@ bfd_h8_disassemble (addr, info, hmode)
   int rd = 0;
   int rdisp = 0;
   int abs = 0;
+  int bit = 0;
   int plen = 0;
-  static boolean init;  
+  static boolean init = 0;
   struct h8_opcode *q = h8_opcodes;
-  char CONST **pregnames = hmode ? lregnames : wregnames;
+  char CONST **pregnames = mode != 0 ? lregnames : wregnames;
   int status;
+  int l;
+  
   unsigned char data[20];  
   void *stream = info->stream;
   fprintf_ftype fprintf = info->fprintf_func;
@@ -104,7 +108,7 @@ bfd_h8_disassemble (addr, info, hmode)
   if (!init)
     {
       bfd_h8_disassemble_init ();
-      init = true;
+      init = 1;
     }
 
   status = info->read_memory_func(addr, data, 2, info);
@@ -113,8 +117,11 @@ bfd_h8_disassemble (addr, info, hmode)
       info->memory_error_func(status, addr, info);
       return -1;
     }
-  status = info->read_memory_func(addr, data+2, 8, info);
-
+  for (l = 2; status == 0 && l < 10; l+=2)
+    {
+      status = info->read_memory_func(addr+l, data+l, 2, info);
+    }
+  
   
 
   /* Find the exact opcode/arg combo */
@@ -132,7 +139,7 @@ bfd_h8_disassemble (addr, info, hmode)
          
          thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
          
-         if (looking_for < 16) 
+         if (looking_for < 16 && looking_for >=0
            {
              
              if (looking_for != thisnib) 
@@ -185,7 +192,10 @@ bfd_h8_disassemble (addr, info, hmode)
                      | (data[2] << 8)
                        | (data[3]);
                }
-             
+             else if(looking_for & MEMIND)
+               {
+                 abs = data[1];
+               }
              else if (looking_for & L_32)
                {
                  int i = len >> 1;
@@ -200,8 +210,7 @@ bfd_h8_disassemble (addr, info, hmode)
              else if (looking_for & L_24)
                {
                  int i = len >> 1;
-                 abs = (data[i] << 16) | (data[i + 1] << 8)|  (data[i+
-                                                                    2]);
+                 abs = (data[i] << 16) | (data[i + 1] << 8)|  (data[i+2]);
                  plen =24;
                }
              else if (looking_for & IGNORE)
@@ -225,6 +234,8 @@ bfd_h8_disassemble (addr, info, hmode)
                    case 0:
                      abs = 1;
                      break;
+                   default:
+                     goto fail;
                    }
                }
              else if (looking_for & L_8)
@@ -234,9 +245,16 @@ bfd_h8_disassemble (addr, info, hmode)
                }
              else if (looking_for & L_3)
                {
-                 plen = 3;
-             
-                 abs = thisnib;
+                 bit = thisnib & 0x7;
+               }
+             else if (looking_for & L_2)
+               {
+                 plen = 2;
+                 abs = thisnib & 0x3;
+               }
+             else if (looking_for & MACREG)
+               {
+                 abs = (thisnib == 3);
                }
              else if (looking_for == E)
                {
@@ -254,6 +272,30 @@ bfd_h8_disassemble (addr, info, hmode)
                      }
                  }
                  fprintf (stream, "%s\t", q->name);
+
+                 /* Gross.  Disgusting.  */
+                 if (strcmp (q->name, "ldm.l") == 0)
+                   {
+                     int count, high;
+
+                     count = (data[1] >> 4) & 0x3;
+                     high = data[3] & 0x7;
+
+                     fprintf (stream, "@sp+,er%d-er%d", high - count, high);
+                     return q->length;
+                   }
+
+                 if (strcmp (q->name, "stm.l") == 0)
+                   {
+                     int count, low;
+
+                     count = (data[1] >> 4) & 0x3;
+                     low = data[3] & 0x7;
+
+                     fprintf (stream, "er%d-er%d,@-sp", low, low + count);
+                     return q->length;
+                   }
+
                  /* Fill in the args */
                  {
                    op_type *args = q->args.nib;
@@ -267,9 +309,16 @@ bfd_h8_disassemble (addr, info, hmode)
                          fprintf (stream, ",");
 
 
-                       if (x & (IMM|KBIT|DBIT))
+                       if (x & L_3)
+                         {
+                           fprintf (stream, "#0x%x", (unsigned) bit);
+                         }
+                       else if (x & (IMM|KBIT|DBIT))
                          {
-                       
+                           /* Bletch.  For shal #2,er0 and friends.  */
+                           if (*(args+1) & SRC_IN_DST)
+                             abs = 2;
+
                            fprintf (stream, "#0x%x", (unsigned) abs);
                          }
                        else if (x & REG)
@@ -290,7 +339,10 @@ bfd_h8_disassemble (addr, info, hmode)
                    
                              }
                          }
-
+                       else if (x & MACREG)
+                         {
+                           fprintf (stream, "mac%c", abs ? 'l' : 'h');
+                         }
                        else if (x & INC)
                          {
                            fprintf (stream, "@%s+", pregnames[rs]);
@@ -306,7 +358,12 @@ bfd_h8_disassemble (addr, info, hmode)
                            fprintf (stream, "@%s", pregnames[rn]);
                          }
 
-                       else if (x & (ABS|ABSJMP|ABSMOV))
+                       else if (x & ABS8MEM)
+                         {
+                           fprintf (stream, "@0x%x:8", (unsigned) abs);
+                         }
+
+                       else if (x & (ABS|ABSJMP))
                          {
                            fprintf (stream, "@0x%x:%d", (unsigned) abs, plen);
                          }
@@ -318,8 +375,16 @@ bfd_h8_disassemble (addr, info, hmode)
 
                        else if (x & PCREL)
                          {
-                           fprintf (stream, ".%s%d (%x)", (char) abs > 0 ? "+" : "", (char) abs,
-                                    addr + (char) abs + 2);
+                           if (x & L_16) 
+                             {
+                               abs  +=2;
+                               fprintf (stream, ".%s%d (%x)", (short) abs > 0 ? "+" : "", (short) abs,
+                                        addr + (short) abs + 2);
+                             }
+                           else {
+                             fprintf (stream, ".%s%d (%x)", (char) abs > 0 ? "+" : "", (char) abs,
+                                      addr + (char) abs + 2);
+                           }
                          }
                        else if (x & DISP)
                          {
@@ -328,12 +393,15 @@ bfd_h8_disassemble (addr, info, hmode)
 
                        else if (x & CCR)
                          {
-
                            fprintf (stream, "ccr");
                          }
-
+                       else if (x & EXR)
+                         {
+                           fprintf (stream, "exr");
+                         }
                        else
-                         fprintf (stream, "Hmmmm %x", x);
+                         /* xgettext:c-format */
+                         fprintf (stream, _("Hmmmm %x"), x);
                        hadone = 1;
                        args++;
                      }
@@ -344,7 +412,8 @@ bfd_h8_disassemble (addr, info, hmode)
       
              else
                {
-                 fprintf (stream, "Dont understand %x \n", looking_for);
+                 /* xgettext:c-format */
+                 fprintf (stream, _("Don't understand %x \n"), looking_for);
                }
            }
          
@@ -371,7 +440,7 @@ disassemble_info *info;
   return bfd_h8_disassemble (addr, info , 0);
 }
 
- int 
+int 
 print_insn_h8300h (addr, info)
 bfd_vma addr;
 disassemble_info *info;
@@ -379,3 +448,10 @@ disassemble_info *info;
   return bfd_h8_disassemble (addr, info , 1);
 }
 
+int 
+print_insn_h8300s (addr, info)
+bfd_vma addr;
+disassemble_info *info;
+{
+  return bfd_h8_disassemble (addr, info , 2);
+}