From patchwork Fri May 22 02:34:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 187121 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp2103650ilb; Thu, 21 May 2020 19:38:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRPqmt+w7hZqCo6ZLVdQyf2r5mnF90KWssQJgCBYYF8TOYnhe/+LvJJnEM0Y16kRh6fHRZ X-Received: by 2002:a0c:e947:: with SMTP id n7mr1759725qvo.165.1590115089039; Thu, 21 May 2020 19:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590115089; cv=none; d=google.com; s=arc-20160816; b=AOysQ13Cz9IvtEs51PGZe4qJ+XEK7ds8Ihqy2yYiuYwjlIBTKHZm97FbiQW79/0F2D vTCYrPq2nSjzzHoPnxlBRJCl7P64whkQXgIMJWfhRJieWsDHa5vOAB/OmuA1akeVyvWy v5KV6WRnhSwE+l9tYsVRaHZSuUOqoz6U7BH/XDt8LYBng1Pvi52VOQ1fXbxCaafsHZhy MpKjtMk4M4zJnEf3RrQVmZ/EEer7q1LBxsdyhJzDjT8mLyRMfX+JcC0+6GxHKOb66+Oq 43kUQJ+VO/nd1GrKooOCZVdLh+vMj6H0xa3BG6xa2QyeZEjqQdJ2np/7uC5GzahkV+0C 6oxg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=pUDhKq2QDEDanz0bWwiGRznNEu5AkBEdSOmZLuPk6MM=; b=X2rkCjnq5dG66wb6O7iJ0fk2NU2GUJME/QUoZayL53Qqw8akho0RvGWIRvt/avGGlY QLjwAVNIZgoBl8NiROtgTS+BclNme0H2fezGgKTg5upXzdXDJmZQq0nbaYcFB/5rFCun CgRMa+YGrDHZz38hnI15ZNE096KE4FwYVUi41yEqWfsFhN2gEUsRNB8pDT71unjPnxSW SHFwh2O2ERjXPC6NdK1thlpDSOv7ma6Y0k7E+PA+6B6lCVHmDeOx1QNd/4+UV6ziZv4C igGOlJATk2wSVvm8EU1n6e8IqB+5P7dqw3/65/dnqN7UyJQ003iaR3LvZoQExMyT7IlL ElpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kAhNLlZz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r4si3975071qtm.294.2020.05.21.19.38.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 May 2020 19:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kAhNLlZz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbxZY-0002FI-Iv for patch@linaro.org; Thu, 21 May 2020 22:38:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbxWP-0002J8-Ot for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:53 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:42280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbxWO-00056U-LC for qemu-devel@nongnu.org; Thu, 21 May 2020 22:34:53 -0400 Received: by mail-pl1-x634.google.com with SMTP id x11so2823481plv.9 for ; Thu, 21 May 2020 19:34:52 -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=pUDhKq2QDEDanz0bWwiGRznNEu5AkBEdSOmZLuPk6MM=; b=kAhNLlZzg2GBWJw+ycBl3L6CRTnj/U9QsqOlpiX/UYaf5Ujo/5+D6ILOgKr+5SMmY5 xG96qiAGbapeuTLSl5gA66pwQ7fPVqeqE+Jx5a8jLgme/nyy7dZc8niVvptL6oOKdGcS N/Vaj75ePGXGmlLG/usRefmMcbMnKRyqvsJsFLQSyy+rWaIju3Qiki677TvLDt+kzb3B 6Lfji/PYU57qxaBTUfWkDXEYsGsue0EKXJaIul60QhT+NUdecdbA4ERKOl8XIjETf5pA yFvu40r/NGeEY4u2qKjz+QsHVudMpemUF0QHUGJDqiBT7A4E3Rbp6MpHSPqjr23zRYFR lRbg== 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=pUDhKq2QDEDanz0bWwiGRznNEu5AkBEdSOmZLuPk6MM=; b=RwvBXF8b6AownatS+4SIKVm3Ynh/Z+h02XYRCciD0zGhHxLCyXh+BkaBDHF+LfBd1e o8zJcS584xaIhmcexBzoTvkbqFhom6enafwgm3fYCv1/DeKQm7IW7x6ZLybqSbzUu7zy iHuwiZObLDOjDcjSDNkb8XAJFQTXNJcw4a2Ba86Ke/7lcfE6TyEnCoZ9EAZnB8ZFJ4bL scvjBEP/wVBh5Ubf8uGVShOaIs3QIeJtMieWzBljhMof6mVHAgF3/MxzuOhzi3TOAbpu 7bYmePoNSFparnfdy0Xdll/pCGK3i2l9MFKLmJiJuGjuZx7MRyjCF96XF90bqsO0A222 JXFQ== X-Gm-Message-State: AOAM532JkYsUmVn5QbkqwsvGL5lalFVikr5t4K/DowV5/UUh8U8mwiEX TOsTMbQehwmec/qdFWD1v62pUEqXORs= X-Received: by 2002:a17:902:a513:: with SMTP id s19mr9034196plq.168.1590114890804; Thu, 21 May 2020 19:34:50 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id gt10sm5443755pjb.30.2020.05.21.19.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 19:34:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 07/25] Add enum RisuOp Date: Thu, 21 May 2020 19:34:22 -0700 Message-Id: <20200522023440.26261-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200522023440.26261-1-richard.henderson@linaro.org> References: <20200522023440.26261-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Formalize the set of defines, plus -1, into an enum. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- risu.h | 23 +++++++++++++++-------- reginfo.c | 32 +++++++++++++++++++------------- risu_aarch64.c | 6 +++--- risu_arm.c | 6 +++--- risu_i386.c | 4 ++-- risu_m68k.c | 4 ++-- risu_ppc64.c | 4 ++-- 7 files changed, 46 insertions(+), 33 deletions(-) -- 2.20.1 diff --git a/risu.h b/risu.h index e2b4508..a7aa929 100644 --- a/risu.h +++ b/risu.h @@ -45,11 +45,17 @@ extern uintptr_t image_start_address; extern void *memblock; /* Ops code under test can request from risu: */ -#define OP_COMPARE 0 -#define OP_TESTEND 1 -#define OP_SETMEMBLOCK 2 -#define OP_GETMEMBLOCK 3 -#define OP_COMPAREMEM 4 +typedef enum { + /* Any other sigill besides the destignated undefined insn. */ + OP_SIGILL = -1, + + /* These are generated by the designated undefined insn. */ + OP_COMPARE = 0, + OP_TESTEND = 1, + OP_SETMEMBLOCK = 2, + OP_GETMEMBLOCK = 3, + OP_COMPAREMEM = 4, +} RisuOp; /* The memory block should be this long */ #define MEMBLOCKLEN 8192 @@ -114,10 +120,11 @@ void set_ucontext_paramreg(void *vuc, uint64_t value); /* Return the value of the parameter register from a reginfo. */ uint64_t get_reginfo_paramreg(struct reginfo *ri); -/* Return the risu operation number we have been asked to do, - * or -1 if this was a SIGILL for a non-risuop insn. +/* + * Return the risu operation number we have been asked to do, + * or OP_SIGILL if this was a SIGILL for a non-risuop insn. */ -int get_risuop(struct reginfo *ri); +RisuOp get_risuop(struct reginfo *ri); /* Return the PC from a reginfo */ uintptr_t get_pc(struct reginfo *ri); diff --git a/reginfo.c b/reginfo.c index 1b2a821..2d67c93 100644 --- a/reginfo.c +++ b/reginfo.c @@ -11,7 +11,7 @@ #include #include - +#include #include "risu.h" struct reginfo master_ri, apprentice_ri; @@ -25,7 +25,7 @@ int send_register_info(write_fn write_fn, void *uc) { struct reginfo ri; trace_header_t header; - int op; + RisuOp op; reginfo_init(&ri, uc); op = get_risuop(&ri); @@ -38,11 +38,18 @@ int send_register_info(write_fn write_fn, void *uc) } switch (op) { + case OP_COMPARE: case OP_TESTEND: - write_fn(&ri, reginfo_size()); - /* if we are tracing write_fn will return 0 unlike a remote - end, hence we force return of 1 here */ - return 1; + case OP_SIGILL: + /* + * Do a simple register compare on (a) explicit request + * (b) end of test (c) a non-risuop UNDEF + */ + if (write_fn(&ri, reginfo_size()) != 0) { + return -1; + } + /* For OP_TEST_END, force return 1 to exit. */ + return op == OP_TESTEND; case OP_SETMEMBLOCK: memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri); break; @@ -53,12 +60,8 @@ int send_register_info(write_fn write_fn, void *uc) case OP_COMPAREMEM: return write_fn(memblock, MEMBLOCKLEN); break; - case OP_COMPARE: default: - /* Do a simple register compare on (a) explicit request - * (b) end of test (c) a non-risuop UNDEF - */ - return write_fn(&ri, reginfo_size()); + abort(); } return 0; } @@ -74,8 +77,9 @@ 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; + int resp = 0; trace_header_t header; + RisuOp op; reginfo_init(&master_ri, uc); op = get_risuop(&master_ri); @@ -97,7 +101,7 @@ int recv_and_compare_register_info(read_fn read_fn, switch (op) { case OP_COMPARE: case OP_TESTEND: - default: + case OP_SIGILL: /* Do a simple register compare on (a) explicit request * (b) end of test (c) a non-risuop UNDEF */ @@ -130,6 +134,8 @@ int recv_and_compare_register_info(read_fn read_fn, } resp_fn(resp); break; + default: + abort(); } return resp; diff --git a/risu_aarch64.c b/risu_aarch64.c index 492d141..f8a8412 100644 --- a/risu_aarch64.c +++ b/risu_aarch64.c @@ -29,16 +29,16 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri) return ri->regs[0]; } -int get_risuop(struct reginfo *ri) +RisuOp get_risuop(struct reginfo *ri) { /* Return the risuop we have been asked to do - * (or -1 if this was a SIGILL for a non-risuop insn) + * (or OP_SIGILL if this was a SIGILL for a non-risuop insn) */ uint32_t insn = ri->faulting_insn; uint32_t op = insn & 0xf; uint32_t key = insn & ~0xf; uint32_t risukey = 0x00005af0; - return (key != risukey) ? -1 : op; + return (key != risukey) ? OP_SIGILL : op; } uintptr_t get_pc(struct reginfo *ri) diff --git a/risu_arm.c b/risu_arm.c index 5fcb2a5..a20bf73 100644 --- a/risu_arm.c +++ b/risu_arm.c @@ -56,17 +56,17 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri) return ri->gpreg[0]; } -int get_risuop(struct reginfo *ri) +RisuOp get_risuop(struct reginfo *ri) { /* Return the risuop we have been asked to do - * (or -1 if this was a SIGILL for a non-risuop insn) + * (or OP_SIGILL if this was a SIGILL for a non-risuop insn) */ uint32_t insn = ri->faulting_insn; int isz = ri->faulting_insn_size; uint32_t op = insn & 0xf; uint32_t key = insn & ~0xf; uint32_t risukey = (isz == 2) ? 0xdee0 : 0xe7fe5af0; - return (key != risukey) ? -1 : op; + return (key != risukey) ? OP_SIGILL : op; } uintptr_t get_pc(struct reginfo *ri) diff --git a/risu_i386.c b/risu_i386.c index 9962b8f..127e816 100644 --- a/risu_i386.c +++ b/risu_i386.c @@ -38,12 +38,12 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri) return ri->gregs[REG_E(AX)]; } -int get_risuop(struct reginfo *ri) +RisuOp get_risuop(struct reginfo *ri) { if ((ri->faulting_insn & 0xf8ffff) == 0xc0b90f) { /* UD1 %xxx,%eax */ return (ri->faulting_insn >> 16) & 7; } - return -1; + return OP_SIGILL; } uintptr_t get_pc(struct reginfo *ri) diff --git a/risu_m68k.c b/risu_m68k.c index 1056eef..acdd57a 100644 --- a/risu_m68k.c +++ b/risu_m68k.c @@ -25,13 +25,13 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri) return ri->gregs[R_A0]; } -int get_risuop(struct reginfo *ri) +RisuOp get_risuop(struct reginfo *ri) { uint32_t insn = ri->faulting_insn; uint32_t op = insn & 0xf; uint32_t key = insn & ~0xf; uint32_t risukey = 0x4afc7000; - return (key != risukey) ? -1 : op; + return (key != risukey) ? OP_SIGILL : op; } uintptr_t get_pc(struct reginfo *ri) diff --git a/risu_ppc64.c b/risu_ppc64.c index a3028f7..9df8d58 100644 --- a/risu_ppc64.c +++ b/risu_ppc64.c @@ -32,13 +32,13 @@ uint64_t get_reginfo_paramreg(struct reginfo *ri) return ri->gregs[0]; } -int get_risuop(struct reginfo *ri) +RisuOp get_risuop(struct reginfo *ri) { uint32_t insn = ri->faulting_insn; uint32_t op = insn & 0xf; uint32_t key = insn & ~0xf; uint32_t risukey = 0x00005af0; - return (key != risukey) ? -1 : op; + return (key != risukey) ? OP_SIGILL : op; } uintptr_t get_pc(struct reginfo *ri)