diff lcdtest/memops.c @ 28:de3d3cfcbb35

lcdtest: lcdphone program put together, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 May 2018 22:26:58 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/memops.c	Sun May 27 22:26:58 2018 +0000
@@ -0,0 +1,148 @@
+/*
+ * Functions for ETM memory read requests
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <rvinterf/etm.h>
+#include <rvinterf/limits.h>
+#include <rvinterf/localtypes.h>
+#include "exitcodes.h"
+
+#ifndef	MAX_MEMREAD_BYTES
+#define	MAX_MEMREAD_BYTES	238
+#endif
+
+#ifndef	MAX_MEMREAD_16BIT
+#define	MAX_MEMREAD_16BIT	119
+#endif
+
+#ifndef	MAX_MEMREAD_32BIT
+#define	MAX_MEMREAD_32BIT	59
+#endif
+
+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);
+}
+
+do_memory_read_16(memaddr, databuf, nwords)
+	u32 memaddr;
+	u_char *databuf;
+{
+	u_char cmdpkt[10];
+	int rc;
+
+	if (nwords > MAX_MEMREAD_16BIT) {
+		printf("error: # of 16-bit words to read may not exceed %d\n",
+			MAX_MEMREAD_16BIT);
+		return(ERROR_USAGE);
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x02;
+	cmdpkt[4] = nwords;
+	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 16 request: 0x%02X\n",
+			rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len != nwords * 2 + 7) {
+		printf("error: mem read 16 response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x02) {
+		printf("error: mem read 16 response has wrong opcode\n");
+		return(ERROR_TARGET);
+	}
+	bcopy(rvi_msg + 6, databuf, nwords * 2);
+	return(0);
+}
+
+do_memory_read_32(memaddr, databuf, nwords)
+	u32 memaddr;
+	u_char *databuf;
+{
+	u_char cmdpkt[10];
+	int rc;
+
+	if (nwords > MAX_MEMREAD_32BIT) {
+		printf("error: # of 32-bit words to read may not exceed %d\n",
+			MAX_MEMREAD_32BIT);
+		return(ERROR_USAGE);
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x04;
+	cmdpkt[4] = nwords;
+	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 32 request: 0x%02X\n",
+			rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len != nwords * 4 + 7) {
+		printf("error: mem read 32 response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[4] != TMCORE_OPC_MEM || rvi_msg[5] != 0x04 && rvi_msg[5]) {
+		printf("error: mem read 32 response has wrong opcode\n");
+		return(ERROR_TARGET);
+	}
+	bcopy(rvi_msg + 6, databuf, nwords * 4);
+	return(0);
+}