commit 03aad6688981becb1fcdf492f96df0ee9a70b52b
parent 377df4c3326727764f7401b94db4da8fd97deab1
Author: Brian Swetland <swetland@frotz.net>
Date:   Wed,  5 Aug 2015 14:23:47 -0700
debugger: add wconsole command
Use DebugMonitor exception to send console input to target.
Any debugger commandline starting with / becomes a remote console command.
Diffstat:
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/tools/debugger-commands.c b/tools/debugger-commands.c
@@ -815,6 +815,35 @@ int do_threads(int argc, param *argv) {
 	return 0;
 }
 
+int remote_msg(u32 cmd) {
+	unsigned timeout = 250;
+	u32 n = 0;
+	if (swdp_ahb_write(DCRDR, cmd)) return -1;
+	if (swdp_ahb_read(DEMCR, &n)) return -1;
+	if (swdp_ahb_write(DEMCR, n | DEMCR_MON_PEND)) return -1;
+	while (timeout > 0) {
+		if (swdp_ahb_read(DCRDR, &n)) return -1;
+		if (!(n & 0x80000000)) return 0;
+		timeout--;
+	}
+	return -1;
+}
+
+int do_wconsole(int argc, param *argv) {
+	if (argc != 1) return -1;
+	const char *line = argv[0].s;
+	while (*line) {
+		if (remote_msg(0x80000000 | *line)) goto oops;
+		line++;
+	}
+	if (remote_msg(0x80000000 | '\n')) goto oops;
+	return 0;
+oops:
+	xprintf(XCORE, "console write failed\n");
+	return -1;
+}
+
+
 struct debugger_command debugger_commands[] = {
 	{ "exit",	"", do_exit,		"" },
 	{ "attach",	"", do_attach,		"attach/reattach to sw-dp" },
@@ -847,6 +876,7 @@ struct debugger_command debugger_commands[] = {
 	{ "arch",	"", do_setarch,		"set architecture for flash agent" },
 	{ "threads",	"", do_threads,		"thread dump" },
 	{ "text",	"", do_text,		"dump text" },
+	{ "wconsole",	"", do_wconsole,	"write to remote console" },
 	{ "help",	"", do_help,		"help" },
 	{ 0, 0, 0, 0 },
 };
diff --git a/tools/debugger-core.c b/tools/debugger-core.c
@@ -449,6 +449,13 @@ int debugger_command(char *line) {
 	unsigned c, n = 0;
 	int r;
 
+	while (*line && (*line == ' ')) line++;
+
+	if (*line == '/') {
+		arg[0].s = line + 1;
+		return _debugger_exec("wconsole", 1, arg);
+	}
+
 	while ((c = *line)) {
 		if (c <= ' ') {
 			line++;