Set default LANGUAGE to english/us.
[deliverable/binutils-gdb.git] / gdb / regcache.c
index ffd13bf8a4ba510365bdf2b961bfcb85943af229..8c1a0aa4e6865112a869ada2875bad52c51a5621 100644 (file)
@@ -90,13 +90,11 @@ register_changed (int regnum)
 /* If REGNUM >= 0, return a pointer to register REGNUM's cache buffer area,
    else return a pointer to the start of the cache buffer.  */
 
-char *
+static char *
 register_buffer (int regnum)
 {
-  if (regnum < 0)
-    return registers;
-  else
-    return &registers[REGISTER_BYTE (regnum)];
+  gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
+  return &registers[REGISTER_BYTE (regnum)];
 }
 
 /* Return whether register REGNUM is a real register.  */
@@ -120,10 +118,15 @@ pseudo_register (int regnum)
 static void
 fetch_register (int regnum)
 {
-  if (real_register (regnum))
-    target_fetch_registers (regnum);
-  else if (pseudo_register (regnum))
+  /* NOTE: cagney/2001-12-04: Legacy targets were using fetch/store
+     pseudo-register as a way of handling registers that needed to be
+     constructed from one or more raw registers.  New targets instead
+     use gdbarch register read/write.  */
+  if (FETCH_PSEUDO_REGISTER_P ()
+      && pseudo_register (regnum))
     FETCH_PSEUDO_REGISTER (regnum);
+  else
+    target_fetch_registers (regnum);
 }
 
 /* Write register REGNUM cached value to the target.  */
@@ -131,10 +134,15 @@ fetch_register (int regnum)
 static void
 store_register (int regnum)
 {
-  if (real_register (regnum))
-    target_store_registers (regnum);
-  else if (pseudo_register (regnum))
+  /* NOTE: cagney/2001-12-04: Legacy targets were using fetch/store
+     pseudo-register as a way of handling registers that needed to be
+     constructed from one or more raw registers.  New targets instead
+     use gdbarch register read/write.  */
+  if (STORE_PSEUDO_REGISTER_P ()
+      && pseudo_register (regnum))
     STORE_PSEUDO_REGISTER (regnum);
+  else
+    target_store_registers (regnum);
 }
 
 /* Low level examining and depositing of registers.
@@ -162,12 +170,7 @@ registers_changed (void)
      gdb gives control to the user (ie watchpoints).  */
   alloca (0);
 
-  for (i = 0; i < NUM_REGS; i++)
-    set_register_cached (i, 0);
-
-  /* Assume that if all the hardware regs have changed, 
-     then so have the pseudo-registers.  */
-  for (i = NUM_REGS; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
+  for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
     set_register_cached (i, 0);
 
   if (registers_changed_hook)
@@ -178,6 +181,13 @@ registers_changed (void)
 
    Indicate that all registers have been fetched, so mark them all valid.  */
 
+/* NOTE: cagney/2001-12-04: This function does not set valid on the
+   pseudo-register range since pseudo registers are always supplied
+   using supply_register().  */
+/* 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 supply_register() the need for
+   this function/hack is eliminated.  */
 
 void
 registers_fetched (void)
@@ -187,7 +197,7 @@ registers_fetched (void)
   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 might not account for all pseudo-regs.  */
+     Fetching all real regs NEVER accounts for pseudo-regs.  */
 }
 
 /* read_register_bytes and write_register_bytes are generally a *BAD*
@@ -230,9 +240,6 @@ read_register_bytes (int in_start, char *in_buf, int in_len)
       int end;
       int byte;
 
-      if (REGISTER_NAME (regnum) == NULL || *REGISTER_NAME (regnum) == '\0')
-       continue;
-
       reg_start = REGISTER_BYTE (regnum);
       reg_len = REGISTER_RAW_SIZE (regnum);
       reg_end = reg_start + reg_len;
@@ -241,8 +248,18 @@ read_register_bytes (int in_start, char *in_buf, int in_len)
        /* The range the user wants to read doesn't overlap with regnum.  */
        continue;
 
-      /* Force the cache to fetch the entire register. */
-      read_register_gen (regnum, reg_buf);
+      if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
+       /* Force the cache to fetch the entire register.  */
+       read_register_gen (regnum, reg_buf);
+      else
+       /* Legacy note: even though this register is ``invalid'' we
+           still need to return something.  It would appear that some
+           code relies on apparent gaps in the register array also
+           being returned.  */
+       /* FIXME: cagney/2001-08-18: This is just silly.  It defeats
+           the entire register read/write flow of control.  Must
+           resist temptation to return 0xdeadbeef.  */
+       memcpy (reg_buf, registers + reg_start, reg_len);
 
       /* Legacy note: This function, for some reason, allows a NULL
          input buffer.  If the buffer is NULL, the registers are still
@@ -295,7 +312,7 @@ legacy_read_register_gen (int regnum, char *myaddr)
 void
 regcache_read (int rawnum, char *buf)
 {
-  gdb_assert (rawnum >= 0 && rawnum < NUM_REGS);
+  gdb_assert (rawnum >= 0 && rawnum < (NUM_REGS + NUM_PSEUDO_REGS));
   /* For moment, just use underlying legacy code. Ulgh!!! */
   legacy_read_register_gen (rawnum, buf);
 }
@@ -354,7 +371,7 @@ legacy_write_register_gen (int regnum, char *myaddr)
 void
 regcache_write (int rawnum, char *buf)
 {
-  gdb_assert (rawnum >= 0 && rawnum < NUM_REGS);
+  gdb_assert (rawnum >= 0 && rawnum < (NUM_REGS + NUM_PSEUDO_REGS));
   /* For moment, just use underlying legacy code. Ulgh!!! */
   legacy_write_register_gen (rawnum, buf);
 }
@@ -556,21 +573,28 @@ supply_register (int regnum, char *val)
      through the method gdbarch_register_read() clean up the
      values. */
 
-#ifdef CLEAN_UP_REGISTER_VALUE
-  CLEAN_UP_REGISTER_VALUE (regnum, register_buffer (regnum));
+#ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
+  DEPRECATED_CLEAN_UP_REGISTER_VALUE (regnum, register_buffer (regnum));
 #endif
 }
 
-/* read_pc, write_pc, read_sp, write_sp, read_fp, write_fp, etc.
-   Special handling for registers PC, SP, and FP.  */
+void
+regcache_collect (int regnum, void *buf)
+{
+  memcpy (buf, register_buffer (regnum), REGISTER_RAW_SIZE (regnum));
+}
+
+
+/* read_pc, write_pc, read_sp, write_sp, read_fp, etc.  Special
+   handling for registers PC, SP, and FP.  */
 
 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
    read_pc_pid(), read_pc(), generic_target_write_pc(),
    write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
-   generic_target_write_sp(), write_sp(), generic_target_read_fp(),
-   read_fp(), generic_target_write_fp(), write_fp will eventually be
-   moved out of the reg-cache into either frame.[hc] or to the
-   multi-arch framework.  The are not part of the raw register cache.  */
+   generic_target_write_sp(), write_sp(), generic_target_read_fp() and
+   read_fp(), will eventually be moved out of the reg-cache into
+   either frame.[hc] or to the multi-arch framework.  The are not part
+   of the raw register cache.  */
 
 /* This routine is getting awfully cluttered with #if's.  It's probably
    time to turn this into READ_PC and define it in the tm.h file.
@@ -714,26 +738,6 @@ read_fp (void)
   return TARGET_READ_FP ();
 }
 
-void
-generic_target_write_fp (CORE_ADDR val)
-{
-#ifdef FP_REGNUM
-  if (FP_REGNUM >= 0)
-    {
-      write_register (FP_REGNUM, val);
-      return;
-    }
-#endif
-  internal_error (__FILE__, __LINE__,
-                 "generic_target_write_fp");
-}
-
-void
-write_fp (CORE_ADDR val)
-{
-  TARGET_WRITE_FP (val);
-}
-
 /* ARGSUSED */
 static void
 reg_flush_command (char *command, int from_tty)
@@ -744,17 +748,33 @@ reg_flush_command (char *command, int from_tty)
     printf_filtered ("Register cache flushed.\n");
 }
 
-
 static void
 build_regcache (void)
 {
-  /* We allocate some extra slop since we do a lot of memcpy's around
-     `registers', and failing-soft is better than failing hard.  */
-  int sizeof_registers = REGISTER_BYTES + /* SLOP */ 256;
-  int sizeof_register_valid = 
-    (NUM_REGS + NUM_PSEUDO_REGS) * sizeof (*register_valid);
+  int i;
+  int sizeof_register_valid;
+  /* Come up with the real size of the registers buffer.  */
+  int sizeof_registers = REGISTER_BYTES; /* OK use.  */
+  for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
+    {
+      long regend;
+      /* Keep extending the buffer so that there is always enough
+         space for all registers.  The comparison is necessary since
+         legacy code is free to put registers in random places in the
+         buffer separated by holes.  Once REGISTER_BYTE() is killed
+         this can be greatly simplified.  */
+      /* FIXME: cagney/2001-12-04: This code shouldn't need to use
+         REGISTER_BYTE().  Unfortunatly, legacy code likes to lay the
+         buffer out so that certain registers just happen to overlap.
+         Ulgh!  New targets use gdbarch's register read/write and
+         entirely avoid this uglyness.  */
+      regend = REGISTER_BYTE (i) + REGISTER_RAW_SIZE (i);
+      if (sizeof_registers < regend)
+       sizeof_registers = regend;
+    }
   registers = xmalloc (sizeof_registers);
-  memset (registers, 0, sizeof_registers);
+  sizeof_register_valid = ((NUM_REGS + NUM_PSEUDO_REGS)
+                          * sizeof (*register_valid));
   register_valid = xmalloc (sizeof_register_valid);
   memset (register_valid, 0, sizeof_register_valid);
 }
@@ -762,8 +782,6 @@ build_regcache (void)
 void
 _initialize_regcache (void)
 {
-  build_regcache ();
-
   register_gdbarch_swap (&registers, sizeof (registers), NULL);
   register_gdbarch_swap (&register_valid, sizeof (register_valid), NULL);
   register_gdbarch_swap (NULL, 0, build_regcache);
This page took 0.025809 seconds and 4 git commands to generate.