+struct remote_state
+{
+ /* Description of the remote protocol registers. */
+ long sizeof_g_packet;
+
+ /* Description of the remote protocol registers indexed by REGNUM
+ (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */
+ struct packet_reg *regs;
+
+ /* This is the size (in chars) of the first response to the ``g''
+ packet. It is used as a heuristic when determining the maximum
+ size of memory-read and memory-write packets. A target will
+ typically only reserve a buffer large enough to hold the ``g''
+ packet. The size does not include packet overhead (headers and
+ trailers). */
+ long actual_register_packet_size;
+
+ /* This is the maximum size (in chars) of a non read/write packet.
+ It is also used as a cap on the size of read/write packets. */
+ long remote_packet_size;
+};
+
+
+/* Handle for retreving the remote protocol data from gdbarch. */
+static struct gdbarch_data *remote_gdbarch_data_handle;
+
+static struct remote_state *
+get_remote_state (void)
+{
+ return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
+}
+
+static void *
+init_remote_state (struct gdbarch *gdbarch)
+{
+ int regnum;
+ struct remote_state *rs = xmalloc (sizeof (struct remote_state));
+
+ /* Start out by having the remote protocol mimic the existing
+ behavour - just copy in the description of the register cache. */
+ rs->sizeof_g_packet = REGISTER_BYTES; /* OK use. */
+
+ /* Assume a 1:1 regnum<->pnum table. */
+ rs->regs = xcalloc (NUM_REGS + NUM_PSEUDO_REGS, sizeof (struct packet_reg));
+ for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
+ {
+ struct packet_reg *r = &rs->regs[regnum];
+ r->pnum = regnum;
+ r->regnum = regnum;
+ r->offset = REGISTER_BYTE (regnum);
+ r->in_g_packet = (regnum < NUM_REGS);
+ /* ...size = REGISTER_RAW_SIZE (regnum); */
+ /* ...name = REGISTER_NAME (regnum); */
+ }
+
+ /* Default maximum number of characters in a packet body. Many
+ remote stubs have a hardwired buffer size of 400 bytes
+ (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
+ as the maximum packet-size to ensure that the packet and an extra
+ NUL character can always fit in the buffer. This stops GDB
+ trashing stubs that try to squeeze an extra NUL into what is
+ already a full buffer (As of 1999-12-04 that was most stubs. */
+ rs->remote_packet_size = 400 - 1;
+
+ /* Should rs->sizeof_g_packet needs more space than the
+ default, adjust the size accordingly. Remember that each byte is
+ encoded as two characters. 32 is the overhead for the packet
+ header / footer. NOTE: cagney/1999-10-26: I suspect that 8
+ (``$NN:G...#NN'') is a better guess, the below has been padded a
+ little. */
+ if (rs->sizeof_g_packet > ((rs->remote_packet_size - 32) / 2))
+ rs->remote_packet_size = (rs->sizeof_g_packet * 2 + 32);
+
+ /* This one is filled in when a ``g'' packet is received. */
+ rs->actual_register_packet_size = 0;
+
+ return rs;
+}
+
+static void
+free_remote_state (struct gdbarch *gdbarch, void *pointer)
+{
+ struct remote_state *data = pointer;
+ xfree (data->regs);
+ xfree (data);
+}
+
+static struct packet_reg *
+packet_reg_from_regnum (struct remote_state *rs, long regnum)
+{
+ if (regnum < 0 && regnum >= NUM_REGS + NUM_PSEUDO_REGS)
+ return NULL;
+ else
+ {
+ struct packet_reg *r = &rs->regs[regnum];
+ gdb_assert (r->regnum == regnum);
+ return r;
+ }
+}
+
+static struct packet_reg *
+packet_reg_from_pnum (struct remote_state *rs, LONGEST pnum)
+{
+ int i;
+ for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
+ {
+ struct packet_reg *r = &rs->regs[i];
+ if (r->pnum == pnum)
+ return r;
+ }
+ return NULL;
+}
+
+/* FIXME: graces/2002-08-08: These variables should eventually be
+ bound to an instance of the target object (as in gdbarch-tdep()),
+ when such a thing exists. */
+
+/* This is set to the data address of the access causing the target
+ to stop for a watchpoint. */
+static CORE_ADDR remote_watch_data_address;
+
+/* This is non-zero if taregt stopped for a watchpoint. */
+static int remote_stopped_by_watchpoint_p;