From patchwork Fri Jun 2 16:08:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 101287 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp478958qge; Fri, 2 Jun 2017 09:19:15 -0700 (PDT) X-Received: by 10.200.37.106 with SMTP id 39mr10052132qtn.92.1496420355736; Fri, 02 Jun 2017 09:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496420355; cv=none; d=google.com; s=arc-20160816; b=JKGkgdwr+wJoiy+u2FrfBubZ5kVJAVjv2Ejt3o7ENFisb1PJI5gWo3RYApJJdew4Nk tF5kZoMaLVBHJoTPubLLgSRcgg1RJjy0PAq/trJgPQvdanGB6L6sakuDuW7daUPtAidA eynIOU+fVFU/NFEuP2BwvW/4gveEJJhbtGipbqjJO48dRl7eIwLcJ0zfT/wp3LU+k+cx WBXaECS+K5qfxmzgWKYCau9KIvv3ezvTX9ej8hjjRiZrOZHGpru7i6Jed+84klb+GtsU fxonEKGLbPRUod+LnWFcjnaMowT8qzLKBY8Zt4EgtJyq62RezZ522Mt1+53dslMoMZxo wOug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Jhoagad3XQ0S+iSghR7fyRcD8gT8B2WNOo3E/mpvp+Q=; b=SjUYnu9BV68C+XTXLQ93/uQV3tyuI8NAQ7qklDXIBhu73gjctGYNSOCW3s7VD2CKeb 75DcD8qah6AM83HQ2v33K2wi6D5jSvG2ONPVnjdwTs5oYfk/jvtWtpJLbvHAe4QoYiBS c/BuiF4Jyi89I61OJaHx6gnwf81K4FN6xiVc/D5i8HVkJbPjN17+c4yZfnfItRi4AaR5 muNVNOcFnxLc2rWTRTOewD5QnT8teLOqqGPcpx9SO2X1UBFLIJsK11jllGf1JDZk5dWL dOp8JBzrXj71vdLCbDvKi8aA2f8Vey7E7JwBzEoFwVkh68+gLGOmV9liAVA8Nsc39odG yNSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b29si23811303qtb.70.2017.06.02.09.19.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 09:19:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGpI9-0007Vg-49 for patch@linaro.org; Fri, 02 Jun 2017 12:19:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGp7z-00060f-W5 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGp7y-00051o-Kd for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:43 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:35979) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGp7y-00050g-CC for qemu-devel@nongnu.org; Fri, 02 Jun 2017 12:08:42 -0400 Received: by mail-wr0-x22b.google.com with SMTP id v111so2774232wrc.3 for ; Fri, 02 Jun 2017 09:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jhoagad3XQ0S+iSghR7fyRcD8gT8B2WNOo3E/mpvp+Q=; b=ZDu788duBLYIs6Z+UsIufWcznYl267+GSR+KvzTi0K8NLbRAzOv/NrHIxglAaOjbLW LWvYPhKDMw2B7eVuzB5DRGYa8FXmFBUY3Yp580rD0t9GOSENCn6J30eoe5gOC3km7x4k u+ZlFqLdL0X6W787g72Y3SxqLkB24CoxmD7yU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jhoagad3XQ0S+iSghR7fyRcD8gT8B2WNOo3E/mpvp+Q=; b=aCPF80G+XfYhLR7Gne3cs2CuVUu+iDhYphsFSjYM+/jQOEcnjQgoZywBjBLzxIqm2k gTg1KNDuRNKOEAWHYf/BqHxBeBb5oi2xvwG0yfKBaZ8FCGWu68iMo0sYWOvUAVe4vb56 ubtXCtUW7Byh+REcbAD5LtTEkNnYkkUzsUdzAQInYwTFwRpAuAx8WjFcTT8zZcGftD/m mnX/RbR/Yres4UvYqpMEuqX1N0WqfY0T7CK6lE9crvplwydWRqfnIn5+u1kqfmCqB1ZR 1Xa+7z5vFUNUSpfK0K8mBZyWAFJ7B9baX9QEBHn95S7WkVdK7hSO0Cxu6HWrFVOUK0Ec oF2A== X-Gm-Message-State: AODbwcB7YkUhYVQXzbQyYf5hEwn9OeT/Dow9OlzSVZHduwdFxXq3WhMU PyHjZWh+jGrwAiF0 X-Received: by 10.223.139.81 with SMTP id v17mr6407420wra.70.1496419721430; Fri, 02 Jun 2017 09:08:41 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p76sm2640094wma.15.2017.06.02.09.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 09:08:37 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 9FA033E03B5; Fri, 2 Jun 2017 17:08:54 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 2 Jun 2017 17:08:44 +0100 Message-Id: <20170602160848.4913-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602160848.4913-1-alex.bennee@linaro.org> References: <20170602160848.4913-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22b Subject: [Qemu-devel] [RISU PATCH v4 06/10] risu: add header to trace stream X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" I've also added a header packet with pc/risu op in it so we can keep better track of how things are going. Signed-off-by: Alex Bennée --- v4 - split from previous patch --- reginfo.c | 103 +++++++++++++++++++++++++++++++++++++-------------------- risu.h | 9 +++++ risu_aarch64.c | 5 +++ risu_arm.c | 5 +++ risu_m68k.c | 5 +++ risu_ppc64.c | 5 +++ 6 files changed, 96 insertions(+), 36 deletions(-) -- 2.13.0 diff --git a/reginfo.c b/reginfo.c index 6498459..be7bcdb 100644 --- a/reginfo.c +++ b/reginfo.c @@ -24,10 +24,20 @@ static int packet_mismatch = 0; int send_register_info(write_fn write_fn, void *uc) { struct reginfo ri; + trace_header_t header; int op; + reginfo_init(&ri, uc); op = get_risuop(&ri); + /* Write a header with PC/op to keep in sync */ + header.pc = get_pc(&ri); + header.risu_op = op; + if (write_fn(&header, sizeof(header)) != 0) { + fprintf(stderr,"%s: failed header write\n", __func__); + return -1; + } + switch (op) { case OP_TESTEND: write_fn(&ri, sizeof(ri)); @@ -63,51 +73,72 @@ int send_register_info(write_fn write_fn, void *uc) int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc) { int resp = 0, op; + trace_header_t header; reginfo_init(&master_ri, uc); op = get_risuop(&master_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 - */ - if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) { - packet_mismatch = 1; - resp = 2; - } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { - /* register mismatch */ - resp = 2; - } else if (op == OP_TESTEND) { - resp = 1; - } - resp_fn(resp); - break; - case OP_SETMEMBLOCK: - memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri); - break; - case OP_GETMEMBLOCK: - set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) + - (uintptr_t)memblock); - break; - case OP_COMPAREMEM: - mem_used = 1; - if (read_fn(apprentice_memblock, MEMBLOCKLEN)) { - packet_mismatch = 1; - resp = 2; - } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) { - /* memory mismatch */ - resp = 2; - } - resp_fn(resp); - break; + if (read_fn(&header, sizeof(header)) != 0) { + fprintf(stderr,"%s: failed header read\n", __func__); + return -1; + } + + if (header.risu_op == op ) { + + /* send OK for the header */ + resp_fn(0); + + 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 + */ + if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) { + packet_mismatch = 1; + resp = 2; + + } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { + /* register mismatch */ + resp = 2; + + } else if (op == OP_TESTEND) { + resp = 1; + } + resp_fn(resp); + break; + case OP_SETMEMBLOCK: + memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri); + break; + case OP_GETMEMBLOCK: + set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) + + (uintptr_t)memblock); + break; + case OP_COMPAREMEM: + mem_used = 1; + if (read_fn(apprentice_memblock, MEMBLOCKLEN)) { + packet_mismatch = 1; + resp = 2; + } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) { + /* memory mismatch */ + resp = 2; + } + resp_fn(resp); + break; + } + } else { + fprintf(stderr, "out of sync %" PRIxPTR "/%" PRIxPTR " %d/%d\n", + get_pc(&master_ri), header.pc, + op, header.risu_op); + resp = 2; + resp_fn(resp); } 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. diff --git a/risu.h b/risu.h index 71ea94f..c01a9c3 100644 --- a/risu.h +++ b/risu.h @@ -51,6 +51,12 @@ extern int ismaster; struct reginfo; +typedef struct +{ + uintptr_t pc; + uint32_t risu_op; +} trace_header_t; + /* Functions operating on reginfo */ /* To keep the read/write logic from multiplying across all arches @@ -102,6 +108,9 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri); */ int get_risuop(struct reginfo *ri); +/* Return the PC from a reginfo */ +uintptr_t get_pc(struct reginfo *ri); + /* initialize structure from a ucontext */ void reginfo_init(struct reginfo *ri, ucontext_t *uc); diff --git a/risu_aarch64.c b/risu_aarch64.c index 5625979..312bd6a 100644 --- a/risu_aarch64.c +++ b/risu_aarch64.c @@ -43,3 +43,8 @@ int get_risuop(struct reginfo *ri) uint32_t risukey = 0x00005af0; return (key != risukey) ? -1 : op; } + +uintptr_t get_pc(struct reginfo *ri) +{ + return ri->pc; +} diff --git a/risu_arm.c b/risu_arm.c index eaf4f6c..a61256b 100644 --- a/risu_arm.c +++ b/risu_arm.c @@ -73,3 +73,8 @@ int get_risuop(struct reginfo *ri) uint32_t risukey = (isz == 2) ? 0xdee0 : 0xe7fe5af0; return (key != risukey) ? -1 : op; } + +uintptr_t get_pc(struct reginfo *ri) +{ + return ri->gpreg[15]; +} diff --git a/risu_m68k.c b/risu_m68k.c index f84ac7a..35b3c03 100644 --- a/risu_m68k.c +++ b/risu_m68k.c @@ -33,3 +33,8 @@ int get_risuop(struct reginfo *ri) uint32_t risukey = 0x4afc7000; return (key != risukey) ? -1 : op; } + +uintptr_t get_pc(struct reginfo *ri) +{ + return ri->gregs[R_PC]; +} diff --git a/risu_ppc64.c b/risu_ppc64.c index b575078..e702a00 100644 --- a/risu_ppc64.c +++ b/risu_ppc64.c @@ -38,3 +38,8 @@ int get_risuop(struct reginfo *ri) uint32_t risukey = 0x00005af0; return (key != risukey) ? -1 : op; } + +uintptr_t get_pc(struct reginfo *ri) +{ + return ri->nip; +}