annotate rvinterf/etmsync/memops.c @ 911:42719fa3e6af

etmsync: memory read implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Tue, 08 Sep 2015 07:52:29 +0000
parents
children f50c71442d50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
911
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * Functions for reading memory regions and Calypso die ID via ETM
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 */
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "etm.h"
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "limits.h"
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "localtypes.h"
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "exitcodes.h"
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 extern u_char rvi_msg[];
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 extern int rvi_msg_len;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 do_memory_read(memaddr, databuf, nbytes)
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 u32 memaddr;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 u_char *databuf;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 {
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 u_char cmdpkt[10];
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 int rc;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 if (nbytes > MAX_MEMREAD_BYTES) {
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 printf("error: # of bytes to read may not exceed %d\n",
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 MAX_MEMREAD_BYTES);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 return(ERROR_USAGE);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 }
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 cmdpkt[1] = ETM_CORE;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 cmdpkt[2] = TMCORE_OPC_MEM;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 cmdpkt[3] = 0x01;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 cmdpkt[4] = nbytes;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 cmdpkt[5] = memaddr;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 cmdpkt[6] = memaddr >> 8;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 cmdpkt[7] = memaddr >> 16;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 cmdpkt[8] = memaddr >> 24;
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 rc = etm_pkt_exch(cmdpkt, 8);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 if (rc)
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 return(rc);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 if (rvi_msg[3]) {
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 printf("ETM error response to mem read request: 0x%02X\n",
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 rvi_msg[3]);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 return(ERROR_TARGET);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 }
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 if (rvi_msg_len != nbytes + 7) {
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 printf("error: mem read response has wrong length\n");
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 return(ERROR_TARGET);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 }
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x01) {
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 printf("error: mem read response has wrong opcode\n");
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 return(ERROR_TARGET);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 }
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 bcopy(rvi_msg + 6, databuf, nbytes);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 return(0);
42719fa3e6af etmsync: memory read implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 }