This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Resurrect sh64 target


Hi,

the below patch resurrects sh64-elf.  I reworked the sh64 code so that it
doesn't use any deprecated mechanism anymore but all new stuff, except for
the DEPRECATED_TM_FILE, which I'm not sure how to circumvent.

This resurrection also requires a small change to the sh64 simulator which
I'm going to send in a couple of minutes, too.


Ok to apply?

Corinna


	* MAINTAINERS: Change sh64-elf state to non-broken.
	* Makefile.in: Fix dependencies for sh64-tdep.o.
	* configure.tgt: Add sh64-*-elf case.
	* sh-tdep.c (sh_gdbarch_init): Reactivate bfd_mach_sh5 case.
	* sh64-tdep.c: Rework to replace all deprecated mechanisms with
	modern methods.
	* config/sh/embed.mt (TDEPFILES): Add sh64-tdep.o.
	* config/sh/sh64.mt: Resurrect.
	* config/sh/tm-sh64.h: Ditto.

Index: MAINTAINERS
===================================================================
RCS file: /cvs/src/src/gdb/MAINTAINERS,v
retrieving revision 1.309
diff -u -p -r1.309 MAINTAINERS
--- MAINTAINERS	12 Feb 2005 21:53:29 -0000	1.309
+++ MAINTAINERS	30 Mar 2005 17:22:03 -0000
@@ -108,7 +108,7 @@ the native maintainer when resolving ABI
 	s390		--target=s390-linux-gnu ,-Werror
 
 	sh		--target=sh-elf ,-Werror
-			--target=sh64-elf broken
+			--target=sh64-elf ,-Werror
 
 	sparc		--target=sparc-elf ,-Werror
 
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.709
diff -u -p -r1.709 Makefile.in
--- Makefile.in	29 Mar 2005 20:34:57 -0000	1.709
+++ Makefile.in	30 Mar 2005 17:22:04 -0000
@@ -2497,11 +2497,11 @@ ser-unix.o: ser-unix.c $(defs_h) $(seria
 sh3-rom.o: sh3-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \
 	$(serial_h) $(srec_h) $(arch_utils_h) $(regcache_h) $(gdb_string_h) \
 	$(sh_tdep_h)
-sh64-tdep.o: sh64-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(objfiles_h) \
-	$(gdbtypes_h) $(gdbcmd_h) $(gdbcore_h) $(value_h) $(dis_asm_h) \
-	$(inferior_h) $(gdb_string_h) $(arch_utils_h) $(floatformat_h) \
-	$(regcache_h) $(doublest_h) $(osabi_h) $(elf_bfd_h) $(solib_svr4_h) \
-	$(elf_sh_h) $(gdb_sim_sh_h)
+sh64-tdep.o: sh64-tdep.c $(defs_h) $(frame_h) $(frame_base_h) \
+	$(frame_unwind_h) $(dwarf2_frame_h) $(symtab_h) $(gdbtypes_h) \
+	$(gdbcmd_h) $(gdbcore_h) $(value_h) $(dis_asm_h) $(inferior_h) \
+	$(gdb_string_h) $(gdb_assert_h) $(arch_utils_h) $(regcache_h) \
+	$(osabi_h) $(elf_bfd_h) $(elf_sh_h) $(gdb_sim_sh_h)
 shnbsd-nat.o: shnbsd-nat.c $(defs_h) $(inferior_h) $(sh_tdep_h) \
 	$(shnbsd_tdep_h)
 shnbsd-tdep.o: shnbsd-tdep.c $(defs_h) $(gdbcore_h) $(regcache_h) $(value_h) \
Index: configure.tgt
===================================================================
RCS file: /cvs/src/src/gdb/configure.tgt,v
retrieving revision 1.161
diff -u -p -r1.161 configure.tgt
--- configure.tgt	18 Mar 2005 18:59:17 -0000	1.161
+++ configure.tgt	30 Mar 2005 17:22:04 -0000
@@ -171,6 +171,7 @@ sh-*-linux*)		gdb_target=linux
 sh*-*-netbsdelf* | sh*-*-knetbsd*-gnu)
 			gdb_target=nbsd ;;
 sh-*-nto*)		gdb_target=nto ;;
+sh64-*-elf*)		gdb_target=sh64 ;;
 sh*)			gdb_target=embed ;;
 
 sparc-*-linux*)		gdb_target=linux ;;
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.185
diff -u -p -r1.185 sh-tdep.c
--- sh-tdep.c	15 Feb 2005 15:49:19 -0000	1.185
+++ sh-tdep.c	30 Mar 2005 17:22:04 -0000
@@ -2560,12 +2560,10 @@ sh_gdbarch_init (struct gdbarch_info inf
       sh_show_regs = sh4_nofpu_show_regs;
       break;
 
-#if 0
     case bfd_mach_sh5:
       sh_show_regs = sh64_show_regs;
       /* SH5 is handled entirely in sh64-tdep.c */
       return sh64_gdbarch_init (info, arches);
-#endif
     }
 
   /* If there is already a candidate, use it.  */
Index: sh64-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh64-tdep.c,v
retrieving revision 1.36
diff -u -p -r1.36 sh64-tdep.c
--- sh64-tdep.c	11 Feb 2005 18:13:53 -0000	1.36
+++ sh64-tdep.c	30 Mar 2005 17:22:05 -0000
@@ -27,8 +27,10 @@
 
 #include "defs.h"
 #include "frame.h"
+#include "frame-base.h"
+#include "frame-unwind.h"
+#include "dwarf2-frame.h"
 #include "symtab.h"
-#include "objfiles.h"
 #include "gdbtypes.h"
 #include "gdbcmd.h"
 #include "gdbcore.h"
@@ -36,14 +38,12 @@
 #include "dis-asm.h"
 #include "inferior.h"
 #include "gdb_string.h"
+#include "gdb_assert.h"
 #include "arch-utils.h"
-#include "floatformat.h"
 #include "regcache.h"
-#include "doublest.h"
 #include "osabi.h"
 
 #include "elf-bfd.h"
-#include "solib-svr4.h"
 
 /* sh flags */
 #include "elf/sh.h"
@@ -63,6 +63,23 @@ struct gdbarch_tdep
     enum sh_abi sh_abi;
   };
 
+struct sh64_frame_cache
+{
+  /* Base address.  */
+  CORE_ADDR base;
+  LONGEST sp_offset;
+  CORE_ADDR pc;
+
+  /* Flag showing that a frame has been created in the prologue code. */
+  int uses_fp;
+
+  int media_mode;
+
+  /* Saved registers.  */
+  CORE_ADDR saved_regs[SIM_SH64_NR_REGS];
+  CORE_ADDR saved_sp;
+};
+
 /* Registers of SH5 */
 enum
   {
@@ -72,6 +89,7 @@ enum
     ARG0_REGNUM = 2,
     ARGLAST_REGNUM = 9,
     FLOAT_ARGLAST_REGNUM = 11,
+    MEDIA_FP_REGNUM = 14,
     PR_REGNUM = 18,
     SR_REGNUM = 65,
     DR0_REGNUM = 141,
@@ -107,18 +125,6 @@ enum
     FP_LAST_REGNUM = SIM_SH64_FR0_REGNUM + SIM_SH64_NR_FP_REGS - 1
   };
 
-
-/* Define other aspects of the stack frame.
-   we keep a copy of the worked out return pc lying around, since it
-   is a useful bit of info */
-  
-struct frame_extra_info
-{
-  CORE_ADDR return_pc;
-  int leaf_function;
-  int f_offset;
-};
-
 static const char *
 sh64_register_name (int reg_nr)
 {
@@ -460,6 +466,7 @@ after_prologue (CORE_ADDR pc)
   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
     return 0;
 
+
   /* Get the line associated with FUNC_ADDR.  */
   sal = find_pc_line (func_addr, 0);
 
@@ -647,7 +654,7 @@ sh64_skip_prologue_hard_way (CORE_ADDR s
 }
 
 static CORE_ADDR
-sh_skip_prologue (CORE_ADDR pc)
+sh64_skip_prologue (CORE_ADDR pc)
 {
   CORE_ADDR post_prologue_pc;
 
@@ -664,133 +671,24 @@ sh_skip_prologue (CORE_ADDR pc)
     return sh64_skip_prologue_hard_way (pc);
 }
 
-/* Immediately after a function call, return the saved pc.
-   Can't always go through the frames for this because on some machines
-   the new frame is not set up until the new function executes
-   some instructions.
-
-   The return address is the value saved in the PR register + 4  */
-static CORE_ADDR
-sh_saved_pc_after_call (struct frame_info *frame)
-{
-  return (ADDR_BITS_REMOVE (read_register (PR_REGNUM)));
-}
-
 /* Should call_function allocate stack space for a struct return?  */
 static int
-sh64_use_struct_convention (int gcc_p, struct type *type)
+sh64_use_struct_convention (struct type *type)
 {
   return (TYPE_LENGTH (type) > 8);
 }
 
-/* Store the address of the place in which to copy the structure the
-   subroutine will return.  This is called from call_function.
-
-   We store structs through a pointer passed in R2 */
-static void
-sh64_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
-{
-  write_register (STRUCT_RETURN_REGNUM, (addr));
-}
-
 /* Disassemble an instruction.  */
 static int
-gdb_print_insn_sh (bfd_vma memaddr, disassemble_info *info)
+gdb_print_insn_sh64 (bfd_vma memaddr, disassemble_info *info)
 {
   info->endian = TARGET_BYTE_ORDER;
   return print_insn_sh (memaddr, info);
 }
 
-/* Given a register number RN as it appears in an assembly
-   instruction, find the corresponding register number in the GDB
-   scheme.  */
-static int 
-translate_insn_rn (int rn, int media_mode)
-{
-  /* FIXME: this assumes that the number rn is for a not pseudo
-     register only.  */
-  if (media_mode)
-    return rn;
-  else
-    {
-      /* These registers don't have a corresponding compact one.  */
-      /* FIXME: This is probably not enough.  */
-#if 0
-      if ((rn >= 16 && rn <= 63) || (rn >= 93 && rn <= 140))
-	return rn;
-#endif
-      if (rn >= 0 && rn <= R0_C_REGNUM)
-	return R0_C_REGNUM + rn;
-      else
-	return rn;
-    }
-}
-
-/* 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.
-
-   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.  */
-static CORE_ADDR
-sh64_frame_chain (struct frame_info *frame)
-{
-  if (deprecated_pc_in_call_dummy (get_frame_pc (frame)))
-    return get_frame_base (frame);    /* dummy frame same as caller's frame */
-  if (get_frame_pc (frame))
-    {
-      int media_mode = pc_is_isa32 (get_frame_pc (frame));
-      int size;
-      if (gdbarch_tdep (current_gdbarch)->sh_abi == SH_ABI_32)
-	size = 4;
-      else
-	size = register_size (current_gdbarch, 
-			      translate_insn_rn (DEPRECATED_FP_REGNUM, 
-						 media_mode));
-      return read_memory_integer (get_frame_base (frame)
-				  + get_frame_extra_info (frame)->f_offset,
-				  size);
-    }
-  else
-    return 0;
-}
-
-static CORE_ADDR
-sh64_get_saved_pr (struct frame_info *fi, int pr_regnum)
-{
-  int media_mode = 0;
-
-  for (; fi; fi = get_next_frame (fi))
-    if (deprecated_pc_in_call_dummy (get_frame_pc (fi)))
-      /* When the caller requests PR from the dummy frame, we return
-         PC because that's where the previous routine appears to have
-         done a call from.  */
-      return deprecated_read_register_dummy (get_frame_pc (fi),
-					     get_frame_base (fi), pr_regnum);
-    else
-      {
-	DEPRECATED_FRAME_INIT_SAVED_REGS (fi);
-	if (!get_frame_pc (fi))
-	  return 0;
-
-	media_mode = pc_is_isa32 (get_frame_pc (fi));
-
-	if (deprecated_get_frame_saved_regs (fi)[pr_regnum] != 0)
-	  {
-	    int gdb_reg_num = translate_insn_rn (pr_regnum, media_mode);
-	    int size = ((gdbarch_tdep (current_gdbarch)->sh_abi == SH_ABI_32)
-			? 4
-			: register_size (current_gdbarch, gdb_reg_num));
-	    return read_memory_integer (deprecated_get_frame_saved_regs (fi)[pr_regnum], size);
-	  }
-      }
-  return read_register (pr_regnum);
-}
-
 /* For vectors of 4 floating point registers.  */
 static int
-fv_reg_base_num (int fv_regnum)
+sh64_fv_reg_base_num (int fv_regnum)
 {
   int fp_regnum;
 
@@ -801,7 +699,7 @@ fv_reg_base_num (int fv_regnum)
 
 /* For double precision floating point registers, i.e 2 fp regs.*/
 static int
-dr_reg_base_num (int dr_regnum)
+sh64_dr_reg_base_num (int dr_regnum)
 {
   int fp_regnum;
 
@@ -812,7 +710,7 @@ dr_reg_base_num (int dr_regnum)
 
 /* For pairs of floating point registers */
 static int
-fpp_reg_base_num (int fpp_regnum)
+sh64_fpp_reg_base_num (int fpp_regnum)
 {
   int fp_regnum;
 
@@ -821,32 +719,6 @@ fpp_reg_base_num (int fpp_regnum)
   return fp_regnum;
 }
 
-static int
-is_media_pseudo (int rn)
-{
-  return (rn >= DR0_REGNUM && rn <= FV_LAST_REGNUM);
-}
-
-static int
-sh64_media_reg_base_num (int reg_nr)
-{
-  int base_regnum = -1;
-
-  if (reg_nr >= DR0_REGNUM
-      && reg_nr <= DR_LAST_REGNUM)
-    base_regnum = dr_reg_base_num (reg_nr);
-
-  else if (reg_nr >= FPP0_REGNUM 
-	   && reg_nr <= FPP_LAST_REGNUM)
-    base_regnum = fpp_reg_base_num (reg_nr);
-
-  else if (reg_nr >= FV0_REGNUM
-	   && reg_nr <= FV_LAST_REGNUM)
-    base_regnum = fv_reg_base_num (reg_nr);
-
-  return base_regnum;
-}
-
 /* *INDENT-OFF* */
 /*
     SH COMPACT MODE (ISA 16) (all pseudo) 221-272
@@ -912,7 +784,7 @@ sh64_media_reg_base_num (int reg_nr)
 static int
 sh64_compact_reg_base_num (int reg_nr)
 {
-  int base_regnum = -1;
+  int base_regnum = reg_nr;
 
   /* general register N maps to general register N */
   if (reg_nr >= R0_C_REGNUM 
@@ -927,14 +799,12 @@ sh64_compact_reg_base_num (int reg_nr)
   /* double prec register N maps to base regnum for double prec register N */
   else if (reg_nr >= DR0_C_REGNUM 
 	    && reg_nr <= DR_LAST_C_REGNUM)
-    base_regnum = dr_reg_base_num (DR0_REGNUM
-				   + reg_nr - DR0_C_REGNUM);
+    base_regnum = sh64_dr_reg_base_num (DR0_REGNUM + reg_nr - DR0_C_REGNUM);
 
   /* vector N maps to base regnum for vector register N */
   else if (reg_nr >= FV0_C_REGNUM 
 	    && reg_nr <= FV_LAST_C_REGNUM)
-    base_regnum = fv_reg_base_num (FV0_REGNUM
-				   + reg_nr - FV0_C_REGNUM);
+    base_regnum = sh64_fv_reg_base_num (FV0_REGNUM + reg_nr - FV0_C_REGNUM);
 
   else if (reg_nr == PC_C_REGNUM)
     base_regnum = PC_REGNUM;
@@ -947,7 +817,7 @@ sh64_compact_reg_base_num (int reg_nr)
     base_regnum = 17;
 
   else if (reg_nr == PR_C_REGNUM) 
-    base_regnum = 18;
+    base_regnum = PR_REGNUM;
 
   else if (reg_nr == T_C_REGNUM) 
     base_regnum = 19;
@@ -961,26 +831,6 @@ sh64_compact_reg_base_num (int reg_nr)
   return base_regnum;
 }
 
-/* Given a register number RN (according to the gdb scheme) , return
-   its corresponding architectural register.  In media mode, only a
-   subset of the registers is pseudo registers. For compact mode, all
-   the registers are pseudo.  */
-static int 
-translate_rn_to_arch_reg_num (int rn, int media_mode)
-{
-
-  if (media_mode)
-    {
-      if (!is_media_pseudo (rn))
-	return rn;
-      else
-	return sh64_media_reg_base_num (rn);
-    }
-  else
-    /* All compact registers are pseudo.  */
-    return sh64_compact_reg_base_num (rn);
-}
-
 static int
 sign_extend (int value, int bits)
 {
@@ -991,99 +841,59 @@ sign_extend (int value, int bits)
 }
 
 static void
-sh64_nofp_frame_init_saved_regs (struct frame_info *fi)
+sh64_analyze_prologue (struct gdbarch *gdbarch,
+		       struct sh64_frame_cache *cache,
+		       CORE_ADDR func_pc,
+		       CORE_ADDR current_pc)
 {
-  int *where = (int *) alloca ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof (int));
-  int rn;
-  int have_fp = 0;
-  int fp_regnum;
-  int sp_regnum;
-  int depth;
+  int reg_nr;
   int pc;
   int opc;
   int insn;
   int r0_val = 0;
-  int media_mode = 0;
   int insn_size;
   int gdb_register_number;
   int register_number;
-  char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi), 
-							  get_frame_base (fi));
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   
-  if (deprecated_get_frame_saved_regs (fi) == NULL)
-    frame_saved_regs_zalloc (fi);
-  else
-    memset (deprecated_get_frame_saved_regs (fi), 0, SIZEOF_FRAME_SAVED_REGS);
-  
-  if (dummy_regs)
-    {
-      /* DANGER!  This is ONLY going to work if the char buffer format of
-         the saved registers is byte-for-byte identical to the 
-         CORE_ADDR regs[NUM_REGS] format used by struct frame_saved_regs! */
-      memcpy (deprecated_get_frame_saved_regs (fi), dummy_regs, SIZEOF_FRAME_SAVED_REGS);
-      return;
-    }
-
-  get_frame_extra_info (fi)->leaf_function = 1;
-  get_frame_extra_info (fi)->f_offset = 0;
-
-  for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
-    where[rn] = -1;
-
-  depth = 0;
+  cache->sp_offset = 0;
 
   /* Loop around examining the prologue insns until we find something
      that does not appear to be part of the prologue.  But give up
      after 20 of them, since we're getting silly then.  */
 
-  pc = get_frame_func (fi);
-  if (!pc)
-    {
-      deprecated_update_frame_pc_hack (fi, 0);
-      return;
-    }
+  pc = func_pc;
 
-  if (pc_is_isa32 (pc))
-    {
-      media_mode = 1;
-      insn_size = 4;
-    }
+  if (cache->media_mode)
+    insn_size = 4;
   else
-    {
-      media_mode = 0;
-      insn_size = 2;
-    }
+    insn_size = 2;
 
- /* The frame pointer register is general register 14 in shmedia and
-    shcompact modes. In sh compact it is a pseudo register.  Same goes
-    for the stack pointer register, which is register 15.  */
-  fp_regnum = translate_insn_rn (DEPRECATED_FP_REGNUM, media_mode);
-  sp_regnum = translate_insn_rn (SP_REGNUM, media_mode);
-
-  for (opc = pc + (insn_size * 28); pc < opc; pc += insn_size)
+  opc = pc + (insn_size * 28);
+  if (opc > current_pc)
+    opc = current_pc;
+  for ( ; pc <= opc; pc += insn_size)
     {
-      insn = read_memory_integer (media_mode ? UNMAKE_ISA32_ADDR (pc) : pc,
+      insn = read_memory_integer (cache->media_mode ? UNMAKE_ISA32_ADDR (pc)
+						    : pc,
 				  insn_size);
 
-      if (media_mode == 0)
+      if (!cache->media_mode)
 	{
 	  if (IS_STS_PR (insn))
 	    {
 	      int next_insn = read_memory_integer (pc + insn_size, insn_size);
 	      if (IS_MOV_TO_R15 (next_insn))
 		{
-		  int reg_nr = PR_C_REGNUM;
-
-		  where[reg_nr] = depth - ((((next_insn & 0xf) ^ 0x8) - 0x8) << 2);
-		  get_frame_extra_info (fi)->leaf_function = 0;
+		  cache->saved_regs[PR_REGNUM] =
+		    cache->sp_offset - ((((next_insn & 0xf) ^ 0x8) - 0x8) << 2);
 		  pc += insn_size;
 		}
 	    }
+
 	  else if (IS_MOV_R14 (insn))
-	    {
-	      where[fp_regnum] = depth - ((((insn & 0xf) ^ 0x8) - 0x8) << 2);
-	    }
+	    cache->saved_regs[MEDIA_FP_REGNUM] =
+	      cache->sp_offset - ((((insn & 0xf) ^ 0x8) - 0x8) << 2);
 
 	  else if (IS_MOV_R0 (insn))
 	    {
@@ -1093,245 +903,63 @@ sh64_nofp_frame_init_saved_regs (struct 
 		 the frame.  */
 	      r0_val = ((insn & 0xff) ^ 0x80) - 0x80;
 	    }
+
 	  else if (IS_ADD_SP_R0 (insn))
 	    {
 	      /* This instruction still prepares r0, but we don't care.
 		 We already have the offset in r0_val.  */
 	    }
+
 	  else if (IS_STS_R0 (insn))
 	    {
 	      /* Store PR at r0_val-4 from SP. Decrement r0 by 4*/
-	      int reg_nr = PR_C_REGNUM;
-	      where[reg_nr] = depth - (r0_val - 4);
+	      cache->saved_regs[PR_REGNUM] = cache->sp_offset - (r0_val - 4);
 	      r0_val -= 4;
-	      get_frame_extra_info (fi)->leaf_function = 0;
 	    }
+
 	  else if (IS_MOV_R14_R0 (insn))
 	    {
 	      /* Store R14 at r0_val-4 from SP. Decrement r0 by 4 */
-	      where[fp_regnum] = depth - (r0_val - 4);
+	      cache->saved_regs[MEDIA_FP_REGNUM] = cache->sp_offset
+	      					   - (r0_val - 4);
 	      r0_val -= 4;
 	    }
 
 	  else if (IS_ADD_SP (insn))
-	    {
-	      depth -= ((insn & 0xff) ^ 0x80) - 0x80;
-	    }
+	    cache->sp_offset -= ((insn & 0xff) ^ 0x80) - 0x80;
+
 	  else if (IS_MOV_SP_FP (insn))
 	    break;
 	}
       else
 	{
-	  if (IS_ADDIL_SP_MEDIA (insn) 
-	      || IS_ADDI_SP_MEDIA (insn))
-	    {
-	      depth -= sign_extend ((((insn & 0xffc00) ^ 0x80000) - 0x80000) >> 10, 9);
-	    }
+	  if (IS_ADDIL_SP_MEDIA (insn) || IS_ADDI_SP_MEDIA (insn))
+	    cache->sp_offset -=
+	      sign_extend ((((insn & 0xffc00) ^ 0x80000) - 0x80000) >> 10, 9);
 
 	  else if (IS_STQ_R18_R15 (insn))
-	    {
-	      where[PR_REGNUM] = 
-		depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
-	      get_frame_extra_info (fi)->leaf_function = 0;
-	    }
+	    cache->saved_regs[PR_REGNUM] = 
+	      cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
 
 	  else if (IS_STL_R18_R15 (insn))
-	    {
-	      where[PR_REGNUM] = 
-		depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
-	      get_frame_extra_info (fi)->leaf_function = 0;
-	    }
+	    cache->saved_regs[PR_REGNUM] = 
+	      cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
 
 	  else if (IS_STQ_R14_R15 (insn))
-	    {
-	      where[fp_regnum] = depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
-	    }
+	    cache->saved_regs[MEDIA_FP_REGNUM] =
+	      cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
 
 	  else if (IS_STL_R14_R15 (insn))
-	    {
-	      where[fp_regnum] = depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
-	    }
+	    cache->saved_regs[MEDIA_FP_REGNUM] =
+	      cache->sp_offset - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
 
 	  else if (IS_MOV_SP_FP_MEDIA (insn))
 	    break;
 	}
     }
 
-  /* Now we know how deep things are, we can work out their addresses.  */
-  for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
-    {
-      register_number = translate_rn_to_arch_reg_num (rn, media_mode);
-
-      if (where[rn] >= 0)
-	{
-	  if (rn == fp_regnum)
-	    have_fp = 1;
-
-	  /* Watch out! saved_regs is only for the real registers, and
-	     doesn't include space for the pseudo registers.  */
-	  deprecated_get_frame_saved_regs (fi)[register_number] 
-	    = get_frame_base (fi) - where[rn] + depth;
-	} 
-      else 
-	deprecated_get_frame_saved_regs (fi)[register_number] = 0;
-    }
-
-  if (have_fp)
-    {
-      /* SP_REGNUM is 15. For shmedia 15 is the real register. For
-	 shcompact 15 is the arch register corresponding to the pseudo
-	 register r15 which still is the SP register.  */
-      /* The place on the stack where fp is stored contains the sp of
-         the caller.  */
-      /* Again, saved_registers contains only space for the real
-	 registers, so we store in DEPRECATED_FP_REGNUM position.  */
-      int size;
-      if (tdep->sh_abi == SH_ABI_32)
-	size = 4;
-      else
-	size = register_size (current_gdbarch, fp_regnum);
-      deprecated_get_frame_saved_regs (fi)[sp_regnum] 
-	= read_memory_integer (deprecated_get_frame_saved_regs (fi)[fp_regnum],
-			       size);
-    }
-  else
-    deprecated_get_frame_saved_regs (fi)[sp_regnum] = get_frame_base (fi);
-
-  get_frame_extra_info (fi)->f_offset = depth - where[fp_regnum];
-}
-
-/* Initialize the extra info saved in a FRAME */
-static void
-sh64_init_extra_frame_info (int fromleaf, struct frame_info *fi)
-{
-  int media_mode = pc_is_isa32 (get_frame_pc (fi));
-
-  frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
-
-  if (get_next_frame (fi)) 
-    deprecated_update_frame_pc_hack (fi, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi)));
-
-  if (deprecated_pc_in_call_dummy (get_frame_pc (fi)))
-    {
-      /* 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));
-      get_frame_extra_info (fi)->return_pc = 
-	deprecated_read_register_dummy (get_frame_pc (fi),
-					get_frame_base (fi), PC_REGNUM);
-      get_frame_extra_info (fi)->f_offset = -4;
-      get_frame_extra_info (fi)->leaf_function = 0;
-      return;
-    }
-  else
-    {
-      DEPRECATED_FRAME_INIT_SAVED_REGS (fi);
-      get_frame_extra_info (fi)->return_pc =
-	sh64_get_saved_pr (fi, PR_REGNUM);
-    }
-}
-
-static void
-sh64_get_saved_register (char *raw_buffer, int *optimized, CORE_ADDR *addrp,
-			 struct frame_info *frame, int regnum,
-			 enum lval_type *lval)
-{
-  int media_mode;
-  int live_regnum = regnum;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
-
-  if (!target_has_registers)
-    error ("No registers.");
-
-  /* Normal systems don't optimize out things with register numbers.  */
-  if (optimized != NULL)
-    *optimized = 0;
-
-  if (addrp)			/* default assumption: not found in memory */
-    *addrp = 0;
-
-  if (raw_buffer)
-    memset (raw_buffer, 0, sizeof (raw_buffer));
-
-  /* We must do this here, before the following while loop changes
-     frame, and makes it NULL. If this is a media register number,
-     but we are in compact mode, it will become the corresponding 
-     compact pseudo register. If there is no corresponding compact 
-     pseudo-register what do we do?*/
-  media_mode = pc_is_isa32 (get_frame_pc (frame));
-  live_regnum = translate_insn_rn (regnum, media_mode);
-
-  /* Note: since the current frame's registers could only have been
-     saved by frames INTERIOR TO the current frame, we skip examining
-     the current frame itself: otherwise, we would be getting the
-     previous frame's registers which were saved by the current frame.  */
-
-  while (frame && ((frame = get_next_frame (frame)) != NULL))
-    {
-      if (deprecated_pc_in_call_dummy (get_frame_pc (frame)))
-	{
-	  if (lval)		/* found it in a CALL_DUMMY frame */
-	    *lval = not_lval;
-	  if (raw_buffer)
-	    memcpy (raw_buffer,
-		    (deprecated_generic_find_dummy_frame (get_frame_pc (frame), get_frame_base (frame))
-		     + DEPRECATED_REGISTER_BYTE (regnum)),
-		    register_size (current_gdbarch, regnum));
-	  return;
-	}
-
-      DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
-      if (deprecated_get_frame_saved_regs (frame) != NULL
-	  && deprecated_get_frame_saved_regs (frame)[regnum] != 0)
-	{
-	  if (lval)		/* found it saved on the stack */
-	    *lval = lval_memory;
-	  if (regnum == SP_REGNUM)
-	    {
-	      if (raw_buffer)	/* SP register treated specially */
-		store_unsigned_integer (raw_buffer, 
-					register_size (current_gdbarch, 
-						       regnum),
-					deprecated_get_frame_saved_regs (frame)[regnum]);
-	    }
-	  else
-	    { /* any other register */
-	      
-	      if (addrp)
-		*addrp = deprecated_get_frame_saved_regs (frame)[regnum];
-	      if (raw_buffer)
-		{
-		  int size;
-		  if (tdep->sh_abi == SH_ABI_32
-		      && (live_regnum == DEPRECATED_FP_REGNUM
-			  || live_regnum == PR_REGNUM))
-		    size = 4;
-		  else
-		    size = register_size (current_gdbarch, live_regnum);
-		  if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
-		    read_memory (deprecated_get_frame_saved_regs (frame)[regnum], 
-				 raw_buffer, size);
-		  else
-		    read_memory (deprecated_get_frame_saved_regs (frame)[regnum],
-				 raw_buffer
-				 + register_size (current_gdbarch, live_regnum)
-				 - size,
-				 size);
-		}
-	    }
-	  return;
-	}
-    }
-
-  /* If we get thru the loop to this point, it means the register was
-     not saved in any frame.  Return the actual live-register value.  */
-
-  if (lval)			/* found it in a live register */
-    *lval = lval_register;
-  if (addrp)
-    *addrp = DEPRECATED_REGISTER_BYTE (live_regnum);
-  if (raw_buffer)
-    deprecated_read_register_gen (live_regnum, raw_buffer);
+  if (cache->saved_regs[MEDIA_FP_REGNUM] >= 0)
+    cache->uses_fp = 1;
 }
 
 static CORE_ADDR
@@ -1346,60 +974,12 @@ sh64_extract_struct_value_address (struc
 }
 
 static CORE_ADDR
-sh_frame_saved_pc (struct frame_info *frame)
-{
-  return (get_frame_extra_info (frame)->return_pc);
-}
-
-/* Discard from the stack the innermost frame, restoring all saved registers.
-   Used in the 'return' command.  */
-static void
-sh64_pop_frame (void)
-{
-  struct frame_info *frame = get_current_frame ();
-  CORE_ADDR fp;
-  int regnum;
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
-
-  int media_mode = pc_is_isa32 (get_frame_pc (frame));
-
-  if (deprecated_pc_in_call_dummy (get_frame_pc (frame)))
-    deprecated_pop_dummy_frame ();
-  else
-    {
-      fp = get_frame_base (frame);
-      DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
-
-      /* Copy regs from where they were saved in the frame */
-      for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
-	if (deprecated_get_frame_saved_regs (frame)[regnum])
-	  {
-	    int size;
-	    if (tdep->sh_abi == SH_ABI_32
-		&& (regnum == DEPRECATED_FP_REGNUM
-		    || regnum ==  PR_REGNUM))
-	      size = 4;
-	    else
-	      size = register_size (current_gdbarch, 
-				    translate_insn_rn (regnum, media_mode));
-	    write_register (regnum,
-			    read_memory_integer (deprecated_get_frame_saved_regs (frame)[regnum],
-						 size));
-	  }
-
-      write_register (PC_REGNUM, get_frame_extra_info (frame)->return_pc);
-      write_register (SP_REGNUM, fp + 8);
-    }
-  flush_cached_frames ();
-}
-
-static CORE_ADDR
-sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
+sh64_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
 {
-  return sp & ~3;
+  return sp & ~7;
 }
 
-/* Function: push_arguments
+/* Function: push_dummy_call
    Setup the function arguments for calling a function in the inferior.
 
    On the Renesas SH architecture, there are four registers (R4 to R7)
@@ -1462,8 +1042,13 @@ sh_frame_align (struct gdbarch *ignore, 
    for which the prototype is not known.  */
 
 static CORE_ADDR
-sh64_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
-		     int struct_return, CORE_ADDR struct_addr)
+sh64_push_dummy_call (struct gdbarch *gdbarch,
+		      struct value *function,
+		      struct regcache *regcache,
+		      CORE_ADDR bp_addr,
+		      int nargs, struct value **args,
+		      CORE_ADDR sp, int struct_return,
+		      CORE_ADDR struct_addr)
 {
   int stack_offset, stack_alloc;
   int int_argreg;
@@ -1484,13 +1069,14 @@ sh64_push_arguments (int nargs, struct v
   memset (fp_args, 0, sizeof (fp_args));
 
   /* first force sp to a 8-byte alignment */
-  sp = sp & ~7;
+  sp = sh64_frame_align (gdbarch, sp);
 
   /* The "struct return pointer" pseudo-argument has its own dedicated 
      register */
 
   if (struct_return)
-    write_register (STRUCT_RETURN_REGNUM, struct_addr);
+    regcache_cooked_write_unsigned (regcache, 
+				    STRUCT_RETURN_REGNUM, struct_addr);
 
   /* Now make sure there's space on the stack */
   for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
@@ -1544,7 +1130,7 @@ sh64_push_arguments (int nargs, struct v
 		{			
 		  /* there's room in a register */
 		  regval = extract_unsigned_integer (val, argreg_size);
-		  write_register (int_argreg, regval);
+		  regcache_cooked_write_unsigned (regcache, int_argreg, regval);
 		}
 	      /* Store the value 8 bytes at a time.  This means that
 		 things larger than 8 bytes may go partly in registers
@@ -1570,8 +1156,9 @@ sh64_push_arguments (int nargs, struct v
 	      if (float_arg_index <= FLOAT_ARGLAST_REGNUM)
 		{
 		  /* Goes in FR0...FR11 */
-		  deprecated_write_register_gen (FP0_REGNUM + float_arg_index,
-						 val);
+		  regcache_cooked_write (regcache,
+					 FP0_REGNUM + float_arg_index,
+					 val);
 		  fp_args[float_arg_index] = 1;
 		  /* Skip the corresponding general argument register.  */
 		  int_argreg ++;
@@ -1596,26 +1183,8 @@ sh64_push_arguments (int nargs, struct v
 		    /* The numbering of the DRi registers is consecutive,
 		       i.e. includes odd numbers.  */
 		    int double_register_offset = double_arg_index / 2;
-		    int regnum = DR0_REGNUM +
-		                 double_register_offset;
-#if 0
-		    if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
-		      {
-			memset (valbuf_tmp, 0, sizeof (valbuf_tmp));
-			DEPRECATED_REGISTER_CONVERT_TO_VIRTUAL (regnum,
-								type, val,
-								valbuf_tmp);
-			val = valbuf_tmp;
-		      }
-#endif
-		    /* Note: must use write_register_gen here instead
-		       of regcache_raw_write, because
-		       regcache_raw_write works only for real
-		       registers, not pseudo.  write_register_gen will
-		       call the gdbarch function to do register
-		       writes, and that will properly know how to deal
-		       with pseudoregs.  */
-		    deprecated_write_register_gen (regnum, val);
+		    int regnum = DR0_REGNUM + double_register_offset;
+		    regcache_cooked_write (regcache, regnum, val);
 		    fp_args[double_arg_index] = 1;
 		    fp_args[double_arg_index + 1] = 1;
 		    /* Skip the corresponding general argument register.  */
@@ -1628,17 +1197,12 @@ sh64_push_arguments (int nargs, struct v
 	      }
 	}
     }
-  return sp;
-}
+  /* Store return address. */
+  regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
 
-/* Function: push_return_address (pc)
-   Set up the return address for the inferior function call.
-   Needed for targets where we don't actually execute a JSR/BSR instruction */
+  /* Update stack pointer.  */
+  regcache_cooked_write_unsigned (regcache, SP_REGNUM, sp);
 
-static CORE_ADDR
-sh64_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
-{
-  write_register (PR_REGNUM, entry_point_address ());
   return sp;
 }
 
@@ -1647,10 +1211,9 @@ sh64_push_return_address (CORE_ADDR pc, 
    containing the (raw) register state a function return value of type
    TYPE, and copy that, in virtual format, into VALBUF.  */
 static void
-sh64_extract_return_value (struct type *type, char *regbuf, char *valbuf)
+sh64_extract_return_value (struct type *type, struct regcache *regcache,
+			   void *valbuf)
 {
-  int offset;
-  int return_register;
   int len = TYPE_LENGTH (type);
   
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
@@ -1658,24 +1221,22 @@ sh64_extract_return_value (struct type *
       if (len == 4)
 	{
 	  /* Return value stored in FP0_REGNUM */
-	  return_register = FP0_REGNUM;
-	  offset = DEPRECATED_REGISTER_BYTE (return_register);
-	  memcpy (valbuf, (char *) regbuf + offset, len);
+	  regcache_raw_read (regcache, FP0_REGNUM, valbuf);
 	}
       else if (len == 8)
 	{
 	  /* return value stored in DR0_REGNUM */
 	  DOUBLEST val;
+	  char buf[8];
 
-	  return_register = DR0_REGNUM;
-	  offset = DEPRECATED_REGISTER_BYTE (return_register);
+	  regcache_cooked_read (regcache, DR0_REGNUM, &buf);
 	  
 	  if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
 	    floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
-				     (char *) regbuf + offset, &val);
+				     buf, &val);
 	  else
 	    floatformat_to_doublest (&floatformat_ieee_double_big,
-				     (char *) regbuf + offset, &val);
+				     buf, &val);
 	  store_typed_floating (valbuf, type, val);
 	}
     }
@@ -1683,15 +1244,18 @@ sh64_extract_return_value (struct type *
     { 
       if (len <= 8)
 	{
+	  int offset;
+	  char buf[8];
 	  /* Result is in register 2. If smaller than 8 bytes, it is padded 
 	     at the most significant end.  */
-	  return_register = DEFAULT_RETURN_REGNUM;
+	  regcache_raw_read (regcache, DEFAULT_RETURN_REGNUM, buf);
+
 	  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-	    offset = DEPRECATED_REGISTER_BYTE (return_register) +
-	      register_size (current_gdbarch, return_register) - len;
+	    offset = register_size (current_gdbarch, DEFAULT_RETURN_REGNUM)
+		     - len;
 	  else
-	    offset = DEPRECATED_REGISTER_BYTE (return_register);
-	  memcpy (valbuf, (char *) regbuf + offset, len);
+	    offset = 0;
+	  memcpy (valbuf, buf + offset, len);
 	}
       else
 	error ("bad size for return value");
@@ -1706,23 +1270,21 @@ sh64_extract_return_value (struct type *
    the result is stored in r0, left-justified.  */
 
 static void
-sh64_store_return_value (struct type *type, char *valbuf)
+sh64_store_return_value (struct type *type, struct regcache *regcache,
+			 const void *valbuf)
 {
   char buf[64];	/* more than enough...  */
   int len = TYPE_LENGTH (type);
 
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     {
-      if (len == 4)
-	{
-	  /* Return value stored in FP0_REGNUM */
-	  deprecated_write_register_gen (FP0_REGNUM, valbuf);
-	}
-      if (len == 8)
-	{
-	  /* return value stored in DR0_REGNUM */
-	  /* FIXME: Implement */
-	}
+      int i, regnum = FP0_REGNUM;
+      for (i = 0; i < len; i += 4)
+	if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
+	  regcache_raw_write (regcache, regnum++,
+			      (char *) valbuf + len - 4 - i);
+	else
+	  regcache_raw_write (regcache, regnum++, (char *) valbuf + i);
     }
   else
     {
@@ -1740,13 +1302,27 @@ sh64_store_return_value (struct type *ty
 	    offset = register_size (current_gdbarch, return_register) - len;
 
 	  memcpy (buf + offset, valbuf, len);
-	  deprecated_write_register_gen (return_register, buf);
+	  regcache_raw_write (regcache, return_register, buf);
 	}
       else
-	deprecated_write_register_gen (return_register, valbuf);
+	regcache_raw_write (regcache, return_register, valbuf);
     }
 }
 
+static enum return_value_convention
+sh64_return_value (struct gdbarch *gdbarch, struct type *type,
+		   struct regcache *regcache,
+		   void *readbuf, const void *writebuf)
+{
+  if (sh64_use_struct_convention (type))
+    return RETURN_VALUE_STRUCT_CONVENTION;
+  if (writebuf)
+    sh64_store_return_value (type, regcache, writebuf);
+  else if (readbuf)
+    sh64_extract_return_value (type, regcache, readbuf);
+  return RETURN_VALUE_REGISTER_CONVENTION;
+}
+
 static void
 sh64_show_media_regs (void)
 {
@@ -1905,91 +1481,6 @@ REGISTER_BYTE returns the register byte 
      dr0_c, dr2_c, dr4_c,  dr6_c,  dr8_c,  dr10_c, dr12_c, dr14_c
      fv0_c, fv4_c, fv8_c,  fv12_c
 */
-/* *INDENT-ON* */
-static int
-sh64_register_byte (int reg_nr)
-{
-  int base_regnum = -1;
-
-  /* If it is a pseudo register, get the number of the first floating
-     point register that is part of it.  */
-  if (reg_nr >= DR0_REGNUM 
-      && reg_nr <= DR_LAST_REGNUM)
-    base_regnum = dr_reg_base_num (reg_nr);
-
-  else if (reg_nr >= FPP0_REGNUM 
-	    && reg_nr <= FPP_LAST_REGNUM)
-    base_regnum = fpp_reg_base_num (reg_nr);
-
-  else if (reg_nr >= FV0_REGNUM 
-	    && reg_nr <= FV_LAST_REGNUM)
-    base_regnum = fv_reg_base_num (reg_nr);
-
-  /* sh compact pseudo register. FPSCR is a pathological case, need to
-     treat it as special.  */
-  else if ((reg_nr >= R0_C_REGNUM 
-	    && reg_nr <= FV_LAST_C_REGNUM) 
-	   && reg_nr != FPSCR_C_REGNUM)
-    base_regnum = sh64_compact_reg_base_num (reg_nr);
-
-  /* Now return the offset in bytes within the register cache.  */
-  /* sh media pseudo register, i.e. any of DR, FFP, FV registers.  */
-  if (reg_nr >= DR0_REGNUM 
-      && reg_nr <= FV_LAST_REGNUM)
-    return (base_regnum - FP0_REGNUM + 1) * 4 
-      + (TR7_REGNUM + 1) * 8;
-
-  /* sh compact pseudo register: general register */
-  if ((reg_nr >= R0_C_REGNUM 
-       && reg_nr <= R_LAST_C_REGNUM))
-    return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
-	    ? base_regnum * 8 + 4
-	    : base_regnum * 8);
-
-  /* sh compact pseudo register: */
-  if (reg_nr == PC_C_REGNUM 
-       || reg_nr == GBR_C_REGNUM
-       || reg_nr == MACL_C_REGNUM
-       || reg_nr == PR_C_REGNUM)
-    return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
-	    ? base_regnum * 8 + 4
-	    : base_regnum * 8);
-
-  if (reg_nr == MACH_C_REGNUM) 
-    return base_regnum * 8;
-
-  if (reg_nr == T_C_REGNUM) 
-    return base_regnum * 8; /* FIXME??? how do we get bit 0? Do we have to? */
-
-  /* sh compact pseudo register: floating point register */
-  else if (reg_nr >= FP0_C_REGNUM
-	   && reg_nr <= FV_LAST_C_REGNUM)
-    return (base_regnum  - FP0_REGNUM) * 4
-      + (TR7_REGNUM + 1) * 8 + 4;
-
-  else if (reg_nr == FPSCR_C_REGNUM)
-    /* This is complicated, for now return the beginning of the
-       architectural FPSCR register.  */
-    return (TR7_REGNUM + 1) * 8;
-
-  else if (reg_nr == FPUL_C_REGNUM)
-    return ((base_regnum - FP0_REGNUM) * 4 + 
-	    (TR7_REGNUM + 1) * 8 + 4);
-
-  /* It is not a pseudo register.  */
-  /* It is a 64 bit register.  */
-  else if (reg_nr <= TR7_REGNUM)
-    return reg_nr * 8;
-
-  /* It is a 32 bit register.  */
-  else if (reg_nr == FPSCR_REGNUM)
-    return (FPSCR_REGNUM * 8);
-
-  /* It is floating point 32-bit register */
-  else
-    return ((TR7_REGNUM + 1) * 8 
-      + (reg_nr - FP0_REGNUM + 1) * 4);
-}
 
 static struct type *
 sh64_build_float_register_type (int high)
@@ -2093,7 +1584,7 @@ sh64_pseudo_register_read (struct gdbarc
   if (reg_nr >= DR0_REGNUM 
       && reg_nr <= DR_LAST_REGNUM)
     {
-      base_regnum = dr_reg_base_num (reg_nr);
+      base_regnum = sh64_dr_reg_base_num (reg_nr);
 
       /* Build the value in the provided buffer.  */ 
       /* DR regs are double precision registers obtained by
@@ -2114,7 +1605,7 @@ sh64_pseudo_register_read (struct gdbarc
   else if (reg_nr >= FPP0_REGNUM 
 	   && reg_nr <= FPP_LAST_REGNUM)
     {
-      base_regnum = fpp_reg_base_num (reg_nr);
+      base_regnum = sh64_fpp_reg_base_num (reg_nr);
 
       /* Build the value in the provided buffer.  */ 
       /* FPP regs are pairs of single precision registers obtained by
@@ -2128,7 +1619,7 @@ sh64_pseudo_register_read (struct gdbarc
   else if (reg_nr >= FV0_REGNUM 
 	   && reg_nr <= FV_LAST_REGNUM)
     {
-      base_regnum = fv_reg_base_num (reg_nr);
+      base_regnum = sh64_fv_reg_base_num (reg_nr);
 
       /* Build the value in the provided buffer.  */ 
       /* FV regs are vectors of single precision registers obtained by
@@ -2261,7 +1752,7 @@ sh64_pseudo_register_write (struct gdbar
   if (reg_nr >= DR0_REGNUM
       && reg_nr <= DR_LAST_REGNUM)
     {
-      base_regnum = dr_reg_base_num (reg_nr);
+      base_regnum = sh64_dr_reg_base_num (reg_nr);
       /* We must pay attention to the endianness.  */
       sh64_register_convert_to_raw (gdbarch_register_type (gdbarch, reg_nr),
 				    reg_nr,
@@ -2278,7 +1769,7 @@ sh64_pseudo_register_write (struct gdbar
   else if (reg_nr >= FPP0_REGNUM 
 	   && reg_nr <= FPP_LAST_REGNUM)
     {
-      base_regnum = fpp_reg_base_num (reg_nr);
+      base_regnum = sh64_fpp_reg_base_num (reg_nr);
 
       /* Write the real regs for which this one is an alias.  */
       for (portion = 0; portion < 2; portion++)
@@ -2291,7 +1782,7 @@ sh64_pseudo_register_write (struct gdbar
   else if (reg_nr >= FV0_REGNUM
 	   && reg_nr <= FV_LAST_REGNUM)
     {
-      base_regnum = fv_reg_base_num (reg_nr);
+      base_regnum = sh64_fv_reg_base_num (reg_nr);
 
       /* Write the real regs for which this one is an alias.  */
       for (portion = 0; portion < 4; portion++)
@@ -2423,111 +1914,53 @@ sh64_pseudo_register_write (struct gdbar
     }
 }
 
-/* Floating point vector of 4 float registers.  */
-static void
-do_fv_register_info (struct gdbarch *gdbarch, struct ui_file *file,
-		     int fv_regnum)
-{
-  int first_fp_reg_num = fv_reg_base_num (fv_regnum);
-  fprintf_filtered (file, "fv%d\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n", 
-		     fv_regnum - FV0_REGNUM, 
-		     (int) read_register (first_fp_reg_num),
-		     (int) read_register (first_fp_reg_num + 1),
-		     (int) read_register (first_fp_reg_num + 2),
-		     (int) read_register (first_fp_reg_num + 3));
-}
-
-/* Floating point vector of 4 float registers, compact mode.  */
-static void
-do_fv_c_register_info (int fv_regnum)
-{
-  int first_fp_reg_num = sh64_compact_reg_base_num (fv_regnum);
-  printf_filtered ("fv%d_c\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n", 
-		     fv_regnum - FV0_C_REGNUM, 
-		     (int) read_register (first_fp_reg_num),
-		     (int) read_register (first_fp_reg_num + 1),
-		     (int) read_register (first_fp_reg_num + 2),
-		     (int) read_register (first_fp_reg_num + 3));
-}
-
-/* Pairs of single regs. The DR are instead double precision
-   registers.  */
-static void
-do_fpp_register_info (int fpp_regnum)
-{
-  int first_fp_reg_num = fpp_reg_base_num (fpp_regnum);
-
-  printf_filtered ("fpp%d\t0x%08x\t0x%08x\n", 
-		    fpp_regnum - FPP0_REGNUM, 
-		    (int) read_register (first_fp_reg_num),
-		    (int) read_register (first_fp_reg_num + 1));
-}
-
-/* Double precision registers.  */
-static void
-do_dr_register_info (struct gdbarch *gdbarch, struct ui_file *file,
-		     int dr_regnum)
-{
-  int first_fp_reg_num = dr_reg_base_num (dr_regnum);
-
-  fprintf_filtered (file, "dr%d\t0x%08x%08x\n", 
-		    dr_regnum - DR0_REGNUM, 
-		    (int) read_register (first_fp_reg_num),
-		    (int) read_register (first_fp_reg_num + 1));
-}
-
-/* Double precision registers, compact mode.  */
-static void
-do_dr_c_register_info (int dr_regnum)
-{
- int first_fp_reg_num = sh64_compact_reg_base_num (dr_regnum);
-
- printf_filtered ("dr%d_c\t0x%08x%08x\n",
-		  dr_regnum - DR0_C_REGNUM,
-		  (int) read_register (first_fp_reg_num),
-		  (int) read_register (first_fp_reg_num +1));
-}
-
-/* General register in compact mode.  */
-static void
-do_r_c_register_info (int r_c_regnum)
-{
-  int regnum =  sh64_compact_reg_base_num (r_c_regnum);
-
-  printf_filtered ("r%d_c\t0x%08x\n", 
-		    r_c_regnum - R0_C_REGNUM, 
-		   /*FIXME!!!*/  (int) read_register (regnum));
-}
-
 /* FIXME:!! THIS SHOULD TAKE CARE OF GETTING THE RIGHT PORTION OF THE
    shmedia REGISTERS.  */
 /* Control registers, compact mode.  */
 static void
-do_cr_c_register_info (int cr_c_regnum)
+sh64_do_cr_c_register_info (struct ui_file *file, struct frame_info *frame,
+			    int cr_c_regnum)
 {
   switch (cr_c_regnum)
     {
-    case 237: printf_filtered ("pc_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case PC_C_REGNUM:
+      fprintf_filtered (file, "pc_c\t0x%08x\n",
+	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 238: printf_filtered ("gbr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case GBR_C_REGNUM: 
+      fprintf_filtered (file, "gbr_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 239: printf_filtered ("mach_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case MACH_C_REGNUM: 
+      fprintf_filtered (file, "mach_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 240: printf_filtered ("macl_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case MACL_C_REGNUM: 
+      fprintf_filtered (file, "macl_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 241: printf_filtered ("pr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case PR_C_REGNUM: 
+      fprintf_filtered (file, "pr_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 242: printf_filtered ("t_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case T_C_REGNUM: 
+      fprintf_filtered (file, "t_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 243: printf_filtered ("fpscr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
+    case FPSCR_C_REGNUM: 
+      fprintf_filtered (file, "fpscr_c\t0x%08x\n",
+      	  (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
-    case 244: printf_filtered ("fpul_c\t0x%08x\n", (int)read_register (cr_c_regnum));
+    case FPUL_C_REGNUM:
+      fprintf_filtered (file, "fpul_c\t0x%08x\n",
+          (int) get_frame_register_unsigned (frame, cr_c_regnum));
       break;
     }
 }
 
 static void
-sh_do_fp_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
+sh64_do_fp_register (struct gdbarch *gdbarch, struct ui_file *file,
+		     struct frame_info *frame, int regnum)
 {				/* do values for FP (float) regs */
   char *raw_buffer;
   double flt;	/* double extracted from raw hex data */
@@ -2538,7 +1971,7 @@ sh_do_fp_register (struct gdbarch *gdbar
   raw_buffer = (char *) alloca (register_size (gdbarch, FP0_REGNUM));
 
   /* Get the data in raw format.  */
-  if (!frame_register_read (get_selected_frame (NULL), regnum, raw_buffer))
+  if (!frame_register_read (frame, regnum, raw_buffer))
     error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
 
   /* Get the register as a number */ 
@@ -2567,50 +2000,79 @@ sh_do_fp_register (struct gdbarch *gdbar
 }
 
 static void
-sh64_do_pseudo_register (int regnum)
+sh64_do_pseudo_register (struct gdbarch *gdbarch, struct ui_file *file,
+			 struct frame_info *frame, int regnum)
 {
   /* All the sh64-compact mode registers are pseudo registers.  */
 
   if (regnum < NUM_REGS 
-      || regnum >= NUM_REGS + NUM_PSEUDO_REGS_SH_MEDIA + NUM_PSEUDO_REGS_SH_COMPACT)
+      || regnum >= NUM_REGS + NUM_PSEUDO_REGS_SH_MEDIA
+			    + NUM_PSEUDO_REGS_SH_COMPACT)
     internal_error (__FILE__, __LINE__,
 		    _("Invalid pseudo register number %d\n"), regnum);
 
-  else if ((regnum >= DR0_REGNUM
-	    && regnum <= DR_LAST_REGNUM))
-    do_dr_register_info (current_gdbarch, gdb_stdout, regnum);
-
-  else if ((regnum >= DR0_C_REGNUM
-	    && regnum <= DR_LAST_C_REGNUM))
-    do_dr_c_register_info (regnum);
-
-  else if ((regnum >= FV0_REGNUM
-	    && regnum <= FV_LAST_REGNUM))
-    do_fv_register_info (current_gdbarch, gdb_stdout, regnum);
+  else if ((regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM))
+    {
+      int fp_regnum = sh64_dr_reg_base_num (regnum);
+      fprintf_filtered (file, "dr%d\t0x%08x%08x\n", regnum - DR0_REGNUM, 
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum),
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum + 1));
+    }
+
+  else if ((regnum >= DR0_C_REGNUM && regnum <= DR_LAST_C_REGNUM))
+    {
+      int fp_regnum = sh64_compact_reg_base_num (regnum);
+      fprintf_filtered (file, "dr%d_c\t0x%08x%08x\n", regnum - DR0_C_REGNUM,
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum),
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum + 1));
+    }
+
+  else if ((regnum >= FV0_REGNUM && regnum <= FV_LAST_REGNUM))
+    {
+      int fp_regnum = sh64_fv_reg_base_num (regnum);
+      fprintf_filtered (file, "fv%d\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n", 
+	   regnum - FV0_REGNUM, 
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 1),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 2),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 3));
+    }
 	   
-  else if ((regnum >= FV0_C_REGNUM
-	    && regnum <= FV_LAST_C_REGNUM))
-    do_fv_c_register_info (regnum);
-
-  else if (regnum >= FPP0_REGNUM
-	   && regnum <= FPP_LAST_REGNUM)
-    do_fpp_register_info (regnum);
-
-  else if (regnum >= R0_C_REGNUM
-	   && regnum <= R_LAST_C_REGNUM)
-    /* FIXME, this function will not print the right format.  */
-    do_r_c_register_info (regnum);
-  else if (regnum >= FP0_C_REGNUM
-	   && regnum <= FP_LAST_C_REGNUM)
+  else if ((regnum >= FV0_C_REGNUM && regnum <= FV_LAST_C_REGNUM))
+    {
+      int fp_regnum = sh64_compact_reg_base_num (regnum);
+      fprintf_filtered (file, "fv%d_c\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n", 
+	   regnum - FV0_C_REGNUM, 
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 1),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 2),
+	   (unsigned) get_frame_register_unsigned (frame, fp_regnum + 3));
+    }
+
+  else if (regnum >= FPP0_REGNUM && regnum <= FPP_LAST_REGNUM)
+    {
+      int fp_regnum = sh64_fpp_reg_base_num (regnum);
+      fprintf_filtered (file, "fpp%d\t0x%08x\t0x%08x\n", regnum - FPP0_REGNUM, 
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum),
+	  (unsigned) get_frame_register_unsigned (frame, fp_regnum + 1));
+    }
+
+  else if (regnum >= R0_C_REGNUM && regnum <= R_LAST_C_REGNUM)
+    {
+      int c_regnum = sh64_compact_reg_base_num (regnum);
+      fprintf_filtered (file, "r%d_c\t0x%08x\n", regnum - R0_C_REGNUM, 
+	   (unsigned) get_frame_register_unsigned (frame, c_regnum));
+    }
+  else if (regnum >= FP0_C_REGNUM && regnum <= FP_LAST_C_REGNUM)
     /* This should work also for pseudoregs.  */
-    sh_do_fp_register (current_gdbarch, gdb_stdout, regnum);
-  else if (regnum >= PC_C_REGNUM
-	   && regnum <= FPUL_C_REGNUM)
-    do_cr_c_register_info (regnum);
+    sh64_do_fp_register (gdbarch, file, frame, regnum);
+  else if (regnum >= PC_C_REGNUM && regnum <= FPUL_C_REGNUM)
+    sh64_do_cr_c_register_info (file, frame, regnum);
 }
 
 static void
-sh_do_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
+sh64_do_register (struct gdbarch *gdbarch, struct ui_file *file,
+		  struct frame_info *frame, int regnum)
 {
   char raw_buffer[MAX_REGISTER_SIZE];
 
@@ -2618,7 +2080,7 @@ sh_do_register (struct gdbarch *gdbarch,
   print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), file);
 
   /* Get the data in raw format.  */
-  if (!frame_register_read (get_selected_frame (NULL), regnum, raw_buffer))
+  if (!frame_register_read (frame, regnum, raw_buffer))
     fprintf_filtered (file, "*value not available*\n");
       
   val_print (gdbarch_register_type (gdbarch, regnum), raw_buffer, 0, 0,
@@ -2630,7 +2092,8 @@ sh_do_register (struct gdbarch *gdbarch,
 }
 
 static void
-sh_print_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
+sh64_print_register (struct gdbarch *gdbarch, struct ui_file *file,
+		     struct frame_info *frame, int regnum)
 {
   if (regnum < 0 || regnum >= NUM_REGS + NUM_PSEUDO_REGS)
     internal_error (__FILE__, __LINE__,
@@ -2639,25 +2102,26 @@ sh_print_register (struct gdbarch *gdbar
   else if (regnum >= 0 && regnum < NUM_REGS)
     {
       if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
-	sh_do_fp_register (gdbarch, file, regnum);	/* FP regs */
+	sh64_do_fp_register (gdbarch, file, frame, regnum);	/* FP regs */
       else
-	sh_do_register (gdbarch, file, regnum);	/* All other regs */
+	sh64_do_register (gdbarch, file, frame, regnum);
     }
 
   else if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
-    sh64_do_pseudo_register (regnum);
+    sh64_do_pseudo_register (gdbarch, file, frame, regnum);
 }
 
 static void
-sh_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
-			 struct frame_info *frame, int regnum, int fpregs)
+sh64_media_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
+				 struct frame_info *frame, int regnum,
+				 int fpregs)
 {
   if (regnum != -1)		/* do one specified register */
     {
       if (*(REGISTER_NAME (regnum)) == '\0')
 	error ("Not a valid register for the current processor type");
 
-      sh_print_register (gdbarch, file, regnum);
+      sh64_print_register (gdbarch, file, frame, regnum);
     }
   else
     /* do all (or most) registers */
@@ -2674,12 +2138,13 @@ sh_print_registers_info (struct gdbarch 
 	      continue;
 	    }
 
-	  if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
+	  if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum))
+	      == TYPE_CODE_FLT)
 	    {
 	      if (fpregs)
 		{
 		  /* true for "INFO ALL-REGISTERS" command */
-		  sh_do_fp_register (gdbarch, file, regnum);	/* FP regs */
+		  sh64_do_fp_register (gdbarch, file, frame, regnum);
 		  regnum ++;
 		}
 	      else
@@ -2687,7 +2152,7 @@ sh_print_registers_info (struct gdbarch 
 	    }
 	  else
 	    {
-	      sh_do_register (gdbarch, file, regnum);	/* All other regs */
+	      sh64_do_register (gdbarch, file, frame, regnum);
 	      regnum++;
 	    }
 	}
@@ -2695,14 +2160,17 @@ sh_print_registers_info (struct gdbarch 
       if (fpregs)
 	while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
 	  {
-	    sh64_do_pseudo_register (regnum);
+	    sh64_do_pseudo_register (gdbarch, file, frame, regnum);
 	    regnum++;
 	  }
     }
 }
 
 static void
-sh_compact_do_registers_info (int regnum, int fpregs)
+sh64_compact_print_registers_info (struct gdbarch *gdbarch,
+				   struct ui_file *file,
+				   struct frame_info *frame, int regnum,
+				   int fpregs)
 {
   if (regnum != -1)		/* do one specified register */
     {
@@ -2712,7 +2180,7 @@ sh_compact_do_registers_info (int regnum
       if (regnum >= 0 && regnum < R0_C_REGNUM)
         error ("Not a valid register for the current processor mode.");
 
-      sh_print_register (current_gdbarch, gdb_stdout, regnum);
+      sh64_print_register (gdbarch, file, frame, regnum);
     }
   else
     /* do all compact registers */
@@ -2720,64 +2188,227 @@ sh_compact_do_registers_info (int regnum
       regnum = R0_C_REGNUM;
       while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
         {
-          sh64_do_pseudo_register (regnum);
+          sh64_do_pseudo_register (gdbarch, file, frame, regnum);
           regnum++;
         }
     }
 }
 
 static void
-sh64_do_registers_info (int regnum, int fpregs)
+sh64_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
+			   struct frame_info *frame, int regnum, int fpregs)
 {
-  if (pc_is_isa32 (get_frame_pc (deprecated_selected_frame)))
-   sh_print_registers_info (current_gdbarch, gdb_stdout,
-			    deprecated_selected_frame, regnum, fpregs);
+  if (pc_is_isa32 (get_frame_pc (frame)))
+    sh64_media_print_registers_info (gdbarch, file, frame, regnum, fpregs);
   else
-   sh_compact_do_registers_info (regnum, fpregs);
+    sh64_compact_print_registers_info (gdbarch, file, frame, regnum, fpregs);
 }
 
-/* Fetch (and possibly build) an appropriate link_map_offsets structure
-   for native i386 linux targets using the struct offsets defined in
-   link.h (but without actual reference to that file).
+static struct sh64_frame_cache *
+sh64_alloc_frame_cache (void)
+{
+  struct sh64_frame_cache *cache;
+  int i;
+
+  cache = FRAME_OBSTACK_ZALLOC (struct sh64_frame_cache);
 
-   This makes it possible to access i386-linux shared libraries from
-   a gdb that was not built on an i386-linux host (for cross debugging).
-   */
+  /* Base address.  */
+  cache->base = 0;
+  cache->saved_sp = 0;
+  cache->sp_offset = 0;
+  cache->pc = 0;
 
-struct link_map_offsets *
-sh_linux_svr4_fetch_link_map_offsets (void)
+  /* Frameless until proven otherwise.  */
+  cache->uses_fp = 0;
+
+  /* Saved registers.  We initialize these to -1 since zero is a valid
+     offset (that's where fp is supposed to be stored).  */
+  for (i = 0; i < SIM_SH64_NR_REGS; i++)
+    {
+      cache->saved_regs[i] = -1;
+    }
+
+  return cache;
+}
+
+static struct sh64_frame_cache *
+sh64_frame_cache (struct frame_info *next_frame, void **this_cache)
 {
-  static struct link_map_offsets lmo;
-  static struct link_map_offsets *lmp = 0;
+  struct sh64_frame_cache *cache;
+  CORE_ADDR current_pc;
+  int i;
+
+  if (*this_cache)
+    return *this_cache;
+
+  cache = sh64_alloc_frame_cache ();
+  *this_cache = cache;
+
+  current_pc = frame_pc_unwind (next_frame);
+  cache->media_mode = pc_is_isa32 (current_pc);
+
+  /* In principle, for normal frames, fp holds the frame pointer,
+     which holds the base address for the current stack frame.
+     However, for functions that don't need it, the frame pointer is
+     optional.  For these "frameless" functions the frame pointer is
+     actually the frame pointer of the calling frame. */
+  cache->base = frame_unwind_register_unsigned (next_frame, MEDIA_FP_REGNUM);
+  if (cache->base == 0)
+    return cache;
+
+  cache->pc = frame_func_unwind (next_frame);
+  if (cache->pc != 0)
+    sh64_analyze_prologue (current_gdbarch, cache, cache->pc, current_pc);
 
-  if (lmp == 0)
+  if (!cache->uses_fp)
     {
-      lmp = &lmo;
+      /* We didn't find a valid frame, which means that CACHE->base
+         currently holds the frame pointer for our calling frame.  If
+         we're at the start of a function, or somewhere half-way its
+         prologue, the function's frame probably hasn't been fully
+         setup yet.  Try to reconstruct the base address for the stack
+         frame by looking at the stack pointer.  For truly "frameless"
+         functions this might work too.  */
+      cache->base = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
+    }
+
+  /* Now that we have the base address for the stack frame we can
+     calculate the value of sp in the calling frame.  */
+  cache->saved_sp = cache->base + cache->sp_offset;
+
+  /* Adjust all the saved registers such that they contain addresses
+     instead of offsets.  */
+  for (i = 0; i < SIM_SH64_NR_REGS; i++)
+    if (cache->saved_regs[i] != -1)
+      cache->saved_regs[i] = cache->saved_sp - cache->saved_regs[i];
 
-      lmo.r_debug_size = 8;	/* 20 not actual size but all we need */
+  return cache;
+}
 
-      lmo.r_map_offset = 4;
-      lmo.r_map_size   = 4;
+static void
+sh64_frame_prev_register (struct frame_info *next_frame, void **this_cache,
+			  int regnum, int *optimizedp,
+			  enum lval_type *lvalp, CORE_ADDR *addrp,
+			  int *realnump, void *valuep)
+{
+  struct sh64_frame_cache *cache = sh64_frame_cache (next_frame, this_cache);
 
-      lmo.link_map_size = 20;	/* 552 not actual size but all we need */
+  gdb_assert (regnum >= 0);
 
-      lmo.l_addr_offset = 0;
-      lmo.l_addr_size   = 4;
+  if (regnum == SP_REGNUM && cache->saved_sp)
+    {
+      *optimizedp = 0;
+      *lvalp = not_lval;
+      *addrp = 0;
+      *realnump = -1;
+      if (valuep)
+        {
+          /* Store the value.  */
+          store_unsigned_integer (valuep,
+	  			  register_size (current_gdbarch, SP_REGNUM),
+				  cache->saved_sp);
+        }
+      return;
+    }
 
-      lmo.l_name_offset = 4;
-      lmo.l_name_size   = 4;
+  /* The PC of the previous frame is stored in the PR register of
+     the current frame.  Frob regnum so that we pull the value from
+     the correct place.  */
+  if (regnum == PC_REGNUM)
+    regnum = PR_REGNUM;
 
-      lmo.l_next_offset = 12;
-      lmo.l_next_size   = 4;
+  if (regnum < SIM_SH64_NR_REGS && cache->saved_regs[regnum] != -1)
+    {
+      int reg_size = register_size (current_gdbarch, regnum);
+      int size;
 
-      lmo.l_prev_offset = 16;
-      lmo.l_prev_size   = 4;
+      *optimizedp = 0;
+      *lvalp = lval_memory;
+      *addrp = cache->saved_regs[regnum];
+      *realnump = -1;
+      if (gdbarch_tdep (current_gdbarch)->sh_abi == SH_ABI_32
+          && (regnum == MEDIA_FP_REGNUM || regnum == PR_REGNUM))
+	size = 4;
+      else
+        size = reg_size;
+      if (valuep)
+        {
+	  memset (valuep, 0, reg_size);
+	  if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
+	    read_memory (*addrp, valuep, size);
+	  else
+	    read_memory (*addrp, (char *) valuep + reg_size - size, size);
+        }
+      return;
     }
 
-    return lmp;
+  *optimizedp = 0;
+  *lvalp = lval_register;
+  *addrp = 0;
+  *realnump = regnum;
+  if (valuep)
+    frame_unwind_register (next_frame, (*realnump), valuep);
+}
+
+static void
+sh64_frame_this_id (struct frame_info *next_frame, void **this_cache,
+		    struct frame_id *this_id)
+{
+  struct sh64_frame_cache *cache = sh64_frame_cache (next_frame, this_cache);
+
+  /* This marks the outermost frame.  */
+  if (cache->base == 0)
+    return;
+
+  *this_id = frame_id_build (cache->saved_sp, cache->pc);
+}
+
+static const struct frame_unwind sh64_frame_unwind = {
+  NORMAL_FRAME,
+  sh64_frame_this_id,
+  sh64_frame_prev_register
+};
+
+static const struct frame_unwind *
+sh64_frame_sniffer (struct frame_info *next_frame)
+{
+  return &sh64_frame_unwind;
+}
+
+static CORE_ADDR
+sh64_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+  return frame_unwind_register_unsigned (next_frame, SP_REGNUM);
+}
+
+static CORE_ADDR
+sh64_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+  return frame_unwind_register_unsigned (next_frame, PC_REGNUM);
 }
 
-gdbarch_init_ftype sh64_gdbarch_init;
+static struct frame_id
+sh64_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
+{
+  return frame_id_build (sh64_unwind_sp (gdbarch, next_frame),
+                         frame_pc_unwind (next_frame));
+}
+
+static CORE_ADDR
+sh64_frame_base_address (struct frame_info *next_frame, void **this_cache)
+{
+  struct sh64_frame_cache *cache = sh64_frame_cache (next_frame, this_cache);
+
+  return cache->base;
+}
+
+static const struct frame_base sh64_frame_base = {
+  &sh64_frame_unwind,
+  sh64_frame_base_address,
+  sh64_frame_base_address,
+  sh64_frame_base_address
+};
+
 
 struct gdbarch *
 sh64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
@@ -2795,10 +2426,6 @@ sh64_gdbarch_init (struct gdbarch_info i
   tdep = XMALLOC (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
-  /* 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);
-
   /* Determine the ABI */
   if (info.abfd && bfd_get_arch_size (info.abfd) == 64)
     {
@@ -2818,63 +2445,61 @@ sh64_gdbarch_init (struct gdbarch_info i
 
   set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
   set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
+  set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
   set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
   set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
   set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
   set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
 
+  /* The number of real registers is the same whether we are in 
+     ISA16(compact) or ISA32(media).  */
+  set_gdbarch_num_regs (gdbarch, SIM_SH64_NR_REGS);
   set_gdbarch_sp_regnum (gdbarch, 15);
-  set_gdbarch_deprecated_fp_regnum (gdbarch, 14);
+  set_gdbarch_pc_regnum (gdbarch, 64);
+  set_gdbarch_fp0_regnum (gdbarch, SIM_SH64_FR0_REGNUM);
+  set_gdbarch_num_pseudo_regs (gdbarch, NUM_PSEUDO_REGS_SH_MEDIA
+  					+ NUM_PSEUDO_REGS_SH_COMPACT);
+
+  set_gdbarch_register_name (gdbarch, sh64_register_name);
+  set_gdbarch_register_type (gdbarch, sh64_register_type);
+
+  set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
+  set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
+
+  set_gdbarch_breakpoint_from_pc (gdbarch, sh64_breakpoint_from_pc);
 
-  set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh);
+  set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh64);
   set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
 
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
 
-  set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
-  set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
+  set_gdbarch_return_value (gdbarch, sh64_return_value);
+  set_gdbarch_deprecated_extract_struct_value_address (gdbarch,
+					    sh64_extract_struct_value_address);
 
-  set_gdbarch_believe_pcc_promotion (gdbarch, 1);
+  set_gdbarch_skip_prologue (gdbarch, sh64_skip_prologue);
+  set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_deprecated_frame_saved_pc (gdbarch, sh_frame_saved_pc);
-  set_gdbarch_deprecated_saved_pc_after_call (gdbarch, sh_saved_pc_after_call);
-  set_gdbarch_frame_align (gdbarch, sh_frame_align);
+  set_gdbarch_push_dummy_call (gdbarch, sh64_push_dummy_call);
 
-  set_gdbarch_num_pseudo_regs (gdbarch, NUM_PSEUDO_REGS_SH_MEDIA + NUM_PSEUDO_REGS_SH_COMPACT);
-  set_gdbarch_fp0_regnum (gdbarch, SIM_SH64_FR0_REGNUM);
-  set_gdbarch_pc_regnum (gdbarch, 64);
+  set_gdbarch_believe_pcc_promotion (gdbarch, 1);
 
-  /* The number of real registers is the same whether we are in 
-     ISA16(compact) or ISA32(media).  */
-  set_gdbarch_num_regs (gdbarch, SIM_SH64_NR_REGS);
+  set_gdbarch_frame_align (gdbarch, sh64_frame_align);
+  set_gdbarch_unwind_sp (gdbarch, sh64_unwind_sp);
+  set_gdbarch_unwind_pc (gdbarch, sh64_unwind_pc);
+  set_gdbarch_unwind_dummy_id (gdbarch, sh64_unwind_dummy_id);
+  frame_base_set_default (gdbarch, &sh64_frame_base);
 
-  set_gdbarch_register_name (gdbarch, sh64_register_name);
-  set_gdbarch_register_type (gdbarch, sh64_register_type);
-  set_gdbarch_deprecated_store_return_value (gdbarch, sh64_store_return_value);
-  set_gdbarch_deprecated_register_byte (gdbarch, sh64_register_byte);
-  set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
-  set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
+  set_gdbarch_print_registers_info (gdbarch, sh64_print_registers_info);
 
-  set_gdbarch_deprecated_do_registers_info (gdbarch, sh64_do_registers_info);
-  set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, sh64_nofp_frame_init_saved_regs);
-  set_gdbarch_breakpoint_from_pc (gdbarch, sh64_breakpoint_from_pc);
-
-  set_gdbarch_deprecated_init_extra_frame_info (gdbarch, sh64_init_extra_frame_info);
-  set_gdbarch_deprecated_frame_chain (gdbarch, sh64_frame_chain);
-  set_gdbarch_deprecated_get_saved_register (gdbarch, sh64_get_saved_register);
-  set_gdbarch_deprecated_extract_return_value (gdbarch, sh64_extract_return_value);
-  set_gdbarch_deprecated_push_arguments (gdbarch, sh64_push_arguments);
-  set_gdbarch_deprecated_push_return_address (gdbarch, sh64_push_return_address);
-  set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
-  set_gdbarch_deprecated_store_struct_return (gdbarch, sh64_store_struct_return);
-  set_gdbarch_deprecated_extract_struct_value_address (gdbarch, sh64_extract_struct_value_address);
-  set_gdbarch_deprecated_use_struct_convention (gdbarch, sh64_use_struct_convention);
-  set_gdbarch_deprecated_pop_frame (gdbarch, sh64_pop_frame);
   set_gdbarch_elf_make_msymbol_special (gdbarch,
 					sh64_elf_make_msymbol_special);
 
   /* Hook in ABI-specific overrides, if they have been registered.  */
   gdbarch_init_osabi (info, gdbarch);
 
+  frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
+  frame_unwind_append_sniffer (gdbarch, sh64_frame_sniffer);
+
   return gdbarch;
 }
Index: config/sh/embed.mt
===================================================================
RCS file: /cvs/src/src/gdb/config/sh/embed.mt,v
retrieving revision 1.5
diff -u -p -r1.5 embed.mt
--- config/sh/embed.mt	13 Sep 2004 20:55:41 -0000	1.5
+++ config/sh/embed.mt	30 Mar 2005 17:22:05 -0000
@@ -1,5 +1,5 @@
 # Target: Embedded Renesas Super-H with ICE and simulator
-TDEPFILES= sh-tdep.o monitor.o sh3-rom.o remote-e7000.o ser-e7kpc.o dsrec.o 
+TDEPFILES= sh-tdep.o sh64-tdep.o monitor.o sh3-rom.o remote-e7000.o ser-e7kpc.o dsrec.o 
 DEPRECATED_TM_FILE= tm-sh.h
 
 SIM_OBS = remote-sim.o
Index: config/sh/sh64.mt
===================================================================
RCS file: config/sh/sh64.mt
diff -N config/sh/sh64.mt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/sh/sh64.mt	30 Mar 2005 17:22:05 -0000
@@ -0,0 +1,6 @@
+# Target: Hitachi Super-H 64 bit with simulator
+TDEPFILES= sh-tdep.o sh64-tdep.o solib.o solib-svr4.o
+DEPRECATED_TM_FILE= tm-sh64.h
+
+SIM_OBS = remote-sim.o
+SIM = ../sim/sh64/libsim.a
Index: config/sh/tm-sh64.h
===================================================================
RCS file: config/sh/tm-sh64.h
diff -N config/sh/tm-sh64.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/sh/tm-sh64.h	30 Mar 2005 17:22:05 -0000
@@ -0,0 +1,22 @@
+/* Support for SH64, for GDB, the GNU debugger.
+   Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* Pull in Linux generic defs */
+#include "tm-linux.h"

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]