* inferior.h (read_sp): Remove prototype.
[platform/upstream/binutils.git] / gdb / regcache.c
index 508d3a2..bb9cfde 100644 (file)
@@ -381,19 +381,29 @@ regcache_dup_no_passthrough (struct regcache *src)
 }
 
 int
-regcache_valid_p (struct regcache *regcache, int regnum)
+regcache_valid_p (const struct regcache *regcache, int regnum)
 {
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
+  gdb_assert (regnum >= 0);
+  if (regcache->readonly_p)
+    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
+  else
+    gdb_assert (regnum < regcache->descr->nr_raw_registers);
+
   return regcache->register_valid_p[regnum];
 }
 
-gdb_byte *
-deprecated_grub_regcache_for_registers (struct regcache *regcache)
+void
+regcache_invalidate (struct regcache *regcache, int regnum)
 {
-  return regcache->registers;
+  gdb_assert (regcache != NULL);
+  gdb_assert (regnum >= 0);
+  gdb_assert (!regcache->readonly_p);
+  gdb_assert (regnum < regcache->descr->nr_raw_registers);
+  regcache->register_valid_p[regnum] = 0;
 }
 
+
 /* Global structure containing the current regcache.  */
 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
    deprecated_register_valid[] currently point into this structure.  */
@@ -408,33 +418,6 @@ struct regcache *current_regcache;
 
 static ptid_t registers_ptid;
 
-/*
- * FUNCTIONS:
- */
-
-/* REGISTER_CACHED()
-
-   Returns 0 if the value is not in the cache (needs fetch).
-          >0 if the value is in the cache.
-         <0 if the value is permanently unavailable (don't ask again).  */
-
-int
-register_cached (int regnum)
-{
-  return current_regcache->register_valid_p[regnum];
-}
-
-/* Record that REGNUM's value is cached if STATE is >0, uncached but
-   fetchable if STATE is 0, and uncached and unfetchable if STATE is <0.  */
-
-void
-set_register_cached (int regnum, int state)
-{
-  gdb_assert (regnum >= 0);
-  gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
-  current_regcache->register_valid_p[regnum] = state;
-}
-
 /* Observer for the target_changed event.  */
 
 void
@@ -469,31 +452,9 @@ registers_changed (void)
   alloca (0);
 
   for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
-    set_register_cached (i, 0);
-
-  if (deprecated_registers_changed_hook)
-    deprecated_registers_changed_hook ();
+    regcache_invalidate (current_regcache, i);
 }
 
-/* DEPRECATED_REGISTERS_FETCHED ()
-
-   Indicate that all registers have been fetched, so mark them all valid.  */
-
-/* FIXME: cagney/2001-12-04: This function is DEPRECATED.  The target
-   code was blatting the registers[] array and then calling this.
-   Since targets should only be using regcache_raw_supply() the need for
-   this function/hack is eliminated.  */
-
-void
-deprecated_registers_fetched (void)
-{
-  int i;
-
-  for (i = 0; i < NUM_REGS; i++)
-    set_register_cached (i, 1);
-  /* Do not assume that the pseudo-regs have also been fetched.
-     Fetching all real regs NEVER accounts for pseudo-regs.  */
-}
 
 void
 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
@@ -512,8 +473,8 @@ regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
          registers_changed ();
          registers_ptid = inferior_ptid;
        }
-      if (!register_cached (regnum))
-       target_fetch_registers (regnum);
+      if (!regcache_valid_p (regcache, regnum))
+       target_fetch_registers (regcache, regnum);
 #if 0
       /* FIXME: cagney/2004-08-07: At present a number of targets
         forget (or didn't know that they needed) to set this leading to
@@ -521,7 +482,7 @@ regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
         that a register is in one of the possible states: valid,
         undefined, unknown.  The last of which isn't yet
         possible.  */
-      gdb_assert (register_cached (regnum));
+      gdb_assert (regcache_valid_p (regcache, regnum));
 #endif
     }
   /* Copy the value directly into the register cache.  */
@@ -578,14 +539,6 @@ regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
 }
 
 void
-deprecated_read_register_gen (int regnum, gdb_byte *buf)
-{
-  gdb_assert (current_regcache != NULL);
-  gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
-  regcache_cooked_read (current_regcache, regnum, buf);
-}
-
-void
 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
 {
   gdb_assert (regnum >= 0);
@@ -681,19 +634,11 @@ regcache_raw_write (struct regcache *regcache, int regnum,
                  regcache->descr->sizeof_register[regnum]) == 0))
     return;
 
-  target_prepare_to_store ();
+  target_prepare_to_store (regcache);
   memcpy (register_buffer (regcache, regnum), buf,
          regcache->descr->sizeof_register[regnum]);
   regcache->register_valid_p[regnum] = 1;
-  target_store_registers (regnum);
-}
-
-void
-deprecated_write_register_gen (int regnum, gdb_byte *buf)
-{
-  gdb_assert (current_regcache != NULL);
-  gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
-  regcache_cooked_write (current_regcache, regnum, buf);
+  target_store_registers (regcache, regnum);
 }
 
 void
@@ -810,7 +755,9 @@ ULONGEST
 read_register (int regnum)
 {
   gdb_byte *buf = alloca (register_size (current_gdbarch, regnum));
-  deprecated_read_register_gen (regnum, buf);
+  gdb_assert (current_regcache != NULL);
+  gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
+  regcache_cooked_read (current_regcache, regnum, buf);
   return (extract_unsigned_integer (buf, register_size (current_gdbarch, regnum)));
 }
 
@@ -845,7 +792,9 @@ write_register (int regnum, LONGEST val)
   size = register_size (current_gdbarch, regnum);
   buf = alloca (size);
   store_signed_integer (buf, size, (LONGEST) val);
-  deprecated_write_register_gen (regnum, buf);
+  gdb_assert (current_regcache != NULL);
+  gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
+  regcache_cooked_write (current_regcache, regnum, buf);
 }
 
 void
@@ -918,8 +867,7 @@ regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
 }
 
 
-/* read_pc, write_pc, read_sp, etc.  Special handling for registers
-   PC, SP, and FP.  */
+/* read_pc, write_pc, etc.  Special handling for register PC.  */
 
 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc() and
    read_sp(), will eventually be replaced by per-frame methods.
@@ -992,21 +940,6 @@ write_pc (CORE_ADDR pc)
   write_pc_pid (pc, inferior_ptid);
 }
 
-/* Cope with strage ways of getting to the stack and frame pointers */
-
-CORE_ADDR
-read_sp (void)
-{
-  if (TARGET_READ_SP_P ())
-    return TARGET_READ_SP ();
-  else if (gdbarch_unwind_sp_p (current_gdbarch))
-    return get_frame_sp (get_current_frame ());
-  else if (SP_REGNUM >= 0)
-    /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions
-       about the architecture so put it at the end.  */
-    return read_register (SP_REGNUM);
-  internal_error (__FILE__, __LINE__, _("read_sp: Unable to find SP"));
-}
 
 static void
 reg_flush_command (char *command, int from_tty)
@@ -1116,7 +1049,6 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
          fprintf_unfiltered (file, " %6ld",
                              regcache->descr->register_offset[regnum]);
          if (register_offset != regcache->descr->register_offset[regnum]
-             || register_offset != DEPRECATED_REGISTER_BYTE (regnum)
              || (regnum > 0
                  && (regcache->descr->register_offset[regnum]
                      != (regcache->descr->register_offset[regnum - 1]