FreeCalypso > hg > freecalypso-sw
changeset 911:42719fa3e6af
etmsync: memory read implemented
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 08 Sep 2015 07:52:29 +0000 |
parents | d1333db6385f |
children | f50c71442d50 |
files | rvinterf/etmsync/Makefile rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/memcmd.c rvinterf/etmsync/memops.c rvinterf/include/etm.h |
diffstat | 5 files changed, 120 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile Tue Sep 08 06:34:02 2015 +0000 +++ b/rvinterf/etmsync/Makefile Tue Sep 08 07:52:29 2015 +0000 @@ -5,7 +5,7 @@ FSIO_OBJS= connect.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \ fserr.o fsiomain.o fsmisc.o fspath.o fsread.o fsupload.o \ - fswrite.o interf.o launchrvif.o symlink.o + fswrite.o interf.o launchrvif.o memcmd.o memops.o symlink.o all: ${PROGS}
--- a/rvinterf/etmsync/fscmdtab.c Tue Sep 08 06:34:02 2015 +0000 +++ b/rvinterf/etmsync/fscmdtab.c Tue Sep 08 07:52:29 2015 +0000 @@ -16,6 +16,7 @@ extern int cmd_hd(); extern int cmd_ll(); extern int cmd_ls(); +extern int cmd_memdump(); extern int cmd_mkdir(); extern int cmd_preformat(); extern int cmd_readlink(); @@ -40,6 +41,7 @@ {"hd", 1, 1, cmd_hd}, {"ll", 1, 1, cmd_ll}, {"ls", 1, 1, cmd_ls}, + {"memdump", 2, 2, cmd_memdump}, {"mkdir", 1, 1, cmd_mkdir}, {"preformat", 0, 0, cmd_preformat}, {"readlink", 1, 1, cmd_readlink},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/memcmd.c Tue Sep 08 07:52:29 2015 +0000 @@ -0,0 +1,59 @@ +/* + * User commands for reading memory regions and Calypso die ID via ETM + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "etm.h" +#include "limits.h" +#include "localtypes.h" +#include "exitcodes.h" + +void +memdump_line(addr, buf, len) + u32 addr; + u_char *buf; +{ + int i, c; + + printf("%08X: ", addr); + for (i = 0; i < 16; i++) { + if (i < len) + printf("%02X ", buf[i]); + else + fputs(" ", stdout); + if (i == 7 || i == 15) + putchar(' '); + } + for (i = 0; i < len; i++) { + c = buf[i]; + if (c < ' ' || c > '~') + c = '.'; + putchar(c); + } + putchar('\n'); +} + +cmd_memdump(argc, argv) + char **argv; +{ + u_char databuf[MAX_MEMREAD_BYTES]; + u32 memaddr; + int rc, sz, off, l; + + memaddr = strtoul(argv[1], 0, 16); + sz = strtoul(argv[2], 0, 16); + rc = do_memory_read(memaddr, databuf, sz); + if (rc) + return(rc); + for (off = 0; off < sz; off += 16) { + l = sz - off; + if (l > 16) + l = 16; + memdump_line(memaddr + off, databuf + off, l); + } + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/memops.c Tue Sep 08 07:52:29 2015 +0000 @@ -0,0 +1,56 @@ +/* + * Functions for reading memory regions and Calypso die ID via ETM + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "etm.h" +#include "limits.h" +#include "localtypes.h" +#include "exitcodes.h" + +extern u_char rvi_msg[]; +extern int rvi_msg_len; + +do_memory_read(memaddr, databuf, nbytes) + u32 memaddr; + u_char *databuf; +{ + u_char cmdpkt[10]; + int rc; + + if (nbytes > MAX_MEMREAD_BYTES) { + printf("error: # of bytes to read may not exceed %d\n", + MAX_MEMREAD_BYTES); + return(ERROR_USAGE); + } + cmdpkt[1] = ETM_CORE; + cmdpkt[2] = TMCORE_OPC_MEM; + cmdpkt[3] = 0x01; + cmdpkt[4] = nbytes; + cmdpkt[5] = memaddr; + cmdpkt[6] = memaddr >> 8; + cmdpkt[7] = memaddr >> 16; + cmdpkt[8] = memaddr >> 24; + rc = etm_pkt_exch(cmdpkt, 8); + if (rc) + return(rc); + if (rvi_msg[3]) { + printf("ETM error response to mem read request: 0x%02X\n", + rvi_msg[3]); + return(ERROR_TARGET); + } + if (rvi_msg_len != nbytes + 7) { + printf("error: mem read response has wrong length\n"); + return(ERROR_TARGET); + } + if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x01) { + printf("error: mem read response has wrong opcode\n"); + return(ERROR_TARGET); + } + bcopy(rvi_msg + 6, databuf, nbytes); + return(0); +}