comparison lcdpoll/memops.c @ 3:06e900c54ae3

fc-lcdpoll program put together, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Mar 2018 23:04:44 +0000
parents
children
comparison
equal deleted inserted replaced
2:bff57443b0f7 3:06e900c54ae3
1 /*
2 * Functions for ETM memory read requests
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <rvinterf/etm.h>
11 #include <rvinterf/limits.h>
12 #include <rvinterf/localtypes.h>
13 #include <rvinterf/exitcodes.h>
14
15 #ifndef MAX_MEMREAD_BYTES
16 #define MAX_MEMREAD_BYTES 238
17 #endif
18
19 #ifndef MAX_MEMREAD_16BIT
20 #define MAX_MEMREAD_16BIT 119
21 #endif
22
23 #ifndef MAX_MEMREAD_32BIT
24 #define MAX_MEMREAD_32BIT 59
25 #endif
26
27 extern u_char rvi_msg[];
28 extern int rvi_msg_len;
29
30 do_memory_read(memaddr, databuf, nbytes)
31 u32 memaddr;
32 u_char *databuf;
33 {
34 u_char cmdpkt[10];
35 int rc;
36
37 if (nbytes > MAX_MEMREAD_BYTES) {
38 printf("error: # of bytes to read may not exceed %d\n",
39 MAX_MEMREAD_BYTES);
40 return(ERROR_USAGE);
41 }
42 cmdpkt[1] = ETM_CORE;
43 cmdpkt[2] = TMCORE_OPC_MEM;
44 cmdpkt[3] = 0x01;
45 cmdpkt[4] = nbytes;
46 cmdpkt[5] = memaddr;
47 cmdpkt[6] = memaddr >> 8;
48 cmdpkt[7] = memaddr >> 16;
49 cmdpkt[8] = memaddr >> 24;
50 rc = etm_pkt_exch(cmdpkt, 8);
51 if (rc)
52 return(rc);
53 if (rvi_msg[3]) {
54 printf("ETM error response to mem read request: 0x%02X\n",
55 rvi_msg[3]);
56 return(ERROR_TARGET);
57 }
58 if (rvi_msg_len != nbytes + 7) {
59 printf("error: mem read response has wrong length\n");
60 return(ERROR_TARGET);
61 }
62 if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x01) {
63 printf("error: mem read response has wrong opcode\n");
64 return(ERROR_TARGET);
65 }
66 bcopy(rvi_msg + 6, databuf, nbytes);
67 return(0);
68 }
69
70 do_memory_read_16(memaddr, databuf, nwords)
71 u32 memaddr;
72 u_char *databuf;
73 {
74 u_char cmdpkt[10];
75 int rc;
76
77 if (nwords > MAX_MEMREAD_16BIT) {
78 printf("error: # of 16-bit words to read may not exceed %d\n",
79 MAX_MEMREAD_16BIT);
80 return(ERROR_USAGE);
81 }
82 cmdpkt[1] = ETM_CORE;
83 cmdpkt[2] = TMCORE_OPC_MEM;
84 cmdpkt[3] = 0x02;
85 cmdpkt[4] = nwords;
86 cmdpkt[5] = memaddr;
87 cmdpkt[6] = memaddr >> 8;
88 cmdpkt[7] = memaddr >> 16;
89 cmdpkt[8] = memaddr >> 24;
90 rc = etm_pkt_exch(cmdpkt, 8);
91 if (rc)
92 return(rc);
93 if (rvi_msg[3]) {
94 printf("ETM error response to mem read 16 request: 0x%02X\n",
95 rvi_msg[3]);
96 return(ERROR_TARGET);
97 }
98 if (rvi_msg_len != nwords * 2 + 7) {
99 printf("error: mem read 16 response has wrong length\n");
100 return(ERROR_TARGET);
101 }
102 if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x02) {
103 printf("error: mem read 16 response has wrong opcode\n");
104 return(ERROR_TARGET);
105 }
106 bcopy(rvi_msg + 6, databuf, nwords * 2);
107 return(0);
108 }
109
110 do_memory_read_32(memaddr, databuf, nwords)
111 u32 memaddr;
112 u_char *databuf;
113 {
114 u_char cmdpkt[10];
115 int rc;
116
117 if (nwords > MAX_MEMREAD_32BIT) {
118 printf("error: # of 32-bit words to read may not exceed %d\n",
119 MAX_MEMREAD_32BIT);
120 return(ERROR_USAGE);
121 }
122 cmdpkt[1] = ETM_CORE;
123 cmdpkt[2] = TMCORE_OPC_MEM;
124 cmdpkt[3] = 0x04;
125 cmdpkt[4] = nwords;
126 cmdpkt[5] = memaddr;
127 cmdpkt[6] = memaddr >> 8;
128 cmdpkt[7] = memaddr >> 16;
129 cmdpkt[8] = memaddr >> 24;
130 rc = etm_pkt_exch(cmdpkt, 8);
131 if (rc)
132 return(rc);
133 if (rvi_msg[3]) {
134 printf("ETM error response to mem read 32 request: 0x%02X\n",
135 rvi_msg[3]);
136 return(ERROR_TARGET);
137 }
138 if (rvi_msg_len != nwords * 4 + 7) {
139 printf("error: mem read 32 response has wrong length\n");
140 return(ERROR_TARGET);
141 }
142 if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x04 && rvi_msg[5]) {
143 printf("error: mem read 32 response has wrong opcode\n");
144 return(ERROR_TARGET);
145 }
146 bcopy(rvi_msg + 6, databuf, nwords * 4);
147 return(0);
148 }