...and here's the prefetch version (fixed one little mistake...):
diff --git a/src/target/arm_semihosting.c b/src/target/arm_semihosting.c
index a247cc8..ef13f68 100644
--- a/src/target/arm_semihosting.c
+++ b/src/target/arm_semihosting.c
@@ -136,18 +136,26 @@ static int do_semihosting(struct target *target)
}
break;
- case 0x04: /* SYS_WRITE0 */
- do {
- unsigned char c;
- retval = target_read_memory(target, r1, 1, 1, &c);
- if (retval != ERROR_OK)
- return retval;
- if (!c)
- break;
- putchar(c);
- } while (1);
- result = 0;
- break;
+#define WRITE0_PREFETCH 16
+
+ case 0x04: /* SYS_WRITE0 */
+ do {
+ unsigned char c[WRITE0_PREFETCH];
+ int i;
+ retval = target_read_memory(target, r1, 1, WRITE0_PREFETCH, c);
+ if (retval != ERROR_OK)
+ return retval;
+ r1 += WRITE0_PREFETCH;
+ for (i=0; i < WRITE0_PREFETCH; i++) {
+ if (!c[i])
+ break;
+ putchar(c[i]);
+ }
+ if (i < WRITE0_PREFETCH)
+ break;
+ } while (1);
+ result = 0;
+ break;
case 0x05: /* SYS_WRITE */
retval = target_read_memory(target, r1, 4, 3, params);
On Mon, Mar 14, 2011 at 12:14 PM, John and Tina Peterson <[email protected]>wrote:
> In the latest git commit of openocd-0.5.0-dev, this is the code that
> handles the semihosting call SYS_WRITE0:
>
> case 0x04: /* SYS_WRITE0 */
> do {
> unsigned char c;
> retval = target_read_memory(target, r1, 1, 1, &c);
> if (retval != ERROR_OK)
> return retval;
> if (!c)
> break;
> putchar(c);
> } while (1);
> result = 0;
> break;
>
>
> Problem is, trying to print "Hello, world!\n" just prints endless H's,
> because r1 is never incremented.
>
> One way to fix it would be to add a "++" after "r1".
>
> Additionally, it would be much more efficient to amortize the USB/JTAG
> round trip times by grabbing more than one byte at a time. Something like
> this:
>
> #define WRITE0_PREFETCH 16
>
> case 0x04: /* SYS_WRITE0 */
> do {
> unsigned char c[WRITE0_PREFETCH];
> int i;
> retval = target_read_memory(target, r1, 1, WRITE0_PREFETCH,
> &c);
> if (retval != ERROR_OK)
> return retval;
> r1 += WRITE0_PREFETCH;
> for (i=0; i < WRITE0_PREFETCH; i++) {
> if (!c[i])
> break;
> putchar(c[i]);
> }
> if (i < WRITE0_PREFETCH)
> break;
> } while (1);
> result = 0;
> break;
>
> ...with the caveat that this would error out if the end of the string is
> within 16 bytes of the end of memory. Probably a reasonable risk or some
> code could detect that.
>
> John K Peterson
>
>
>
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development