From patchwork Mon Jun 19 10:46:50 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: 105824 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp811264qgd; Mon, 19 Jun 2017 03:53:42 -0700 (PDT) X-Received: by 10.31.134.203 with SMTP id i194mr11585641vkd.93.1497869622732; Mon, 19 Jun 2017 03:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497869622; cv=none; d=google.com; s=arc-20160816; b=BLf29cHiXila/vdH0g320c/hiEI01f7EYTmbYNFYvjnf7yEm+COJf6RB1jhJj2YtAt utn21HVnGdPwNNHBjVqsZymPZr+5e1HfxIK4Sca8ee/JwkrqIalvOHEFkAZRE112+C+5 SgnOGiVpWGdPFGuvnCmlhqQPeCZ3kFppzK46K4gqyNSDGQpimdJzWi7NJN1NiFeBqB+g UR4ghH2Y2ODaYyVLnpArDoOdqsO/iFC1wXLk/VPPH+apx0RiwgKQ701j5P7QjVWysHg8 hurkAHD2/IwLuPFicGMOyHFsfktwlzU0AAUgln2HYx/hdUbFlwdAU9y/QRO9wVMUxaqS R20g== 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=uMCKcSAJEv9E1m93eqmne+Mnp3bcYvmVZ3HdkhhaY4s=; b=uNdz0YgUljctFHBrGagZRdeZwvSaEcaa2zCLvCFqxPvK5fMpQKu02s9GGANYmXqobK hhdPktw9ULwrzInpx657TW4X5ZdwX0enmmcd0mQAMNhJpmTdIY468z6TIUn0gP6dqy1j 2PVuTJFToD9EhaClb4ZxJWJimvLF0Swymp1qJyptSb0ccavl9pA7QhgMaAk4zdxmSOAu 4qxG6m8TSc3m11+j1EV5IUz6Mpl6sTrIkxlGqLk6J/IMDuk9F3dAjIVNQZkuhxQlOYZh /BWiOQUTocl/EQ05GeX52TFYLfenobFji8ak1cO/5cxotupGLKyPMAB6U2Rc3lQIoaD0 xVWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=Evc1vx3C; 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 b2si2583768uaj.91.2017.06.19.03.53.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Jun 2017 03:53:42 -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 header.b=Evc1vx3C; 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]:41676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuJS-0004tt-9Z for patch@linaro.org; Mon, 19 Jun 2017 06:53:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuCU-0007Mt-Ej for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMuCT-0004un-DD for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:30 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:34415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMuCT-0004tt-3w for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:29 -0400 Received: by mail-wr0-x22b.google.com with SMTP id 77so69495531wrb.1 for ; Mon, 19 Jun 2017 03:46:28 -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=uMCKcSAJEv9E1m93eqmne+Mnp3bcYvmVZ3HdkhhaY4s=; b=Evc1vx3C4OWiPfJW+1jaP5DxxqsyHsAVOjYgHIw8oqOaPDWe2/rABiU0E0+smweNW0 yQvqIttb9kMWhYacYogZM4og0FIfwIzGTZOlSKmXDlPUOfgKoFMcNa43eq6k4FJ6c2UP aV2U04cFc4UAk43ZusNRCBABYLVsnVxV/PwOE= 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=uMCKcSAJEv9E1m93eqmne+Mnp3bcYvmVZ3HdkhhaY4s=; b=sKa77KIZb+Dn5/nyYxVdvsarNrx1C4aBTiZbpk/gKwMfqjA6w/nAu6QiAJ7VzgIqQY 6+4bMfnzZKWqMS1Dq1E6YJBtBKvM/YmCARiNN0Qsci36du/f4sNqbC9GRKY/+He239vq FxFJmI7CuzV+ceYGJX0/gAHuO52xtbvJWvjp2e/sbkEfdDqg3zv7LT7+WwfTF4SEjACc JrQLEZecnrg3ao8kywzPeftKwFkAo75VSg4Oq7IAtGtApLk9jLePhEv0zLarMQ+ZeokG zAVbqotpwZz+YSMFdorC28oYDlKau1Dv3rHxQqFchQKkhQ9dZEDYul71k9tnSzrYT3WF EDSQ== X-Gm-Message-State: AKS2vOyTNnhyiw5aHzXw1YTNMVKwGaze2UWLFMITB93PrtwC0ylbo1Db 0b35DC7z2P7cNgss X-Received: by 10.223.132.130 with SMTP id 2mr17290538wrg.157.1497869187934; Mon, 19 Jun 2017 03:46:27 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q143sm7917773wmg.14.2017.06.19.03.46.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 03:46:23 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 67F693E0BE2; Mon, 19 Jun 2017 11:47:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 19 Jun 2017 11:46:50 +0100 Message-Id: <20170619104655.31104-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170619104655.31104-1-alex.bennee@linaro.org> References: <20170619104655.31104-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 v5 08/13] 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 --- v5 - re-base without formatting fixes - dropped fprintfs in signal context v4 - split from previous patch --- reginfo.c | 94 +++++++++++++++++++++++++++++++++++++--------------------- risu.h | 9 ++++++ risu_aarch64.c | 5 ++++ risu_arm.c | 5 ++++ risu_m68k.c | 5 ++++ risu_ppc64.c | 5 ++++ 6 files changed, 89 insertions(+), 34 deletions(-) -- 2.13.0 Reviewed-by: Peter Maydell diff --git a/reginfo.c b/reginfo.c index 90cea8f..4ff937f 100644 --- a/reginfo.c +++ b/reginfo.c @@ -24,10 +24,19 @@ static int packet_mismatch; 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) { + return -1; + } + switch (op) { case OP_TESTEND: write_fn(&ri, sizeof(ri)); @@ -63,46 +72,63 @@ 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; + if (read_fn(&header, sizeof(header)) != 0) { + 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 { + /* We are out of sync */ + resp = 2; resp_fn(resp); - break; } return resp; diff --git a/risu.h b/risu.h index 32241bc..e9e70ab 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 9c6809d..492d141 100644 --- a/risu_aarch64.c +++ b/risu_aarch64.c @@ -40,3 +40,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 a55c6c2..5fcb2a5 100644 --- a/risu_arm.c +++ b/risu_arm.c @@ -68,3 +68,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 0bf5c14..1056eef 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 eb60573..83f8d1f 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; +}