From: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH Risu v2 6/9] Implement initial support for PPC64
Date: Sun, 6 Nov 2016 15:15:25 -0200 [thread overview]
Message-ID: <1478452528-13684-7-git-send-email-joserz@linux.vnet.ibm.com> (raw)
In-Reply-To: <1478452528-13684-1-git-send-email-joserz@linux.vnet.ibm.com>
This implementation drives both client and server sides with PPC64
specific code. It basically reads instructions from both sides and
compare them.
Signed-off-by: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
---
risu_ppc64le.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 158 insertions(+)
create mode 100644 risu_ppc64le.c
diff --git a/risu_ppc64le.c b/risu_ppc64le.c
new file mode 100644
index 0000000..9c1fafd
--- /dev/null
+++ b/risu_ppc64le.c
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * Copyright (c) IBM Corp, 2016
+ * 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:
+ * Jose Ricardo Ziviani - initial implementation
+ * based on Claudio Fontana's risu_aarch64.c
+ * based on Peter Maydell's risu_arm.c
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <ucontext.h>
+#include <string.h>
+
+#include "risu.h"
+#include "risu_reginfo_ppc64le.h"
+
+struct reginfo master_ri, apprentice_ri;
+static int mem_used = 0;
+static int packet_mismatch = 0;
+
+uint8_t apprentice_memblock[MEMBLOCKLEN];
+
+void advance_pc(void *vuc)
+{
+ ucontext_t *uc = (ucontext_t*)vuc;
+ uc->uc_mcontext.regs->nip += 4;
+}
+
+void set_x0(void *vuc, uint64_t x0)
+{
+ ucontext_t *uc = vuc;
+ uc->uc_mcontext.gp_regs[0] = x0;
+}
+
+static int get_risuop(uint32_t insn)
+{
+ uint32_t op = insn & 0xf;
+ uint32_t key = insn & ~0xf;
+ uint32_t risukey = 0x00005af0;
+ 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.faulting_insn);
+
+ switch (op) {
+ case OP_COMPARE:
+ case OP_TESTEND:
+ default:
+ return send_data_pkt(sock, &ri, sizeof(ri));
+ case OP_SETMEMBLOCK:
+ memblock = (void*)ri.gregs[0];
+ break;
+ case OP_GETMEMBLOCK:
+ set_x0(uc, ri.gregs[0] + (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.
+ */
+int recv_and_compare_register_info(int sock, void *uc)
+{
+ int resp = 0;
+ int op;
+
+ reginfo_init(&master_ri, uc);
+ op = get_risuop(master_ri.faulting_insn);
+
+ switch (op) {
+ case OP_COMPARE:
+ case OP_TESTEND:
+ default:
+ if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) {
+ packet_mismatch = 1;
+ resp = 2;
+ } else if (!reginfo_is_eq(&master_ri, &apprentice_ri, uc)) {
+ resp = 2;
+ }
+ else if (op == OP_TESTEND) {
+ resp = 1;
+ }
+ send_response_byte(sock, resp);
+ break;
+ case OP_SETMEMBLOCK:
+ memblock = (void*)master_ri.gregs[0];
+ break;
+ case OP_GETMEMBLOCK:
+ set_x0(uc, master_ri.gregs[0] + (uintptr_t)memblock);
+ break;
+ case OP_COMPAREMEM:
+ mem_used = 1;
+ if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) {
+ packet_mismatch = 1;
+ resp = 2;
+ } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
+ resp = 2;
+ }
+ send_response_byte(sock, resp);
+ break;
+ }
+ return resp;
+}
+
+/* Print a useful report on the status of the last comparison
+ * done in recv_and_compare_register_info(). This is called on
+ * exit, so need not restrict itself to signal-safe functions.
+ * Should return 0 if it was a good match (ie end of test)
+ * and 1 for a mismatch.
+ */
+int report_match_status(void)
+{
+ int resp = 0;
+ fprintf(stderr, "match status...\n");
+
+ if (packet_mismatch) {
+ fprintf(stderr, "packet mismatch (probably disagreement "
+ "about UNDEF on load/store)\n");
+ fprintf(stderr, "master reginfo:\n");
+ reginfo_dump(&master_ri, 0);
+ }
+ if (!reginfo_is_eq(&master_ri, &apprentice_ri, NULL)) {
+ fprintf(stderr, "mismatch on regs!\n");
+ resp = 1;
+ }
+ if (mem_used && memcmp(memblock, &apprentice_memblock, MEMBLOCKLEN) != 0) {
+ fprintf(stderr, "mismatch on memory!\n");
+ resp = 1;
+ }
+ if (!resp) {
+ fprintf(stderr, "match!\n");
+ return 0;
+ }
+
+ fprintf(stderr, "master reginfo:\n");
+ reginfo_dump(&master_ri, 1);
+
+ fprintf(stderr, "apprentice reginfo:\n");
+ reginfo_dump(&apprentice_ri, 0);
+
+ reginfo_dump_mismatch(&master_ri, &apprentice_ri, stderr);
+ return resp;
+}
--
2.7.4
next prev parent reply other threads:[~2016-11-06 17:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-06 17:15 [Qemu-devel] [PATCH Risu v2 0/9] Risu support for PPC64LE Jose Ricardo Ziviani
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 1/9] Create risugen_arm.pm module for risugen Jose Ricardo Ziviani
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 2/9] Refactor risugen to remove ARM specific code Jose Ricardo Ziviani
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 3/9] Change mode directive of ARM risu files Jose Ricardo Ziviani
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 4/9] Implement lib to deal with PPC64 registers Jose Ricardo Ziviani
2017-02-15 18:50 ` Peter Maydell
2017-02-15 19:28 ` joserz
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 5/9] Implement basic test code for PPC64 Jose Ricardo Ziviani
2016-11-06 17:15 ` Jose Ricardo Ziviani [this message]
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 7/9] Add PPC64 in risu build system Jose Ricardo Ziviani
2017-02-18 22:41 ` Peter Maydell
2017-02-21 2:24 ` joserz
2017-02-21 9:59 ` Peter Maydell
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 8/9] Implement risugen module for PPC64 Jose Ricardo Ziviani
2016-11-06 17:15 ` [Qemu-devel] [PATCH Risu v2 9/9] Implement risufile with all PPC64 instructions Jose Ricardo Ziviani
2016-11-07 16:43 ` [Qemu-devel] [PATCH Risu v2 0/9] Risu support for PPC64LE Peter Maydell
2016-11-07 20:18 ` joserz
2016-11-07 20:44 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478452528-13684-7-git-send-email-joserz@linux.vnet.ibm.com \
--to=joserz@linux.vnet.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).