readmem.c
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <bstring.h>
#include <diag.h>
#include <dbg_comm.h>
extern dbg_comm_struct dbg_comm;
int commtype=DG_VERILOG;
void main(int argc, char **argv) {
unsigned int vaddr, len;
int i, j;
int ret_len;
char *buf;
if (argc == 3) {
vaddr = (int)strtoul (argv[1], (char **)NULL, 0);
len = (int)strtol (argv[2], (char **)NULL, 0);
} else {
printf("Usage: readmem vaddr len\n");
exit (1);
}
printf("vaddr 0x%x len %d\n", vaddr, len);
if ( dgInitComm() ) {
fprintf(stderr,
"%s: unable to initialize communication with target system.\n",
argv[0]);
exit(1);
}
buf = malloc(len);
if ( dgReadMem(vaddr, len, buf) ) {
fprintf(stderr,
"%s: unable to read memory from target system.\n",
argv[0]);
exit(1);
}
for (i = 0; i < len; ) {
printf("0x%08x ", vaddr + i);
for (j = 0; j < 16 && i < len; j++, i++)
printf("%02x ", buf[i]);
printf("\n");
}
}
void
errlog() {
}