2004-05-08 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / mcore-tdep.c
index 22dbf508082b38f3cdf3caf21bee39d21e87b7b0..50aa2c5580cf47ad700249711aed6a811d84dd8f 100644 (file)
@@ -1,5 +1,7 @@
 /* Target-machine dependent code for Motorola MCore for GDB, the GNU debugger
-   Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
+
+   Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software
+   Foundation, Inc.
 
    This file is part of GDB.
 
 #include "value.h"
 #include "gdbcmd.h"
 #include "regcache.h"
-#include "symfile.h"
+#include "objfiles.h"
 #include "gdbcore.h"
 #include "inferior.h"
+#include "arch-utils.h"
+#include "gdb_string.h"
+#include "disasm.h"
+#include "dis-asm.h"
 
-/* Functions declared and used only in this file */
-
-static CORE_ADDR mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue);
-
-static struct frame_info *analyze_dummy_frame (CORE_ADDR pc, CORE_ADDR frame);
-
+static CORE_ADDR mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc,
+                                        int skip_prologue);
 static int get_insn (CORE_ADDR pc);
 
-/* Functions exported from this file */
-
-int mcore_use_struct_convention (int gcc_p, struct type *type);
-
-void _initialize_mcore (void);
-
-void mcore_init_extra_frame_info (struct frame_info *fi);
-
-CORE_ADDR mcore_frame_saved_pc (struct frame_info *fi);
-
-CORE_ADDR mcore_find_callers_reg (struct frame_info *fi, int regnum);
-
-CORE_ADDR mcore_frame_args_address (struct frame_info *fi);
-
-CORE_ADDR mcore_frame_locals_address (struct frame_info *fi);
-
-void mcore_virtual_frame_pointer (CORE_ADDR pc, long *reg, long *offset);
-
-CORE_ADDR mcore_push_return_address (CORE_ADDR pc, CORE_ADDR sp);
-
-CORE_ADDR mcore_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
-                       unsigned char struct_return, CORE_ADDR struct_addr);
-
-void mcore_pop_frame (struct frame_info *fi);
-
-CORE_ADDR mcore_skip_prologue (CORE_ADDR pc);
-
-CORE_ADDR mcore_frame_chain (struct frame_info *fi);
-
-unsigned char *mcore_breakpoint_from_pc (CORE_ADDR * bp_addr, int *bp_size);
-
-int mcore_use_struct_convention (int gcc_p, struct type *type);
-
-void mcore_store_return_value (struct type *type, char *valbuf);
-
-CORE_ADDR mcore_extract_struct_value_address (char *regbuf);
-
-void mcore_extract_return_value (struct type *type, char *regbuf, char *valbuf);
-
 #ifdef MCORE_DEBUG
 int mcore_debug = 0;
 #endif
 
-/* The registers of the Motorola MCore processors */
-/* *INDENT-OFF* */
-char *mcore_register_names[] =
-{ "r0",   "r1",  "r2",    "r3",   "r4",   "r5",   "r6",   "r7",
-  "r8",   "r9",  "r10",   "r11",  "r12",  "r13",  "r14",  "r15",
-  "ar0",  "ar1", "ar2",   "ar3",  "ar4",  "ar5",  "ar6",  "ar7",
-  "ar8",  "ar9", "ar10", "ar11",  "ar12", "ar13", "ar14", "ar15",
-  "psr",  "vbr", "epsr",  "fpsr", "epc",  "fpc",  "ss0",  "ss1",
-  "ss2",  "ss3", "ss4",   "gcr",  "gsr",  "cr13", "cr14", "cr15",
-  "cr16", "cr17", "cr18", "cr19", "cr20", "cr21", "cr22", "cr23",
-  "cr24", "cr25", "cr26", "cr27", "cr28", "cr29", "cr30", "cr31",
-  "pc" };
-/* *INDENT-ON* */
 
+/* All registers are 4 bytes long.  */
+#define MCORE_REG_SIZE 4
+#define MCORE_NUM_REGS 65
 
+/* Some useful register numbers.  */
+#define PR_REGNUM 15
+#define FIRST_ARGREG 2
+#define LAST_ARGREG 7
+#define RETVAL_REGNUM 2
 
+  
 /* Additional info that we use for managing frames */
 struct frame_extra_info
   {
@@ -167,7 +126,7 @@ mcore_dump_insn (char *commnt, CORE_ADDR pc, int insn)
     {
       printf_filtered ("MCORE:  %s %08x %08x ",
                       commnt, (unsigned int) pc, (unsigned int) insn);
-      (*tm_print_insn) (pc, &tm_print_insn_info);
+      gdb_print_insn (pc, gdb_stdout);
       printf_filtered ("\n");
     }
 }
@@ -177,6 +136,68 @@ mcore_dump_insn (char *commnt, CORE_ADDR pc, int insn)
 #define mcore_insn_debug(args) {}
 #endif
 
+
+static struct type *
+mcore_register_virtual_type (int regnum)
+{
+  if (regnum < 0 || regnum >= MCORE_NUM_REGS)
+    internal_error (__FILE__, __LINE__,
+                   "mcore_register_virtual_type: illegal register number %d",
+                   regnum);
+  else
+    return builtin_type_int;
+}
+
+static int
+mcore_register_byte (int regnum)
+{
+  if (regnum < 0 || regnum >= MCORE_NUM_REGS)
+    internal_error (__FILE__, __LINE__,
+                   "mcore_register_byte: illegal register number %d",
+                   regnum);
+  else 
+    return (regnum * MCORE_REG_SIZE);
+}
+
+static int
+mcore_register_size (int regnum)
+{
+  
+  if (regnum < 0 || regnum >= MCORE_NUM_REGS)
+    internal_error (__FILE__, __LINE__,
+                   "mcore_register_size: illegal register number %d",
+                   regnum);
+  else
+    return MCORE_REG_SIZE;
+}
+
+/* The registers of the Motorola MCore processors */
+
+static const char *
+mcore_register_name (int regnum)
+{
+
+  static char *register_names[] = { 
+    "r0",   "r1",  "r2",    "r3",   "r4",   "r5",   "r6",   "r7",
+    "r8",   "r9",  "r10",   "r11",  "r12",  "r13",  "r14",  "r15",
+    "ar0",  "ar1", "ar2",   "ar3",  "ar4",  "ar5",  "ar6",  "ar7",
+    "ar8",  "ar9", "ar10", "ar11",  "ar12", "ar13", "ar14", "ar15",
+    "psr",  "vbr", "epsr",  "fpsr", "epc",  "fpc",  "ss0",  "ss1",
+    "ss2",  "ss3", "ss4",   "gcr",  "gsr",  "cr13", "cr14", "cr15",
+    "cr16", "cr17", "cr18", "cr19", "cr20", "cr21", "cr22", "cr23",
+    "cr24", "cr25", "cr26", "cr27", "cr28", "cr29", "cr30", "cr31",
+    "pc" 
+  };
+
+  if (regnum < 0 ||
+      regnum >= sizeof (register_names) / sizeof (register_names[0]))
+    internal_error (__FILE__, __LINE__,
+                   "mcore_register_name: illegal register number %d",
+                   regnum);
+  else
+    return register_names[regnum];
+}
+
 /* Given the address at which to insert a breakpoint (BP_ADDR),
    what will that breakpoint be?
 
@@ -184,7 +205,7 @@ mcore_dump_insn (char *commnt, CORE_ADDR pc, int insn)
    instructions are 16 bits, this is all we need, regardless of
    address. bpkt = 0x0000 */
 
-unsigned char *
+static const unsigned char *
 mcore_breakpoint_from_pc (CORE_ADDR * bp_addr, int *bp_size)
 {
   static char breakpoint[] =
@@ -193,6 +214,33 @@ mcore_breakpoint_from_pc (CORE_ADDR * bp_addr, int *bp_size)
   return breakpoint;
 }
 
+static CORE_ADDR
+mcore_saved_pc_after_call (struct frame_info *frame)
+{
+  return read_register (PR_REGNUM);
+}
+
+/* This is currently handled by init_extra_frame_info.  */
+static void
+mcore_frame_init_saved_regs (struct frame_info *frame)
+{
+
+}
+
+/* This is currently handled by mcore_push_arguments  */
+static void
+mcore_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
+{
+
+}
+
+static int
+mcore_reg_struct_has_addr (int gcc_p, struct type *type)
+{
+  return 0;
+}
+
+
 /* Helper function for several routines below.  This funtion simply
    sets up a fake, aka dummy, frame (not a _call_ dummy frame) that
    we can analyze with mcore_analyze_prologue. */
@@ -200,24 +248,16 @@ mcore_breakpoint_from_pc (CORE_ADDR * bp_addr, int *bp_size)
 static struct frame_info *
 analyze_dummy_frame (CORE_ADDR pc, CORE_ADDR frame)
 {
-  static struct frame_info *dummy = NULL;
-
-  if (dummy == NULL)
-    {
-      dummy = (struct frame_info *) xmalloc (sizeof (struct frame_info));
-      dummy->saved_regs = (CORE_ADDR *) xmalloc (SIZEOF_FRAME_SAVED_REGS);
-      dummy->extra_info =
-       (struct frame_extra_info *) xmalloc (sizeof (struct frame_extra_info));
-    }
-
-  dummy->next = NULL;
-  dummy->prev = NULL;
-  dummy->pc = pc;
-  dummy->frame = frame;
-  dummy->extra_info->status = 0;
-  dummy->extra_info->framesize = 0;
-  memset (dummy->saved_regs, '\000', SIZEOF_FRAME_SAVED_REGS);
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+  struct frame_info *dummy
+    = deprecated_frame_xmalloc_with_cleanup (SIZEOF_FRAME_SAVED_REGS,
+                                            sizeof (struct frame_extra_info));
+  deprecated_update_frame_pc_hack (dummy, pc);
+  deprecated_update_frame_base_hack (dummy, frame);
+  get_frame_extra_info (dummy)->status = 0;
+  get_frame_extra_info (dummy)->framesize = 0;
   mcore_analyze_prologue (dummy, 0, 0);
+  do_cleanups (old_chain);
   return dummy;
 }
 
@@ -260,7 +300,7 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
 
   /* If provided, use the PC in the frame to look up the
      start of this function. */
-  pc = (fi == NULL ? pc : fi->pc);
+  pc = (fi == NULL ? pc : get_frame_pc (fi));
 
   /* Find the start of this function. */
   status = find_pc_partial_function (pc, &name, &func_addr, &func_end);
@@ -274,7 +314,7 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
   if (func_addr == entry_point_address ())
     {
       if (fi != NULL)
-       fi->extra_info->status |= NO_MORE_FRAMES;
+       get_frame_extra_info (fi)->status |= NO_MORE_FRAMES;
       return pc;
     }
 
@@ -299,21 +339,21 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
   if (fi != NULL && IS_RTS (insn))
     {
       mcore_insn_debug (("MCORE: got jmp r15"));
-      if (fi->next == NULL)
-       fi->frame = read_sp ();
-      return fi->pc;
+      if (get_next_frame (fi) == NULL)
+       deprecated_update_frame_base_hack (fi, read_sp ());
+      return get_frame_pc (fi);
     }
 
   /* Check for first insn of prologue */
-  if (fi != NULL && fi->pc == func_addr)
+  if (fi != NULL && get_frame_pc (fi) == func_addr)
     {
-      if (fi->next == NULL)
-       fi->frame = read_sp ();
-      return fi->pc;
+      if (get_next_frame (fi) == NULL)
+       deprecated_update_frame_base_hack (fi, read_sp ());
+      return get_frame_pc (fi);
     }
 
   /* Figure out where to stop scanning */
-  stop = (fi ? fi->pc : func_end);
+  stop = (fi ? get_frame_pc (fi) : func_end);
 
   /* Don't walk off the end of the function */
   stop = (stop > func_end ? func_end : stop);
@@ -520,19 +560,19 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
   /* Save everything we have learned about this frame into FI. */
   if (fi != NULL)
     {
-      fi->extra_info->framesize = framesize;
-      fi->extra_info->fp_regnum = fp_regnum;
-      fi->extra_info->status = flags;
+      get_frame_extra_info (fi)->framesize = framesize;
+      get_frame_extra_info (fi)->fp_regnum = fp_regnum;
+      get_frame_extra_info (fi)->status = flags;
 
       /* Fix the frame pointer. When gcc uses r8 as a frame pointer,
          it is really an arg ptr. We adjust fi->frame to be a "real"
          frame pointer. */
-      if (fi->next == NULL)
+      if (get_next_frame (fi) == NULL)
        {
-         if (fi->extra_info->status & MY_FRAME_IN_SP)
-           fi->frame = read_sp () + framesize;
+         if (get_frame_extra_info (fi)->status & MY_FRAME_IN_SP)
+           deprecated_update_frame_base_hack (fi, read_sp () + framesize);
          else
-           fi->frame = read_register (fp_regnum) + framesize;
+           deprecated_update_frame_base_hack (fi, read_register (fp_regnum) + framesize);
        }
 
       /* Note where saved registers are stored. The offsets in REGISTER_OFFSETS
@@ -541,7 +581,7 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
        {
          if (register_offsets[rn] >= 0)
            {
-             fi->saved_regs[rn] = fi->frame - register_offsets[rn];
+             deprecated_get_frame_saved_regs (fi)[rn] = get_frame_base (fi) - register_offsets[rn];
              mcore_insn_debug (("Saved register %s stored at 0x%08x, value=0x%08x\n",
                               mcore_register_names[rn], fi->saved_regs[rn],
                              read_memory_integer (fi->saved_regs[rn], 4)));
@@ -553,22 +593,23 @@ mcore_analyze_prologue (struct frame_info *fi, CORE_ADDR pc, int skip_prologue)
   return addr;
 }
 
-/* Given a GDB frame, determine the address of the calling function's frame.
-   This will be used to create a new GDB frame struct, and then
-   INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. */
+/* Given a GDB frame, determine the address of the calling function's
+   frame.  This will be used to create a new GDB frame struct, and
+   then DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC
+   will be called for the new frame. */
 
-CORE_ADDR
+static CORE_ADDR
 mcore_frame_chain (struct frame_info * fi)
 {
   struct frame_info *dummy;
   CORE_ADDR callers_addr;
 
   /* Analyze the prologue of this function. */
-  if (fi->extra_info->status == 0)
+  if (get_frame_extra_info (fi)->status == 0)
     mcore_analyze_prologue (fi, 0, 0);
 
   /* If mcore_analyze_prologue set NO_MORE_FRAMES, quit now. */
-  if (fi->extra_info->status & NO_MORE_FRAMES)
+  if (get_frame_extra_info (fi)->status & NO_MORE_FRAMES)
     return 0;
 
   /* Now that we've analyzed our prologue, we can start to ask
@@ -582,31 +623,32 @@ mcore_frame_chain (struct frame_info * fi)
 
      If our caller does not have a frame pointer, then his frame base
      is <our base> + -<caller's frame size>. */
-  dummy = analyze_dummy_frame (FRAME_SAVED_PC (fi), fi->frame);
+  dummy = analyze_dummy_frame (DEPRECATED_FRAME_SAVED_PC (fi), get_frame_base (fi));
 
-  if (dummy->extra_info->status & MY_FRAME_IN_FP)
+  if (get_frame_extra_info (dummy)->status & MY_FRAME_IN_FP)
     {
-      int fp = dummy->extra_info->fp_regnum;
+      int fp = get_frame_extra_info (dummy)->fp_regnum;
 
       /* Our caller has a frame pointer. */
-      if (fi->saved_regs[fp] != 0)
+      if (deprecated_get_frame_saved_regs (fi)[fp] != 0)
        {
          /* The "FP" was saved on the stack.  Don't forget to adjust
             the "FP" with the framesize to get a real FP. */
-         callers_addr = read_memory_integer (fi->saved_regs[fp], REGISTER_SIZE)
-           + dummy->extra_info->framesize;
+         callers_addr = read_memory_integer (deprecated_get_frame_saved_regs (fi)[fp],
+                                             DEPRECATED_REGISTER_SIZE)
+           + get_frame_extra_info (dummy)->framesize;
        }
       else
        {
          /* It's still in the register.  Don't forget to adjust
             the "FP" with the framesize to get a real FP. */
-         callers_addr = read_register (fp) + dummy->extra_info->framesize;
+         callers_addr = read_register (fp) + get_frame_extra_info (dummy)->framesize;
        }
     }
   else
     {
       /* Our caller does not have a frame pointer. */
-      callers_addr = fi->frame + dummy->extra_info->framesize;
+      callers_addr = get_frame_base (fi) + get_frame_extra_info (dummy)->framesize;
     }
 
   return callers_addr;
@@ -614,7 +656,7 @@ mcore_frame_chain (struct frame_info * fi)
 
 /* Skip the prologue of the function at PC. */
 
-CORE_ADDR
+static CORE_ADDR
 mcore_skip_prologue (CORE_ADDR pc)
 {
   CORE_ADDR func_addr, func_end;
@@ -634,48 +676,50 @@ mcore_skip_prologue (CORE_ADDR pc)
 }
 
 /* Return the address at which function arguments are offset. */
-CORE_ADDR
+static CORE_ADDR
 mcore_frame_args_address (struct frame_info * fi)
 {
-  return fi->frame - fi->extra_info->framesize;
+  return get_frame_base (fi) - get_frame_extra_info (fi)->framesize;
 }
 
-CORE_ADDR
+static CORE_ADDR
 mcore_frame_locals_address (struct frame_info * fi)
 {
-  return fi->frame - fi->extra_info->framesize;
+  return get_frame_base (fi) - get_frame_extra_info (fi)->framesize;
 }
 
 /* Return the frame pointer in use at address PC. */
 
-void
-mcore_virtual_frame_pointer (CORE_ADDR pc, long *reg, long *offset)
+static void
+mcore_virtual_frame_pointer (CORE_ADDR pc, int *reg, LONGEST *offset)
 {
   struct frame_info *dummy = analyze_dummy_frame (pc, 0);
-  if (dummy->extra_info->status & MY_FRAME_IN_SP)
+  if (get_frame_extra_info (dummy)->status & MY_FRAME_IN_SP)
     {
       *reg = SP_REGNUM;
       *offset = 0;
     }
   else
     {
-      *reg = dummy->extra_info->fp_regnum;
+      *reg = get_frame_extra_info (dummy)->fp_regnum;
       *offset = 0;
     }
 }
 
 /* Find the value of register REGNUM in frame FI. */
 
-CORE_ADDR
+static CORE_ADDR
 mcore_find_callers_reg (struct frame_info *fi, int regnum)
 {
-  for (; fi != NULL; fi = fi->next)
+  for (; fi != NULL; fi = get_next_frame (fi))
     {
-      if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
-       return generic_read_register_dummy (fi->pc, fi->frame, regnum);
-      else if (fi->saved_regs[regnum] != 0)
-       return read_memory_integer (fi->saved_regs[regnum],
-                                   REGISTER_SIZE);
+      if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
+                                      get_frame_base (fi)))
+       return deprecated_read_register_dummy (get_frame_pc (fi),
+                                              get_frame_base (fi), regnum);
+      else if (deprecated_get_frame_saved_regs (fi)[regnum] != 0)
+       return read_memory_integer (deprecated_get_frame_saved_regs (fi)[regnum],
+                                   DEPRECATED_REGISTER_SIZE);
     }
 
   return read_register (regnum);
@@ -683,12 +727,14 @@ mcore_find_callers_reg (struct frame_info *fi, int regnum)
 
 /* Find the saved pc in frame FI. */
 
-CORE_ADDR
+static CORE_ADDR
 mcore_frame_saved_pc (struct frame_info * fi)
 {
 
-  if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
-    return generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
+  if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
+                                  get_frame_base (fi)))
+    return deprecated_read_register_dummy (get_frame_pc (fi),
+                                          get_frame_base (fi), PC_REGNUM);
   else
     return mcore_find_callers_reg (fi, PR_REGNUM);
 }
@@ -698,33 +744,35 @@ mcore_frame_saved_pc (struct frame_info * fi)
 /* This routine gets called when either the user uses the "return"
    command, or the call dummy breakpoint gets hit. */
 
-void
-mcore_pop_frame (struct frame_info *fi)
+static void
+mcore_pop_frame (void)
 {
   int rn;
+  struct frame_info *fi = get_current_frame ();
 
-  if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
-    generic_pop_dummy_frame ();
+  if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
+                                  get_frame_base (fi)))
+    deprecated_pop_dummy_frame ();
   else
     {
       /* Write out the PC we saved. */
-      write_register (PC_REGNUM, FRAME_SAVED_PC (fi));
+      write_register (PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (fi));
 
       /* Restore any saved registers. */
       for (rn = 0; rn < NUM_REGS; rn++)
        {
-         if (fi->saved_regs[rn] != 0)
+         if (deprecated_get_frame_saved_regs (fi)[rn] != 0)
            {
              ULONGEST value;
 
-             value = read_memory_unsigned_integer (fi->saved_regs[rn],
-                                                   REGISTER_SIZE);
+             value = read_memory_unsigned_integer (deprecated_get_frame_saved_regs (fi)[rn],
+                                                   DEPRECATED_REGISTER_SIZE);
              write_register (rn, value);
            }
        }
 
       /* Actually cut back the stack. */
-      write_register (SP_REGNUM, FRAME_FP (fi));
+      write_register (SP_REGNUM, get_frame_base (fi));
     }
 
   /* Finally, throw away any cached frame information. */
@@ -734,9 +782,9 @@ mcore_pop_frame (struct frame_info *fi)
 /* Setup arguments and PR for a call to the target. First six arguments
    go in FIRST_ARGREG -> LAST_ARGREG, subsequent args go on to the stack.
 
-   * Types with lengths greater than REGISTER_SIZE may not be split
-   between registers and the stack, and they must start in an even-numbered
-   register. Subsequent args will go onto the stack.
+   - Types with lengths greater than DEPRECATED_REGISTER_SIZE may not
+   be split between registers and the stack, and they must start in an
+   even-numbered register. Subsequent args will go onto the stack.
 
    * Structs may be split between registers and stack, left-aligned.
 
@@ -746,9 +794,9 @@ mcore_pop_frame (struct frame_info *fi)
    FIRST_ARGREG, since the MCORE treats struct returns (of less than eight
    bytes) as hidden first arguments. */
 
-CORE_ADDR
-mcore_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
-                     unsigned char struct_return, CORE_ADDR struct_addr)
+static CORE_ADDR
+mcore_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
+                     int struct_return, CORE_ADDR struct_addr)
 {
   int argreg;
   int argnum;
@@ -788,21 +836,21 @@ mcore_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
          numbered register. */
       olen = len;
 
-      if (TYPE_CODE (type) != TYPE_CODE_STRUCT && len > REGISTER_SIZE && argreg % 2)
+      if (TYPE_CODE (type) != TYPE_CODE_STRUCT && len > DEPRECATED_REGISTER_SIZE && argreg % 2)
        {
-         mcore_insn_debug (("MCORE PUSH: %d > REGISTER_SIZE: and %s is not even\n",
+         mcore_insn_debug (("MCORE PUSH: %d > DEPRECATED_REGISTER_SIZE: and %s is not even\n",
                             len, mcore_register_names[argreg]));
          argreg++;
        }
 
-      if ((argreg <= LAST_ARGREG && len <= (LAST_ARGREG - argreg + 1) * REGISTER_SIZE)
+      if ((argreg <= LAST_ARGREG && len <= (LAST_ARGREG - argreg + 1) * DEPRECATED_REGISTER_SIZE)
          || (TYPE_CODE (type) == TYPE_CODE_STRUCT))
        {
          /* Something that will fit entirely into registers (or a struct
             which may be split between registers and stack). */
          mcore_insn_debug (("MCORE PUSH: arg %d going into regs\n", argnum));
 
-         if (TYPE_CODE (type) == TYPE_CODE_STRUCT && olen < REGISTER_SIZE)
+         if (TYPE_CODE (type) == TYPE_CODE_STRUCT && olen < DEPRECATED_REGISTER_SIZE)
            {
              /* Small structs must be right aligned within the register,
                 the most significant bits are undefined. */
@@ -813,16 +861,16 @@ mcore_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
 
          while (len > 0 && argreg <= LAST_ARGREG)
            {
-             write_register (argreg, extract_unsigned_integer (val, REGISTER_SIZE));
+             write_register (argreg, extract_unsigned_integer (val, DEPRECATED_REGISTER_SIZE));
              argreg++;
-             val += REGISTER_SIZE;
-             len -= REGISTER_SIZE;
+             val += DEPRECATED_REGISTER_SIZE;
+             len -= DEPRECATED_REGISTER_SIZE;
            }
 
          /* Any remainder for the stack is noted below... */
        }
       else if (TYPE_CODE (VALUE_TYPE (args[argnum])) != TYPE_CODE_STRUCT
-              && len > REGISTER_SIZE)
+              && len > DEPRECATED_REGISTER_SIZE)
        {
          /* All subsequent args go onto the stack. */
          mcore_insn_debug (("MCORE PUSH: does not fit into regs, going onto stack\n"));
@@ -852,14 +900,14 @@ mcore_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
   return sp;
 }
 
-/* Store the return address for the call dummy. For MCore, we've
-   opted to use generic call dummies, so we simply store the
-   CALL_DUMMY_ADDRESS into the PR register (r15). */
+/* Store the return address for the call dummy. For MCore, we've opted
+   to use generic call dummies, so we simply store the entry-point
+   address into the PR register (r15). */
 
-CORE_ADDR
+static CORE_ADDR
 mcore_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
 {
-  write_register (PR_REGNUM, CALL_DUMMY_ADDRESS ());
+  write_register (PR_REGNUM, entry_point_address ());
   return sp;
 }
 
@@ -871,44 +919,31 @@ mcore_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
    argument.
 
    For gdb, this leaves us two routes, based on what
-   USE_STRUCT_CONVENTION (mcore_use_struct_convention) returns.
-   If this macro returns 1, gdb will call STORE_STRUCT_RETURN and
-   EXTRACT_STRUCT_VALUE_ADDRESS.
+   USE_STRUCT_CONVENTION (mcore_use_struct_convention) returns.  If
+   this macro returns 1, gdb will call STORE_STRUCT_RETURN to store
+   the return value.
 
-   If USE_STRUCT_CONVENTION retruns 0, then gdb uses STORE_RETURN_VALUE
-   and EXTRACT_RETURN_VALUE to store/fetch the functions return value. */
+   If USE_STRUCT_CONVENTION returns 0, then gdb uses
+   STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE to store/fetch the
+   functions return value.  */
 
-/* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of
-   EXTRACT_RETURN_VALUE?  GCC_P is true if compiled with gcc
-   and TYPE is the type (which is known to be struct, union or array). */
-
-int
+static int
 mcore_use_struct_convention (int gcc_p, struct type *type)
 {
   return (TYPE_LENGTH (type) > 8);
 }
 
-/* Where is the return value saved? For MCore, a pointer to 
-   this buffer was passed as a hidden first argument, so
-   just return that address. */
-
-CORE_ADDR
-mcore_extract_struct_value_address (char *regbuf)
-{
-  return extract_address (regbuf + REGISTER_BYTE (FIRST_ARGREG), REGISTER_SIZE);
-}
-
 /* Given a function which returns a value of type TYPE, extract the
    the function's return value and place the result into VALBUF.
    REGBUF is the register contents of the target. */
 
-void
+static void
 mcore_extract_return_value (struct type *type, char *regbuf, char *valbuf)
 {
   /* Copy the return value (starting) in RETVAL_REGNUM to VALBUF. */
   /* Only getting the first byte! if len = 1, we need the last byte of
      the register, not the first. */
-  memcpy (valbuf, regbuf + REGISTER_BYTE (RETVAL_REGNUM) +
+  memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (RETVAL_REGNUM) +
   (TYPE_LENGTH (type) < 4 ? 4 - TYPE_LENGTH (type) : 0), TYPE_LENGTH (type));
 }
 
@@ -922,7 +957,7 @@ mcore_extract_return_value (struct type *type, char *regbuf, char *valbuf)
    significant word) and r3 (least significant word, left justified).
    Note that this includes structures of less than eight bytes, too. */
 
-void
+static void
 mcore_store_return_value (struct type *type, char *valbuf)
 {
   int value_size;
@@ -933,13 +968,14 @@ mcore_store_return_value (struct type *type, char *valbuf)
   value_size = TYPE_LENGTH (type);
 
   /* Return value fits into registers. */
-  return_size = (value_size + REGISTER_SIZE - 1) & ~(REGISTER_SIZE - 1);
-  offset = REGISTER_BYTE (RETVAL_REGNUM) + (return_size - value_size);
+  return_size = (value_size + DEPRECATED_REGISTER_SIZE - 1) & ~(DEPRECATED_REGISTER_SIZE - 1);
+  offset = DEPRECATED_REGISTER_BYTE (RETVAL_REGNUM) + (return_size - value_size);
   zeros = alloca (return_size);
   memset (zeros, 0, return_size);
 
-  write_register_bytes (REGISTER_BYTE (RETVAL_REGNUM), zeros, return_size);
-  write_register_bytes (offset, valbuf, value_size);
+  deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (RETVAL_REGNUM), zeros,
+                                  return_size);
+  deprecated_write_register_bytes (offset, valbuf, value_size);
 }
 
 /* Initialize our target-dependent "stuff" for this newly created frame.
@@ -947,24 +983,24 @@ mcore_store_return_value (struct type *type, char *valbuf)
    This includes allocating space for saved registers and analyzing
    the prologue of this frame. */
 
-void
-mcore_init_extra_frame_info (struct frame_info *fi)
+static void
+mcore_init_extra_frame_info (int fromleaf, struct frame_info *fi)
 {
-  if (fi->next)
-    fi->pc = FRAME_SAVED_PC (fi->next);
+  if (fi && get_next_frame (fi))
+    deprecated_update_frame_pc_hack (fi, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi)));
 
   frame_saved_regs_zalloc (fi);
 
-  fi->extra_info = (struct frame_extra_info *)
-    frame_obstack_alloc (sizeof (struct frame_extra_info));
-  fi->extra_info->status = 0;
-  fi->extra_info->framesize = 0;
+  frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
+  get_frame_extra_info (fi)->status = 0;
+  get_frame_extra_info (fi)->framesize = 0;
 
-  if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
+  if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
+                                  get_frame_base (fi)))
     {
-      /* We need to setup fi->frame here because run_stack_dummy gets it wrong
-         by assuming it's always FP.  */
-      fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
+      /* We need to setup fi->frame here because call_function_by_hand
+         gets it wrong by assuming it's always FP.  */
+      deprecated_update_frame_base_hack (fi, deprecated_read_register_dummy (get_frame_pc (fi), get_frame_base (fi), SP_REGNUM));
     }
   else
     mcore_analyze_prologue (fi, 0, 0);
@@ -983,11 +1019,94 @@ get_insn (CORE_ADDR pc)
   return extract_unsigned_integer (buf, 2);
 }
 
+static struct gdbarch *
+mcore_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
+{
+  struct gdbarch_tdep *tdep = NULL;
+  struct gdbarch *gdbarch;
+
+  /* find a candidate among the list of pre-declared architectures. */
+  arches = gdbarch_list_lookup_by_info (arches, &info);
+  if (arches != NULL)
+    return (arches->gdbarch);
+
+  gdbarch = gdbarch_alloc (&info, 0);
+
+  /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
+     ready to unwind the PC first (see frame.c:get_prev_frame()).  */
+  set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
+
+  /* Registers: */
+
+  /* All registers are 32 bits */
+  set_gdbarch_deprecated_register_size (gdbarch, MCORE_REG_SIZE);
+  set_gdbarch_deprecated_max_register_raw_size (gdbarch, MCORE_REG_SIZE);
+  set_gdbarch_deprecated_max_register_virtual_size (gdbarch, MCORE_REG_SIZE);
+  set_gdbarch_register_name (gdbarch, mcore_register_name);
+  set_gdbarch_deprecated_register_virtual_type (gdbarch, mcore_register_virtual_type);
+  set_gdbarch_deprecated_register_virtual_size (gdbarch, mcore_register_size);
+  set_gdbarch_deprecated_register_raw_size (gdbarch, mcore_register_size);
+  set_gdbarch_deprecated_register_byte (gdbarch, mcore_register_byte);
+  set_gdbarch_deprecated_register_bytes (gdbarch, MCORE_REG_SIZE * MCORE_NUM_REGS);
+  set_gdbarch_num_regs (gdbarch, MCORE_NUM_REGS);
+  set_gdbarch_pc_regnum (gdbarch, 64);
+  set_gdbarch_sp_regnum (gdbarch, 0);
+  set_gdbarch_deprecated_fp_regnum (gdbarch, 0);
+
+  /* Call Dummies:  */
+
+  set_gdbarch_deprecated_saved_pc_after_call (gdbarch, mcore_saved_pc_after_call);
+  set_gdbarch_breakpoint_from_pc (gdbarch, mcore_breakpoint_from_pc);
+  set_gdbarch_deprecated_push_return_address (gdbarch, mcore_push_return_address);
+  set_gdbarch_deprecated_push_arguments (gdbarch, mcore_push_arguments);
+
+  /* Frames:  */
+
+  set_gdbarch_deprecated_init_extra_frame_info (gdbarch, mcore_init_extra_frame_info);
+  set_gdbarch_deprecated_frame_chain (gdbarch, mcore_frame_chain);
+  set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, mcore_frame_init_saved_regs);
+  set_gdbarch_deprecated_frame_saved_pc (gdbarch, mcore_frame_saved_pc);
+  set_gdbarch_deprecated_store_return_value (gdbarch, mcore_store_return_value);
+  set_gdbarch_deprecated_extract_return_value (gdbarch, 
+                                              mcore_extract_return_value);
+  set_gdbarch_deprecated_store_struct_return (gdbarch, mcore_store_struct_return);
+  set_gdbarch_skip_prologue (gdbarch, mcore_skip_prologue);
+  set_gdbarch_deprecated_frame_args_address (gdbarch, mcore_frame_args_address);
+  set_gdbarch_deprecated_frame_locals_address (gdbarch, mcore_frame_locals_address);
+  set_gdbarch_deprecated_pop_frame (gdbarch, mcore_pop_frame);
+  set_gdbarch_virtual_frame_pointer (gdbarch, mcore_virtual_frame_pointer);
+
+  /* Misc.:  */
+
+  /* Stack grows down.  */
+  set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
+  set_gdbarch_use_struct_convention (gdbarch, mcore_use_struct_convention);
+  set_gdbarch_believe_pcc_promotion (gdbarch, 1);
+  /* MCore will never pass a sturcture by reference. It will always be split
+     between registers and stack.  */
+  set_gdbarch_deprecated_reg_struct_has_addr
+    (gdbarch, mcore_reg_struct_has_addr);
+
+  /* Should be using push_dummy_call.  */
+  set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
+
+  set_gdbarch_print_insn (gdbarch, print_insn_mcore);
+
+  return gdbarch;
+}
+
+static void
+mcore_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
+{
+
+}
+
+extern initialize_file_ftype _initialize_mcore_tdep; /* -Wmissing-prototypes */
+
 void
 _initialize_mcore_tdep (void)
 {
-  extern int print_insn_mcore (bfd_vma, disassemble_info *);
-  tm_print_insn = print_insn_mcore;
+  gdbarch_register (bfd_arch_mcore, mcore_gdbarch_init, mcore_dump_tdep);
 
 #ifdef MCORE_DEBUG
   add_show_from_set (add_set_cmd ("mcoredebug", no_class,
This page took 0.049226 seconds and 4 git commands to generate.