/* 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 ®isters[REGISTER_BYTE (regnum)];
+ gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
+ return ®isters[REGISTER_BYTE (regnum)];
}
/* Return whether register REGNUM is a real register. */
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. */
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.
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)
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)
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*
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;
/* 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
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);
}
size = REGISTER_RAW_SIZE (regnum);
- /* If we have a valid copy of the register, and new value == old value,
- then don't bother doing the actual store. */
-
- if (register_cached (regnum)
- && memcmp (register_buffer (regnum), myaddr, size) == 0)
- return;
-
if (real_register (regnum))
- target_prepare_to_store ();
+ {
+ /* If we have a valid copy of the register, and new value == old
+ value, then don't bother doing the actual store. */
+ if (register_cached (regnum)
+ && memcmp (register_buffer (regnum), myaddr, size) == 0)
+ return;
+ else
+ target_prepare_to_store ();
+ }
memcpy (register_buffer (regnum), myaddr, size);
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);
}
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
}
+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, write_fp, etc.
Special handling for registers PC, SP, and FP. */
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);
}