comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This is a machine-oriented memory dump command. The output is in the
3 * form of S3 records.
4 */
5
6 #include <sys/types.h>
7 #include "types.h"
8
9 void
10 cmd_memdump_machine(argbulk)
11 char *argbulk;
12 {
13 char *argv[3];
14 u_long start, length;
15 u_long addr;
16 u_char srbuf[0x86], cksum;
17 int i;
18
19 if (parse_args(argbulk, 2, 2, argv, 0) < 0)
20 return;
21 if (parse_hexarg(argv[0], 8, &start) < 0) {
22 printf("ERROR: arg1 must be a valid 32-bit hex address\n");
23 return;
24 }
25 if (parse_hexarg(argv[1], 8, &length) < 0) {
26 printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
27 return;
28 }
29 if (start & 0x7F || length & 0x7F) {
30 printf("ERROR: implementation limit: 128-byte alignment required\n");
31 return;
32 }
33 srbuf[0] = 0x85;
34 for (addr = start; addr < start + length; addr += 0x80) {
35 srbuf[1] = addr >> 24;
36 srbuf[2] = addr >> 16;
37 srbuf[3] = addr >> 8;
38 srbuf[4] = addr;
39 bcopy(addr, srbuf + 5, 0x80);
40 cksum = 0;
41 for (i = 0; i < 0x85; i++)
42 cksum += srbuf[i];
43 srbuf[i] = ~cksum;
44 putchar('S');
45 putchar('3');
46 for (i = 0; i < 0x86; i++)
47 printf("%02X", srbuf[i]);
48 putchar('\n');
49 }
50 }