+static void
+fetch_register (struct regcache *regcache, int regno)
+{
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ long regaddr;
+ int i;
+ char buf[MAX_REGISTER_SIZE];
+ int tid;
+
+ /* Overload thread id onto process id */
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
+ tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
+
+ regaddr = 4 * regmap[regno];
+ for (i = 0; i < register_size (gdbarch, regno); i += sizeof (long))
+ {
+ errno = 0;
+ *(long *) &buf[i] = ptrace (PTRACE_PEEKUSER, tid, regaddr, 0);
+ regaddr += sizeof (long);
+ if (errno != 0)
+ error (_("Couldn't read register %s (#%d): %s."),
+ gdbarch_register_name (gdbarch, regno),
+ regno, safe_strerror (errno));
+ }
+ regcache_raw_supply (regcache, regno, buf);
+}
+
+/* Fetch register values from the inferior.
+ If REGNO is negative, do this for all registers.
+ Otherwise, REGNO specifies which register (so we can save time). */
+
+static void
+old_fetch_inferior_registers (struct regcache *regcache, int regno)
+{
+ if (regno >= 0)
+ {
+ fetch_register (regcache, regno);
+ }
+ else
+ {
+ for (regno = 0;
+ regno < gdbarch_num_regs (get_regcache_arch (regcache));
+ regno++)
+ {
+ fetch_register (regcache, regno);
+ }
+ }
+}
+
+/* Store one register. */
+
+static void
+store_register (const struct regcache *regcache, int regno)
+{
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ long regaddr;
+ int i;
+ int tid;
+ char buf[MAX_REGISTER_SIZE];
+
+ /* Overload thread id onto process id */
+ tid = TIDGET (inferior_ptid);
+ if (tid == 0)
+ tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
+
+ regaddr = 4 * regmap[regno];
+
+ /* Put the contents of regno into a local buffer */
+ regcache_raw_collect (regcache, regno, buf);
+
+ /* Store the local buffer into the inferior a chunk at the time. */
+ for (i = 0; i < register_size (gdbarch, regno); i += sizeof (long))
+ {
+ errno = 0;
+ ptrace (PTRACE_POKEUSER, tid, regaddr, *(long *) &buf[i]);
+ regaddr += sizeof (long);
+ if (errno != 0)
+ error (_("Couldn't write register %s (#%d): %s."),
+ gdbarch_register_name (gdbarch, regno),
+ regno, safe_strerror (errno));
+ }
+}
+
+/* Store our register values back into the inferior.
+ If REGNO is negative, do this for all registers.
+ Otherwise, REGNO specifies which register (so we can save time). */
+
+static void
+old_store_inferior_registers (const struct regcache *regcache, int regno)
+{
+ if (regno >= 0)
+ {
+ store_register (regcache, regno);
+ }
+ else
+ {
+ for (regno = 0;
+ regno < gdbarch_num_regs (get_regcache_arch (regcache));
+ regno++)
+ {
+ store_register (regcache, regno);
+ }
+ }
+}
+\f
+/* Given a pointer to a general register set in /proc format
+ (elf_gregset_t *), unpack the register contents and supply
+ them as gdb's idea of the current register values. */