Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp360018ybb; Wed, 8 Apr 2020 01:00:02 -0700 (PDT) X-Google-Smtp-Source: APiQypLvb7qrqimxJuYowYX+jTSy1f930MyaU9v9uJpXTcCSv+62Qz4L6bcrcgKJ6SlcC4s3rNfd X-Received: by 2002:a05:6830:1c65:: with SMTP id s5mr4959201otg.25.1586332801865; Wed, 08 Apr 2020 01:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586332801; cv=none; d=google.com; s=arc-20160816; b=iAiqK1oblTDDaFggghX42Vnt4lcBvFgFm95/misTiszsTWLSpNvVWBjZqq8W8Q4sz/ YBaxaYE3a1Zi0gmpLNqKiygPoSb3shTijxI3Xz//HCgGwe5naDRy3/u1tfxY5EI5yy9r tcYQbx89bYNyj/q9XMV7h5PotvGTTx6epCVNqW9vAibssnr/gx89CUyNKno1QunDSYWe AynjM42xKjmGM9uZWPRnwD5Y9AuWl3Fb/3fCJa/bs74rcp0tXGgjT4mSE7ok0LpHq4N2 wlMxdAn26Cr5hwdM0cvgu1Pje+JTZm1iyn/j38yUA4jrhIWM0ypr8phkUuToMvkQInSa 9ZUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tOQsL1UwAyeSD7aVc86VJnzoqXGbBrzuC9r/s6opFAQ=; b=F0wi8YRYDWaxMwK21Qe4NnIdpWgYt8kY7Jco7IAW90flxhPOZwEN8qfO/lxHjdbRxa YZeeOsW8RHYHkDOvcwD6h5xj59xd4OZjw/Ypf8+ohXJIpis4MLYcssA4OFUtQ0aS9vn5 SFe+pLTJPvofj04uRJiqhMNC3BHUEMc6BJDgF4IBO9I0E/2gEY3fuDQ2exeNunfE8RXp yyI1RH8a6H7YZlVoQ1ZPeIkMW1P+0ojotT/GuUhD+0WxfaFjx/jeqfTusvVrktmGnA9i GDBVNluLwj/DgqYbEwarYJcItR1AVmsZfQ68VkOsZG4cmFyPgIHTnFzveUME7uMrKQbz lrFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Kn66xOjs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g20si2100645oop.14.2020.04.08.00.59.47; Wed, 08 Apr 2020 01:00:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Kn66xOjs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbgDHH5M (ORCPT + 99 others); Wed, 8 Apr 2020 03:57:12 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34290 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbgDHH5L (ORCPT ); Wed, 8 Apr 2020 03:57:11 -0400 Received: by mail-pf1-f195.google.com with SMTP id v23so2702157pfm.1 for ; Wed, 08 Apr 2020 00:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tOQsL1UwAyeSD7aVc86VJnzoqXGbBrzuC9r/s6opFAQ=; b=Kn66xOjs81SGng0oCT/+Z7hx0FVYo/eEbSiAPSkG9YVazysZSGW4dQ90RJVw3fhxTU LjJTuf3qNq70mPiPOSxgd3h57DEvXCZ4aaKn8N0CWCciCzKED0k7HF0Tu2fNtAMQ4T0k 4c6XsSZEpyV80iSmIYTvIqO9MXT32jyPMkSRuqmIC1LEYBF6OB3BZ+ajDJ4YboAcW1DI 7NKm61fnwUrEFJkjyStI7+n8KexOl+3V3WwgZQYS/GQpoeqSunEHf249g+eF8J4tP0PX cJCST86Qnj/SwsTN+DWIWo6oRiD/mhGFKz4rr2flD9ipTpcUO41ef2MS2ymx9Vevq3uT D9Pg== 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=tOQsL1UwAyeSD7aVc86VJnzoqXGbBrzuC9r/s6opFAQ=; b=ahQPOAKKzuAoTNfMP30epdPGxTxZa6BFfYb1WRCPD4yPPBuUgsyJp902Pub1IUQnbR ukP2sqcxGOw+zQSVHj/LM1L3V9d8JYXG/cRtRIr77Mukpv7cca564A9njrxe7Ar/2TX2 qaxfzCKZVfNeFkHEzwH+s5iEF2UhUDfN+X8VI9MF5ns7ytGeZVIlpMtUH5PP/2fyEcdV X8MbCrSRvJgMDWBHrJGCDU0lflBEkMUXtEbB42qmsA/lSQiNKHgiFF7uTXAiDJ1x2LP4 LYVZudR4gsQjiqJs8LNEGh83XL+meO3ZNiEAExTjQlAphy6gntxnhcHDo4+flZcIda76 p30g== X-Gm-Message-State: AGi0PuZ6lmaQ3gHnQVTbbgQlLSWLTqz7p83hgP60rIjM3OV55c04n0vt ufZJWc2ljHEhAu8gi2+lbb+ELw== X-Received: by 2002:a05:6a00:2cf:: with SMTP id b15mr6388378pft.174.1586332631240; Wed, 08 Apr 2020 00:57:11 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d85sm485599pfd.157.2020.04.08.00.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 00:57:10 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v5 1/9] riscv: add macro to get instruction length Date: Wed, 8 Apr 2020 15:56:56 +0800 Message-Id: <621303b9cdea215af57329b401b15750c1f683ab.1586332296.git.zong.li@sifive.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extract the calculation of instruction length for common use. Signed-off-by: Zong Li --- arch/riscv/include/asm/bug.h | 8 ++++++++ arch/riscv/kernel/traps.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h index 75604fec1b1b..d6f1ec08d97b 100644 --- a/arch/riscv/include/asm/bug.h +++ b/arch/riscv/include/asm/bug.h @@ -19,6 +19,14 @@ #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */ #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */ +#define GET_INSN_LENGTH(insn) \ +({ \ + unsigned long __len; \ + __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \ + 4UL : 2UL; \ + __len; \ +}) + typedef u32 bug_insn_t; #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c index ffb3d94bf0cc..a4d136355f78 100644 --- a/arch/riscv/kernel/traps.c +++ b/arch/riscv/kernel/traps.c @@ -118,7 +118,8 @@ static inline unsigned long get_break_insn_length(unsigned long pc) if (probe_kernel_address((bug_insn_t *)pc, insn)) return 0; - return (((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? 4UL : 2UL); + + return GET_INSN_LENGTH(insn); } asmlinkage __visible void do_trap_break(struct pt_regs *regs) -- 2.26.0