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