diff target-utils/libcommon/cmd_memdump_machine.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children 9214118ae941
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libcommon/cmd_memdump_machine.c	Sat Jun 11 00:13:35 2016 +0000
@@ -0,0 +1,50 @@
+/*
+ * This is a machine-oriented memory dump command.  The output is in the
+ * form of S3 records.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+void
+cmd_memdump_machine(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long addr;
+	u_char srbuf[0x86], cksum;
+	int i;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 8, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	if (start & 0x7F || length & 0x7F) {
+	   printf("ERROR: implementation limit: 128-byte alignment required\n");
+		return;
+	}
+	srbuf[0] = 0x85;
+	for (addr = start; addr < start + length; addr += 0x80) {
+		srbuf[1] = addr >> 24;
+		srbuf[2] = addr >> 16;
+		srbuf[3] = addr >> 8;
+		srbuf[4] = addr;
+		bcopy(addr, srbuf + 5, 0x80);
+		cksum = 0;
+		for (i = 0; i < 0x85; i++)
+			cksum += srbuf[i];
+		srbuf[i] = ~cksum;
+		putchar('S');
+		putchar('3');
+		for (i = 0; i < 0x86; i++)
+			printf("%02X", srbuf[i]);
+		putchar('\n');
+	}
+}