From patchwork Fri Aug 19 03:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 598488 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp1069224mae; Thu, 18 Aug 2022 20:42:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR68EMuZDKO9VrXa0OvfL13SU6+BWMatbXn0Fe40SKqyM+DYV3ZIfIRENg/A9u4D1wWLvZW4 X-Received: by 2002:ac8:570e:0:b0:344:88d7:5ee3 with SMTP id 14-20020ac8570e000000b0034488d75ee3mr4947064qtw.522.1660880571404; Thu, 18 Aug 2022 20:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660880571; cv=none; d=google.com; s=arc-20160816; b=M3OhvxPXXB4DisEDwp+TL1K+W6HVcHtOIMcoXPuUZnTONtCogXByWz/ghkixeO8eFM znl0yG8EkNyKCSjZZH8wSpyF5oE7GKEWD6vg8Nem8mMd0+cdmfUr+tg8XxqHBDzAphOa NTsfORpAbQagkj19UCCcoUQYggbnyvVDJJjEKDwFq86lUpo7t6eI0nBTGhj/CRSea9xs 9vk1tqr6p4UJAFdOkEEdDKe6+/LlbEv2yVKj48hdpqZZTRdQq4ePEquC9ar2jUV71Ndj m8kBIXJJ2N4U2zAz9izzLMXe667hxcOX22s7bYOAr5uUbc7HKidUgq3RBIze6FmPA0M6 1L3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=x19w7YfjB2h5oqwKEQEJIlPdiLtoIpQZ8bzoyerjNiU=; b=GXV6YTTGG/zeKgnlQCgVIpX57E/UIQnROuX6j1t1WtiqLytK53I9ZvDuw2wUJcD+o3 WNEU3qR9A2hhDLHo33IP6OKY6izdHv6mRLWNTgo0sF0/WoxeBk5GMaBYkPoOAKjvpcuL 2VcrujzoMtVvdBK/E1NeYqI+70Vx8s+aEVqUhPjPtceZT7z1e730h2t3gLXmNpkCDehz BWuVwljWJaV5rwjuVC9n7Y3COIDWnRCZFilrnJkl4psiwgzIKwvhQGLuwteMTaqfkxlb RpTJhAulrOllh1/4aQHLSdGS5keS30CXLzKDTOrnixtgpFyb5cV8RC2YS4l3kxUlxV3Y jDMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x3AnRLgh; 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 m18-20020ae9e712000000b006b579afcaf6si1443552qka.298.2022.08.18.20.42.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Aug 2022 20:42:51 -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=x3AnRLgh; 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]:50778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOsuI-0004Mz-T9 for patch@linaro.org; Thu, 18 Aug 2022 23:42:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOseg-0002M8-QA for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:42 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:38438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOsee-0002mF-Oc for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:42 -0400 Received: by mail-pj1-x1034.google.com with SMTP id s31-20020a17090a2f2200b001faaf9d92easo6401076pjd.3 for ; Thu, 18 Aug 2022 20:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=x19w7YfjB2h5oqwKEQEJIlPdiLtoIpQZ8bzoyerjNiU=; b=x3AnRLgh42tz7kLYNwNWqMXuPeqOytRLrrz7c193IvW/VsNoMwYZd/ftwSPHA84Mlr agTuSj3JCR8n7Ilpov8gsJumCK8jLiMqltflCXru6142c8dyBUZVGUfyyO/s0jSujlko ZmO2gh1VRTiwEx88BLaGp0f274BWjIEyFh6YJaQo94xnvl0wv97TjGPRsBIffhhtP9zl SwVy9MptYOX8NzwRR9pn7Yk2Qa2E1wrq1rtW6wrZKC2qepCS7NrnWLKUmlfFgaI2pbR1 w8Mvx784Eono8H92WfNIQ7zANtxscFcVvqC+4dbG/3eoXKPcV6bviwLcypLLf7IQIVS4 uUsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=x19w7YfjB2h5oqwKEQEJIlPdiLtoIpQZ8bzoyerjNiU=; b=wy13lhDB0PyVjVfoXRf4qARR+OKDOxPh7eeaz7V60VmxyO51i1/aDUu/JAaXUz7gX/ NODDkDJFYO7CaCJpYjzlWXeGnQ2goMIN3GnyK8g/BW1VOFvaX2RZjc2FHEnypMQk56F9 fYgs55dOIgkKXcahi16oovggJ3SX5mCXxeOZKjG0vvar/C0EtpdHj9DaA6yOYrnB4bQg 9Lo6LCgQuSqWR9pwN8lsbABTg5rXUAR1rx42Ojym7jVuvE5jeE8c2NZsLSDtblX+rSOR 9gJMw0KEAp9ZaPx/Gs1SEby9b7I5JfHTHx1A68TZ6IAtWmY/3kZNjiU0m8dJzS2hShwV K4ZA== X-Gm-Message-State: ACgBeo3oAG+J/c5YpzeMDpJXbJWYg1MXVMjqYUqoHteMb9g61ZNXKnmC I3YK7kp0cXoeVdo523YXgSZqOSG6ywWM3A== X-Received: by 2002:a17:90b:4c8c:b0:1fa:c44f:473a with SMTP id my12-20020a17090b4c8c00b001fac44f473amr7587509pjb.195.1660879600002; Thu, 18 Aug 2022 20:26:40 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:bbf3:9914:aa9c:3b4e]) by smtp.gmail.com with ESMTPSA id g184-20020a6252c1000000b00535d19c46d7sm2199904pfb.203.2022.08.18.20.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 20:26:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, iii@linux.ibm.com, dramforever@live.com, alistair.francis@wdc.com, alex.bennee@linaro.org Subject: [PATCH v6 20/21] target/riscv: Add MAX_INSN_LEN and insn_len Date: Thu, 18 Aug 2022 20:26:14 -0700 Message-Id: <20220819032615.884847-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819032615.884847-1-richard.henderson@linaro.org> References: <20220819032615.884847-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com 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_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These will be useful in properly ending the TB. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/translate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 38666ddc91..a719aa6e63 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1022,6 +1022,14 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" +/* The specification allows for longer insns, but not supported by qemu. */ +#define MAX_INSN_LEN 4 + +static inline int insn_len(uint16_t first_word) +{ + return (first_word & 3) == 3 ? 4 : 2; +} + static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) { /* @@ -1037,7 +1045,7 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) }; /* Check for compressed insn */ - if (extract16(opcode, 0, 2) != 3) { + if (insn_len(opcode) == 2) { if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else {