Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4452684ybb; Tue, 7 Apr 2020 07:47:50 -0700 (PDT) X-Google-Smtp-Source: APiQypL1o/ATh+guunuubpKxBZhgcMoYqECzH517JkbxPKhKcROAa6eH9spl6vYOp1sm5fm8hZ9t X-Received: by 2002:a9d:69d8:: with SMTP id v24mr1885531oto.148.1586270870858; Tue, 07 Apr 2020 07:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586270870; cv=none; d=google.com; s=arc-20160816; b=TDkWE1i15o/HX3SIyAP0Gn03NY1MZwthw+V09wUanIgZdWaIYLofRVcy/lHo+/sS+o jpNj7aTGhyF9dbidr0m992/PxDwPHfruQZM1m9bqsrPByXkKIpyTn7vwF3fMCEmOAN90 HE4wMRP3gLf4S2BKnUxgA229QYfj7rnHOilI5mAenXMt85vUCJPE6Z/G7VWFZB6lM73t UQCluiOVXGABke/sN5oGM6aDXc4CcwZRZxdvgHr4RxsZ/ATqBUjkDzidwKMa1MgY+V2G G/qPIepDlyHqqdPn0BaCM32raLcyfkmFZo4dUKLSeZNCKSjsMixWqzZmwm46Zv+hzWpQ LNag== 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=nNcn6YFFdMEhnVpwbtECVP48JSrIjlVAOh5PMlI/SH4sQ5lwXqjDC7O9XjK3PonJk0 dZKK6D2H4Y9V1E2EvxUueQ3F/cZSizauDvSxba1XZzdKjUIg01CjEKtiDZpYwIfW4rMc LHrSoHkvfdBHshFVLRHsskHy9CEUqo0iB0SXPBnBp61OCpuTUBr7t1/KBK0OsKiRk5+s dKbdhvftckcwTr7qlXGva910ddO5N1XthY9Miw/xnrXvb8vtNqwa86ruEV+9ENu5kAfD Cd8NoylQ119bMNRj60XEjK+S1PYyAi13+1i/22qDdPR92MwroRSHqxnGh2CKDKNV99iT CC1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jNjrdO2j; 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 r6si1220222oij.49.2020.04.07.07.47.37; Tue, 07 Apr 2020 07:47:50 -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=jNjrdO2j; 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 S1729234AbgDGOrD (ORCPT + 99 others); Tue, 7 Apr 2020 10:47:03 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44972 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728855AbgDGOrB (ORCPT ); Tue, 7 Apr 2020 10:47:01 -0400 Received: by mail-pg1-f193.google.com with SMTP id n13so396311pgp.11 for ; Tue, 07 Apr 2020 07:47:01 -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=jNjrdO2jGlUgSUD9yX89DPR2/2/A55WbbxmEk3D0BPwG9P1qqJkWGiOZ6K9PUE6NI4 ggW+RiFHKkMdsNH4G7JFuLFLB5oFS2LD3ruTt4WslQzsgp4tDE7Cfb8tUftvsBRs3alZ cRRTKvMno8t3cQ4xm6nyN5D0ZzW605zJkEX/DPb47MrtJhxxIEYXO48Fi6A2BOsIJkuu W4CCEZS9aswddXKsB5i3wPQ+2evp1ZGk6FxrS1iQhRL//uz2e11ktzh4CsfIymvLlXCB 2IISADHqCpS4TEXjaRGAoEN64Ct+cjeGOUPvrfx5zDlrSRDrt7GYwCwHG4f3SsBRy6sD gefw== 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=rR78N/MJGxNYLGNpNRiUNvNr5tYG5bB7vFe99ckSX+3tlBYNsFDGtLTwvSOOAVHhaJ 6Z5cfgz6/ughXgv/IsblAkH654Mo8JHUPLXAwowqztuuPRIIXk0UnB9qLNO07/PQOqUO B28+ImBc4ntbBGL+hvUJgxDW18gt6GAu5+wBuRcWJ/fOR0cMlcdSAUoC/lK482UoPr/c /yWy8tBQ+7ozWLnVSUMZv9SKAMMB1SNk6ypRswTjKfirGMnhkzs+TaLE51XDQCyE7ulm 1NDTepf9kNzoB1oCS4cAAHTq5Jf6DV6f+FWI8OffCz4uFO7YAPD6wvl+xv3EoyWUleXZ TZzQ== X-Gm-Message-State: AGi0PuapHVI2IjP6giAhOZ4/Hjif+6sA8Z7atI2yvyLb72E2gL12kqs5 qmAZdOncsPpOFOdTSkoYFJ3fOA== X-Received: by 2002:a63:a052:: with SMTP id u18mr2473808pgn.210.1586270820635; Tue, 07 Apr 2020 07:47:00 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id y15sm14190093pfc.206.2020.04.07.07.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:47:00 -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 v4 1/9] riscv: add macro to get instruction length Date: Tue, 7 Apr 2020 22:46:46 +0800 Message-Id: <621303b9cdea215af57329b401b15750c1f683ab.1586265122.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