comparison rvinterf/tmsh/omr.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 2159f260ed13
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * Old-style memory read command
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdlib.h>
10 #include "pktmux.h"
11 #include "limits.h"
12 #include "localtypes.h"
13 #include "tm3.h"
14
15 extern u_char rvi_msg[];
16 extern int rvi_msg_len;
17
18 static void
19 memdump_line(off, inbuf, len)
20 u_char *inbuf;
21 {
22 char outbuf[80], *dp;
23 int i, c;
24
25 sprintf(outbuf, "omr %02X: ", off);
26 dp = index(outbuf, '\0');
27 for (i = 0; i < 16; i++) {
28 if (i < len)
29 sprintf(dp, "%02X ", inbuf[i]);
30 else
31 strcpy(dp, " ");
32 dp += 3;
33 if (i == 7 || i == 15)
34 *dp++ = ' ';
35 }
36 for (i = 0; i < len; i++) {
37 c = inbuf[i];
38 if (c < ' ' || c > '~')
39 c = '.';
40 *dp++ = c;
41 }
42 *dp = '\0';
43 async_msg_output(outbuf);
44 }
45
46 void
47 handle_omr_response()
48 {
49 int off, len;
50
51 if (rvi_msg[3]) {
52 print_etm_pkt_raw("TM3 memread error");
53 return;
54 }
55 if (rvi_msg_len < 10) {
56 bad: print_etm_pkt_raw("omr bad resp");
57 return;
58 }
59 if (rvi_msg[5] || rvi_msg[6] || rvi_msg[7])
60 goto bad;
61 if (rvi_msg_len != rvi_msg[4] + 9)
62 goto bad;
63 for (off = 0; off < rvi_msg[4]; off += len) {
64 len = rvi_msg[4] - off;
65 if (len > 16)
66 len = 16;
67 memdump_line(off, rvi_msg + 8 + off, len);
68 }
69 }
70
71 void
72 cmd_omr(argc, argv)
73 char **argv;
74 {
75 u32 addr, size;
76 u_char cmdpkt[11];
77
78 addr = strtoul(argv[1], 0, 16);
79 size = strtoul(argv[2], 0, 16);
80 if (size < 1 || size > TM3_MEMREAD_MAX) {
81 printf("error: count argument outside valid range\n");
82 return;
83 }
84 cmdpkt[1] = MEM_READ;
85 cmdpkt[2] = addr;
86 cmdpkt[3] = addr >> 8;
87 cmdpkt[4] = addr >> 16;
88 cmdpkt[5] = addr >> 24;
89 cmdpkt[6] = size;
90 cmdpkt[7] = 0;
91 cmdpkt[8] = 0;
92 cmdpkt[9] = 0;
93 send_etm_cmd(cmdpkt, 9);
94 }