changeset 979:ebdf5afa9fb5

fc-tmsh: omr responses parsed and formatted in a readable manner
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Thu, 10 Dec 2015 04:28:19 +0000
parents 1ee80bcb0fd0
children a0879ce32d2c
files rvinterf/tmsh/etmbasic.c rvinterf/tmsh/omr.c
diffstat 2 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/tmsh/etmbasic.c	Thu Dec 10 04:05:55 2015 +0000
+++ b/rvinterf/tmsh/etmbasic.c	Thu Dec 10 04:28:19 2015 +0000
@@ -10,6 +10,7 @@
 #include "pktmux.h"
 #include "limits.h"
 #include "etm.h"
+#include "tm3.h"
 
 extern u_char rvi_msg[];
 extern int rvi_msg_len;
@@ -36,7 +37,7 @@
 	int i, c;
 
 	if (rvi_msg_len < 4) {
-runt:		print_etm_pkt_raw("ETM Runt");
+runt:		print_etm_pkt_raw("TM runt");
 		return;
 	}
 	c = 0;
@@ -60,8 +61,14 @@
 			goto runt;
 		handle_ffs2_response();
 		return;
+	/* TM3 */
+	case MEM_READ:
+		if (rvi_msg_len < 5)
+			goto runt;
+		handle_omr_response();
+		return;
 	default:
-		print_etm_pkt_raw("ETM Unknown");
+		print_etm_pkt_raw("TM unknown");
 	}
 }
 
--- a/rvinterf/tmsh/omr.c	Thu Dec 10 04:05:55 2015 +0000
+++ b/rvinterf/tmsh/omr.c	Thu Dec 10 04:28:19 2015 +0000
@@ -15,6 +15,59 @@
 extern u_char rvi_msg[];
 extern int rvi_msg_len;
 
+static void
+memdump_line(off, inbuf, len)
+	u_char *inbuf;
+{
+	char outbuf[80], *dp;
+	int i, c;
+
+	sprintf(outbuf, "omr %02X:  ", off);
+	dp = index(outbuf, '\0');
+	for (i = 0; i < 16; i++) {
+		if (i < len)
+			sprintf(dp, "%02X ", inbuf[i]);
+		else
+			strcpy(dp, "   ");
+		dp += 3;
+		if (i == 7 || i == 15)
+			*dp++ = ' ';
+	}
+	for (i = 0; i < len; i++) {
+		c = inbuf[i];
+		if (c < ' ' || c > '~')
+			c = '.';
+		*dp++ = c;
+	}
+	*dp = '\0';
+	async_msg_output(outbuf);
+}
+
+void
+handle_omr_response()
+{
+	int off, len;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("TM3 memread error");
+		return;
+	}
+	if (rvi_msg_len < 10) {
+bad:		print_etm_pkt_raw("omr bad resp");
+		return;
+	}
+	if (rvi_msg[5] || rvi_msg[6] || rvi_msg[7])
+		goto bad;
+	if (rvi_msg_len != rvi_msg[4] + 9)
+		goto bad;
+	for (off = 0; off < rvi_msg[4]; off += len) {
+		len = rvi_msg[4] - off;
+		if (len > 16)
+			len = 16;
+		memdump_line(off, rvi_msg + 8 + off, len);
+	}
+}
+
 void
 cmd_omr(argc, argv)
 	char **argv;