+
+static int
+monitor_write_even_block (CORE_ADDR memaddr, char *myaddr, int len)
+{
+ unsigned int val;
+ int written = 0;;
+ /* Enter the sub mode */
+ monitor_printf (current_monitor->setmem.cmdl, memaddr);
+ monitor_expect_prompt (NULL, 0);
+
+ while (len)
+ {
+ val = extract_unsigned_integer (myaddr, 4); /* REALLY */
+ monitor_printf ("%x\r", val);
+ myaddr += 4;
+ memaddr += 4;
+ written += 4;
+ monitor_debug (" @ %s\n", paddr (memaddr));
+ /* If we wanted to, here we could validate the address */
+ monitor_expect_prompt (NULL, 0);
+ }
+ /* Now exit the sub mode */
+ monitor_printf (current_monitor->getreg.term_cmd);
+ monitor_expect_prompt (NULL, 0);
+ return written;
+}
+
+
+static int
+monitor_write_memory_bytes (CORE_ADDR memaddr, char *myaddr, int len)
+{
+ unsigned char val;
+ int written = 0;
+ if (len == 0)
+ return 0;
+ /* Enter the sub mode */
+ monitor_printf (current_monitor->setmem.cmdb, memaddr);
+ monitor_expect_prompt (NULL, 0);
+ while (len)
+ {
+ val = *myaddr;
+ monitor_printf ("%x\r", val);
+ myaddr++;
+ memaddr++;
+ written++;
+ /* If we wanted to, here we could validate the address */
+ monitor_expect_prompt (NULL, 0);
+ len--;
+ }
+ /* Now exit the sub mode */
+ monitor_printf (current_monitor->getreg.term_cmd);
+ monitor_expect_prompt (NULL, 0);
+ return written;
+}
+
+
+static void
+longlongendswap (unsigned char *a)
+{
+ int i, j;
+ unsigned char x;
+ i = 0;
+ j = 7;
+ while (i < 4)
+ {
+ x = *(a + i);
+ *(a + i) = *(a + j);
+ *(a + j) = x;
+ i++, j--;
+ }
+}
+/* Format 32 chars of long long value, advance the pointer */
+static char *hexlate = "0123456789abcdef";
+static char *
+longlong_hexchars (unsigned long long value,
+ char *outbuff)
+{
+ if (value == 0)
+ {
+ *outbuff++ = '0';
+ return outbuff;
+ }
+ else
+ {
+ static unsigned char disbuf[8]; /* disassembly buffer */
+ unsigned char *scan, *limit; /* loop controls */
+ unsigned char c, nib;
+ int leadzero = 1;
+ scan = disbuf;
+ limit = scan + 8;
+ {
+ unsigned long long *dp;
+ dp = (unsigned long long *) scan;
+ *dp = value;
+ }
+ longlongendswap (disbuf); /* FIXME: ONly on big endian hosts */
+ while (scan < limit)
+ {
+ c = *scan++; /* a byte of our long long value */
+ if (leadzero)
+ {
+ if (c == 0)
+ continue;
+ else
+ leadzero = 0; /* henceforth we print even zeroes */
+ }
+ nib = c >> 4; /* high nibble bits */
+ *outbuff++ = hexlate[nib];
+ nib = c & 0x0f; /* low nibble bits */
+ *outbuff++ = hexlate[nib];
+ }
+ return outbuff;
+ }
+} /* longlong_hexchars */
+
+
+
+/* I am only going to call this when writing virtual byte streams.
+ Which possably entails endian conversions
+ */
+static int
+monitor_write_memory_longlongs (CORE_ADDR memaddr, char *myaddr, int len)
+{
+ static char hexstage[20]; /* At least 16 digits required, plus null */
+ char *endstring;
+ long long *llptr;
+ long long value;
+ int written = 0;
+ llptr = (unsigned long long *) myaddr;
+ if (len == 0)
+ return 0;
+ monitor_printf (current_monitor->setmem.cmdll, memaddr);
+ monitor_expect_prompt (NULL, 0);
+ while (len >= 8)
+ {
+ value = *llptr;
+ endstring = longlong_hexchars (*llptr, hexstage);
+ *endstring = '\0'; /* NUll terminate for printf */
+ monitor_printf ("%s\r", hexstage);
+ llptr++;
+ memaddr += 8;
+ written += 8;
+ /* If we wanted to, here we could validate the address */
+ monitor_expect_prompt (NULL, 0);
+ len -= 8;
+ }
+ /* Now exit the sub mode */
+ monitor_printf (current_monitor->getreg.term_cmd);
+ monitor_expect_prompt (NULL, 0);
+ return written;
+} /* */
+
+
+
+/* ----- MONITOR_WRITE_MEMORY_BLOCK ---------------------------- */
+/* This is for the large blocks of memory which may occur in downloading.
+ And for monitors which use interactive entry,
+ And for monitors which do not have other downloading methods.
+ Without this, we will end up calling monitor_write_memory many times
+ and do the entry and exit of the sub mode many times
+ This currently assumes...
+ MO_SETMEM_INTERACTIVE
+ ! MO_NO_ECHO_ON_SETMEM
+ To use this, the you have to patch the monitor_cmds block with
+ this function. Otherwise, its not tuned up for use by all
+ monitor variations.
+ */
+
+static int
+monitor_write_memory_block (CORE_ADDR memaddr, char *myaddr, int len)
+{
+ int written;
+ written = 0;
+ /* FIXME: This would be a good place to put the zero test */
+#if 1
+ if ((len > 8) && (((len & 0x07)) == 0) && current_monitor->setmem.cmdll)
+ {
+ return monitor_write_memory_longlongs (memaddr, myaddr, len);
+ }
+#endif
+#if 0
+ if (len > 4)
+ {
+ int sublen;
+ written = monitor_write_even_block (memaddr, myaddr, len);
+ /* Adjust calling parameters by written amount */
+ memaddr += written;
+ myaddr += written;
+ len -= written;
+ }
+#endif
+ written = monitor_write_memory_bytes (memaddr, myaddr, len);
+ return written;
+}
+