]> Git Repo - binutils.git/blobdiff - gdb/h8300-tdep.c
* gdb/gdbserver/Makefile.in (docdir): Removed.
[binutils.git] / gdb / h8300-tdep.c
index 20f26cc4ca98253f23e54d8c88cf26d479b068c5..cf455d8500c2e02f0c530a121afb5667c05f7a4d 100644 (file)
@@ -15,7 +15,7 @@ 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.  */
 
 /*
  Contributed by Steve Chamberlain
@@ -26,9 +26,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "frame.h"
 #include "obstack.h"
 #include "symtab.h"
-#include <dis-asm.h>
+#include "dis-asm.h"
 #include "gdbcmd.h"
 #include "gdbtypes.h"
+#include "gdbcore.h"
+#include "gdb_string.h"
+#include "value.h"
+
 
 #undef NUM_REGS
 #define NUM_REGS 11
@@ -44,15 +48,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
  */
 
-#define IS_PUSH(x) ((x & 0xff00)==0x6d00)
+#define IS_PUSH(x) ((x & 0xfff0)==0x6df0)
 #define IS_PUSH_FP(x) (x == 0x6df6)
-#define IS_MOVE_FP(x) (x == 0x0d76)
-#define IS_MOV_SP_FP(x) (x == 0x0d76)
+#define IS_MOVE_FP(x) (x == 0x0d76 || x == 0x0ff6)
+#define IS_MOV_SP_FP(x) (x == 0x0d76 || x == 0x0ff6)
 #define IS_SUB2_SP(x) (x==0x1b87)
+#define IS_SUB4_SP(x) (x==0x1b97)
+#define IS_SUBL_SP(x) (x==0x7a37)
 #define IS_MOVK_R5(x) (x==0x7905)
 #define IS_SUB_R5SP(x) (x==0x1957)
 
+/* Local function declarations.  */
+
 static CORE_ADDR examine_prologue ();
+static void set_machine_hook PARAMS ((char *filename));
 
 void frame_find_saved_regs ();
 CORE_ADDR 
@@ -60,12 +69,19 @@ h8300_skip_prologue (start_pc)
      CORE_ADDR start_pc;
 {
   short int w;
+  int adjust = 0;
 
   w = read_memory_unsigned_integer (start_pc, 2);
+  if (w == 0x0100)
+    {
+      w = read_memory_unsigned_integer (start_pc + 2, 2);
+      adjust = 2;
+    }
+
   /* Skip past all push insns */
   while (IS_PUSH_FP (w))
     {
-      start_pc += 2;
+      start_pc += 2 + adjust;
       w = read_memory_unsigned_integer (start_pc, 2);
     }
 
@@ -88,26 +104,32 @@ h8300_skip_prologue (start_pc)
       start_pc += 2;
       w = read_memory_unsigned_integer (start_pc, 2);
     }
-  while (IS_SUB2_SP (w))
+  while (IS_SUB2_SP (w) || IS_SUB4_SP (w))
     {
       start_pc += 2;
       w = read_memory_unsigned_integer (start_pc, 2);
     }
 
+  if (IS_SUBL_SP (w))
+    start_pc += 6;
+
   return start_pc;
 }
 
 int
-print_insn (memaddr, stream)
-     CORE_ADDR memaddr;
-     GDB_FILE *stream;
+gdb_print_insn_h8300 (memaddr, info)
+     bfd_vma memaddr;
+     disassemble_info *info;
 {
-  disassemble_info info;
-  GDB_INIT_DISASSEMBLE_INFO(info, stream);
-  if (h8300hmode)
-    return print_insn_h8300h (memaddr, &info);
+/* start-sanitize-h8s */
+  if (h8300smode)
+    return print_insn_h8300s (memaddr, info);
   else
-    return print_insn_h8300 (memaddr, &info);
+/* end-sanitize-h8s */
+    if (h8300hmode)
+    return print_insn_h8300h (memaddr, info);
+  else
+    return print_insn_h8300 (memaddr, info);
 }
 
 /* Given a GDB frame, determine the address of the calling function's frame.
@@ -117,9 +139,9 @@ print_insn (memaddr, stream)
    For us, the frame address is its stack pointer value, so we look up
    the function prologue to determine the caller's sp value, and return it.  */
 
-FRAME_ADDR
-FRAME_CHAIN (thisframe)
-     FRAME thisframe;
+CORE_ADDR
+h8300_frame_chain (thisframe)
+     struct frame_info *thisframe;
 {
   frame_find_saved_regs (thisframe, (struct frame_saved_regs *) 0);
   return thisframe->fsr->regs[SP_REGNUM];
@@ -139,9 +161,6 @@ frame_find_saved_regs (fi, fsr)
      struct frame_info *fi;
      struct frame_saved_regs *fsr;
 {
-  register CORE_ADDR next_addr;
-  register CORE_ADDR *saved_regs;
-  register int regnum;
   register struct frame_saved_regs *cache_fsr;
   extern struct obstack frame_cache_obstack;
   CORE_ADDR ip;
@@ -208,18 +227,14 @@ static CORE_ADDR
 examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
      register CORE_ADDR ip;
      register CORE_ADDR limit;
-     FRAME_ADDR after_prolog_fp;
+     CORE_ADDR after_prolog_fp;
      struct frame_saved_regs *fsr;
      struct frame_info *fi;
 {
   register CORE_ADDR next_ip;
   int r;
-  int i;
   int have_fp = 0;
-  register int src;
-  register struct pic_prologue_code *pcode;
   INSN_WORD insn_word;
-  int size, offset;
   /* Number of things pushed onto stack, starts at 2/4, 'cause the
      PC is already there */
   unsigned int reg_save_depth = h8300hmode ? 4 : 2;
@@ -228,6 +243,8 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
 
   char in_frame[11];           /* One for each reg */
 
+  int adjust = 0;
+
   memset (in_frame, 1, 11);
   for (r = 0; r < 8; r++)
     {
@@ -237,20 +254,26 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
     {
       after_prolog_fp = read_register (SP_REGNUM);
     }
-  if (ip == 0 || ip & (h8300hmode ? ~0xffff : ~0xffff))
+  if (ip == 0 || ip & (h8300hmode ? ~0xffffff : ~0xffff))
     return 0;
 
   next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
 
+  if (insn_word == 0x0100)
+    {
+      insn_word = read_memory_unsigned_integer (ip + 2, 2);
+      adjust = 2;
+    }
+
   /* Skip over any fp push instructions */
   fsr->regs[6] = after_prolog_fp;
   while (next_ip && IS_PUSH_FP (insn_word))
     {
-      ip = next_ip;
+      ip = next_ip + adjust;
 
       in_frame[insn_word & 0x7] = reg_save_depth;
       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
-      reg_save_depth += 2;
+      reg_save_depth += 2 + adjust;
     }
 
   /* Is this a move into the fp */
@@ -264,11 +287,11 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
   /* Skip over any stack adjustment, happens either with a number of
      sub#2,sp or a mov #x,r5 sub r5,sp */
 
-  if (next_ip && IS_SUB2_SP (insn_word))
+  if (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word)))
     {
-      while (next_ip && IS_SUB2_SP (insn_word))
+      while (next_ip && (IS_SUB2_SP (insn_word) || IS_SUB4_SP (insn_word)))
        {
-         auto_depth += 2;
+         auto_depth += IS_SUB2_SP (insn_word) ? 2 : 4;
          ip = next_ip;
          next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
        }
@@ -284,7 +307,16 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
          next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn_word);
          auto_depth += insn_word;
        }
+      if (next_ip && IS_SUBL_SP (insn_word))
+       {
+         ip = next_ip;
+         auto_depth += read_memory_unsigned_integer (ip, 4);
+         ip += 4;
+
+         next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn_word);
+       }
     }
+
   /* Work out which regs are stored where */
   while (next_ip && IS_PUSH (insn_word))
     {
@@ -299,7 +331,7 @@ examine_prologue (ip, limit, after_prolog_fp, fsr, fi)
   /* Locals are always reffed based from the fp */
   fi->locals_pointer = after_prolog_fp;
   /* The PC is at a known place */
-  fi->from_pc = read_memory_unsigned_integer (after_prolog_fp + 2, BINWORD);
+  fi->from_pc = read_memory_unsigned_integer (after_prolog_fp + BINWORD, BINWORD);
 
   /* Rememeber any others too */
   in_frame[PC_REGNUM] = 0;
@@ -331,7 +363,7 @@ init_extra_frame_info (fromleaf, fi)
 
 CORE_ADDR
 frame_saved_pc (frame)
-     FRAME frame;
+     struct frame_info *frame;
 {
   return frame->from_pc;
 }
@@ -373,24 +405,23 @@ h8300_pop_frame ()
 {
   unsigned regnum;
   struct frame_saved_regs fsr;
-  struct frame_info *fi;
+  struct frame_info *frame = get_current_frame ();
 
-  FRAME frame = get_current_frame ();
-
-  fi = get_frame_info (frame);
-  get_frame_saved_regs (fi, &fsr);
+  get_frame_saved_regs (frame, &fsr);
 
   for (regnum = 0; regnum < 8; regnum++)
     {
-      if (fsr.regs[regnum])
-       {
-         write_register (regnum, read_memory_integer(fsr.regs[regnum]), BINWORD);
-       }
-
-      flush_cached_frames ();
-      set_current_frame (create_new_frame (read_register (FP_REGNUM),
-                                          read_pc ()));
+      /* Don't forget SP_REGNUM is a frame_saved_regs struct is the
+        actual value we want, not the address of the value we want.  */
+      if (fsr.regs[regnum] && regnum != SP_REGNUM)
+       write_register (regnum, read_memory_integer(fsr.regs[regnum], BINWORD));
+      else if (fsr.regs[regnum] && regnum == SP_REGNUM)
+       write_register (regnum, fsr.regs[regnum]);
     }
+
+  /* Don't forget the update the PC too!  */
+  write_pc (frame->from_pc);
+  flush_cached_frames ();
 }
 
 
@@ -401,6 +432,9 @@ h8300_command(args, from_tty)
 {
   extern int h8300hmode;
   h8300hmode = 0;
+/* start-sanitize-h8s */
+  h8300smode = 0;
+/* end-sanitize-h8s */
 }
 
 static void
@@ -408,17 +442,68 @@ h8300h_command(args, from_tty)
 {
   extern int h8300hmode;
   h8300hmode = 1;
+/* start-sanitize-h8s */
+  h8300smode = 0;
+/* end-sanitize-h8s */
 }
+/* start-sanitize-h8s */
+static void
+h8300s_command(args, from_tty)
+{
+  extern int h8300smode;
+  extern int h8300hmode;
+  h8300smode = 1;
+  h8300hmode = 1;
+}
+/* end-santiize-h8s */
+
 
 static void 
 set_machine (args, from_tty)
      char *args;
      int from_tty;
 {
-  printf_unfiltered ("\"set machine\" must be followed by h8300 or h8300h.\n");
+  printf_unfiltered ("\"set machine\" must be followed by h8300, h8300h");
+/* start-sanitize-h8s */
+  printf_unfiltered ("or h8300s");
+/* end-sanitize-h8s */
   help_list (setmemorylist, "set memory ", -1, gdb_stdout);
 }
 
+/* set_machine_hook is called as the exec file is being opened, but
+   before the symbol file is opened.  This allows us to set the
+   h8300hmode flag based on the machine type specified in the exec
+   file.  This in turn will cause subsequently defined pointer types
+   to be 16 or 32 bits as appropriate for the machine.  */
+
+static void
+set_machine_hook (filename)
+     char *filename;
+{
+/* start-sanitize-h8s */
+  if (bfd_get_mach (exec_bfd) == bfd_mach_h8300s)
+    {
+      h8300smode = 1;
+      h8300hmode = 1;
+    }
+  else 
+/* end-sanitize-h8s */
+    if (bfd_get_mach (exec_bfd) == bfd_mach_h8300h)
+    {
+/* start-sanitize-h8s */
+      h8300smode = 0;
+/* end-sanitize-h8s */
+      h8300hmode = 1;
+    }
+  else
+    {
+/* start-sanitize-h8s */
+      h8300smode = 0;
+/* end-sanitize-h8s */
+      h8300hmode = 0;
+    }
+}
+
 void
 _initialize_h8300m ()
 {
@@ -431,6 +516,15 @@ _initialize_h8300m ()
 
   add_cmd ("h8300h", class_support, h8300h_command,
           "Set machine to be H8/300H.", &setmemorylist);
+
+/* start-sanitize-h8s */
+  add_cmd ("h8300s", class_support, h8300s_command,
+          "Set machine to be H8/300S.", &setmemorylist);
+/* end-sanitize-h8s */
+
+  /* Add a hook to set the machine type when we're loading a file. */
+
+  specify_exec_file_hook(set_machine_hook);
 }
 
 
@@ -441,13 +535,11 @@ print_register_hook (regno)
   if (regno == 8)
     {
       /* CCR register */
-
       int C, Z, N, V;
-      unsigned char b[2];
+      unsigned char b[4];
       unsigned char l;
-
       read_relative_register_raw_bytes (regno, b);
-      l = b[1];
+      l = b[REGISTER_VIRTUAL_SIZE(8) -1];
       printf_unfiltered ("\t");
       printf_unfiltered ("I-%d - ", (l & 0x80) != 0);
       printf_unfiltered ("H-%d - ", (l & 0x20) != 0);
@@ -482,3 +574,8 @@ print_register_hook (regno)
     }
 }
 
+void
+_initialize_h8300_tdep ()
+{
+  tm_print_insn = gdb_print_insn_h8300;
+}
This page took 0.034331 seconds and 4 git commands to generate.