readmem.c 1.05 KB
#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() {
}