/* REGISTER_VALID is 0 if the register needs to be fetched,
1 if it has been fetched, and
-1 if the register value was not available.
- "Not available" means don't try to fetch it again. */
+
+ "Not available" indicates that the target is not not able to supply
+ the register at this state. The register may become available at a
+ later time (after the next resume). This often occures when GDB is
+ manipulating a target that contains only a snapshot of the entire
+ system being debugged - some of the registers in such a system may
+ not have been saved. */
signed char *register_valid;
/* 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);
}
/* Write register REGNUM at MYADDR to the target. MYADDR points at
REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
-/* Registers we shouldn't try to store. */
-#if !defined (CANNOT_STORE_REGISTER)
-#define CANNOT_STORE_REGISTER(regnum) 0
-#endif
-
static void
legacy_write_register_gen (int regnum, char *myaddr)
{
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
}
-/* 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.
write_register_pid (PC_REGNUM, pc, ptid);
if (NPC_REGNUM >= 0)
write_register_pid (NPC_REGNUM, pc + 4, ptid);
- if (NNPC_REGNUM >= 0)
- write_register_pid (NNPC_REGNUM, pc + 8, ptid);
#else
internal_error (__FILE__, __LINE__,
"generic_target_write_pc");
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)
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);
}
void
_initialize_regcache (void)
{
- build_regcache ();
-
register_gdbarch_swap (®isters, sizeof (registers), NULL);
register_gdbarch_swap (®ister_valid, sizeof (register_valid), NULL);
register_gdbarch_swap (NULL, 0, build_regcache);