@@ -17,10 +17,10 @@ VPATH=$(SRCDIR)
CFLAGS ?= -g
-ALL_CFLAGS = -Wall -D_GNU_SOURCE $(CFLAGS) $(EXTRA_CFLAGS)
+ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(CFLAGS) $(EXTRA_CFLAGS)
PROG=risu
-SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
+SRCS=risu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
HDRS=risu.h
BINS=test_$(ARCH).bin
new file mode 100644
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * Copyright (c) 2017 Linaro Limited
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Maydell (Linaro) - initial implementation
+ *****************************************************************************/
+
+#include <stdio.h>
+
+#include "risu.h"
+
+int send_register_info(int sock, void *uc)
+{
+ struct reginfo ri;
+ int op;
+ reginfo_init(&ri, uc);
+ op = get_risuop(&ri);
+
+ switch (op) {
+ case OP_COMPARE:
+ case OP_TESTEND:
+ default:
+ /* Do a simple register compare on (a) explicit request
+ * (b) end of test (c) a non-risuop UNDEF
+ */
+ return send_data_pkt(sock, &ri, sizeof(ri));
+ case OP_SETMEMBLOCK:
+ memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri);
+ break;
+ case OP_GETMEMBLOCK:
+ set_ucontext_paramreg(uc,
+ get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
+ break;
+ case OP_COMPAREMEM:
+ return send_data_pkt(sock, memblock, MEMBLOCKLEN);
+ break;
+ }
+ return 0;
+}
@@ -16,6 +16,15 @@
#include <stdint.h>
#include <ucontext.h>
+/* GCC computed include to pull in the correct risu_reginfo_*.h for
+ * the architecture.
+ */
+#define REGINFO_HEADER2(X) #X
+#define REGINFO_HEADER1(ARCHNAME) REGINFO_HEADER2(risu_reginfo_ ## ARCHNAME.h)
+#define REGINFO_HEADER(ARCH) REGINFO_HEADER1(ARCH)
+
+#include REGINFO_HEADER(ARCH)
+
/* Socket related routines */
int master_connect(int port);
int apprentice_connect(const char *hostname, int port);
@@ -40,7 +49,7 @@ extern int test_fp_exc;
struct reginfo;
-/* Interface provided by CPU-specific code: */
+/* Functions operating on reginfo */
/* Send the register information from the struct ucontext down the socket.
* Return the response code from the master.
@@ -48,6 +57,8 @@ struct reginfo;
*/
int send_register_info(int sock, void *uc);
+/* Interface provided by CPU-specific code: */
+
/* Read register info from the socket and compare it with that from the
* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
* NB: called from a signal handler.
@@ -53,35 +53,6 @@ int get_risuop(struct reginfo *ri)
return (key != risukey) ? -1 : op;
}
-int send_register_info(int sock, void *uc)
-{
- struct reginfo ri;
- int op;
- reginfo_init(&ri, uc);
- op = get_risuop(&ri);
-
- switch (op) {
- case OP_COMPARE:
- case OP_TESTEND:
- default:
- /* Do a simple register compare on (a) explicit request
- * (b) end of test (c) a non-risuop UNDEF
- */
- return send_data_pkt(sock, &ri, sizeof(ri));
- case OP_SETMEMBLOCK:
- memblock = (void *)get_reginfo_paramreg(&ri);
- break;
- case OP_GETMEMBLOCK:
- set_ucontext_paramreg(uc,
- get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
- break;
- case OP_COMPAREMEM:
- return send_data_pkt(sock, memblock, MEMBLOCKLEN);
- break;
- }
- return 0;
-}
-
/* Read register info from the socket and compare it with that from the
* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
* NB: called from a signal handler.
@@ -77,36 +77,6 @@ int get_risuop(struct reginfo *ri)
return (key != risukey) ? -1 : op;
}
-int send_register_info(int sock, void *uc)
-{
- struct reginfo ri;
- int op;
- reginfo_init(&ri, uc);
- op = get_risuop(&ri);
-
- switch (op)
- {
- case OP_COMPARE:
- case OP_TESTEND:
- default:
- /* Do a simple register compare on (a) explicit request
- * (b) end of test (c) a non-risuop UNDEF
- */
- return send_data_pkt(sock, &ri, sizeof(ri));
- case OP_SETMEMBLOCK:
- memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri);
- break;
- case OP_GETMEMBLOCK:
- set_ucontext_paramreg(uc,
- get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
- break;
- case OP_COMPAREMEM:
- return send_data_pkt(sock, memblock, MEMBLOCKLEN);
- break;
- }
- return 0;
-}
-
/* Read register info from the socket and compare it with that from the
* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
* NB: called from a signal handler.
@@ -45,33 +45,6 @@ int get_risuop(struct reginfo *ri)
return (key != risukey) ? -1 : op;
}
-int send_register_info(int sock, void *uc)
-{
- struct reginfo ri;
- int op;
-
- reginfo_init(&ri, uc);
- op = get_risuop(&ri);
-
- switch (op) {
- case OP_COMPARE:
- case OP_TESTEND:
- default:
- return send_data_pkt(sock, &ri, sizeof(ri));
- case OP_SETMEMBLOCK:
- memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri);
- break;
- case OP_GETMEMBLOCK:
- set_ucontext_paramreg(uc,
- get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
- break;
- case OP_COMPAREMEM:
- return send_data_pkt(sock, memblock, MEMBLOCKLEN);
- break;
- }
- return 0;
-}
-
/* Read register info from the socket and compare it with that from the
* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
* NB: called from a signal handler.
@@ -50,33 +50,6 @@ int get_risuop(struct reginfo *ri)
return (key != risukey) ? -1 : op;
}
-int send_register_info(int sock, void *uc)
-{
- struct reginfo ri;
- int op;
-
- reginfo_init(&ri, uc);
- op = get_risuop(&ri);
-
- switch (op) {
- case OP_COMPARE:
- case OP_TESTEND:
- default:
- return send_data_pkt(sock, &ri, sizeof(ri));
- case OP_SETMEMBLOCK:
- memblock = (void*)get_reginfo_paramreg(&ri);
- break;
- case OP_GETMEMBLOCK:
- set_ucontext_paramreg(uc,
- get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
- break;
- case OP_COMPAREMEM:
- return send_data_pkt(sock, memblock, MEMBLOCKLEN);
- break;
- }
- return 0;
-}
-
/* Read register info from the socket and compare it with that from the
* ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch.
* NB: called from a signal handler.
send_register_info() is now essentially the same code for all target CPUs, so move it into reginfo.c rather than having duplicated code. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- Makefile | 4 ++-- reginfo.c | 43 +++++++++++++++++++++++++++++++++++++++++++ risu.h | 13 ++++++++++++- risu_aarch64.c | 29 ----------------------------- risu_arm.c | 30 ------------------------------ risu_m68k.c | 27 --------------------------- risu_ppc64le.c | 27 --------------------------- 7 files changed, 57 insertions(+), 116 deletions(-) create mode 100644 reginfo.c