Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2641329ybh; Mon, 9 Mar 2020 09:56:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsRCJejeCweP+HrnB7YMNPyfsMJK28Cd+dd2ukG9QxQ3+AvwEN5hbZgsAhqOoBXL+gK2lju X-Received: by 2002:a9d:6544:: with SMTP id q4mr13081128otl.269.1583773011985; Mon, 09 Mar 2020 09:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583773011; cv=none; d=google.com; s=arc-20160816; b=AQNTQzpYbSPTY/Ma74KsPrPG9SIYXjNaX9Xlm4bSwr3eRaOETMl74oSqkthNET2VJP ifqfYv4T9FGrb9XTY8IpQgA+bG9ULSlxIW1fcIudkdKjMfhMMNetpl7BUDbSa/EEDqrg 9sE8Z6q1oaoWVx9Q0BMoHm4AGkg2RBIpL7RrIjJI9uOEhl2IobwYg3Nvx7bqeNZKY1Kc PBKUoG9z9Siuu8n6hnMcyKQHxEGZb+8RHbPsr4+meOv5h0UUNl3k6o/aHZCVJwYECkYB fOEpoYXrGlOICxc+pqfnshF3t6+IpdKA3ihySZdy0Lkv+9WddobdjPufaH0OiVlZ67wh Hd9g== 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=DKBW8Eyy8NVtYJgHutHlswaK8NeRD9IAyJm/+12aBBY=; b=E/FrEqc4kBD+XqsSo4+d1fsxa98THZSNziWBS5dzBuXDlqaMGpYLQkPSL3nT0mMLyB Qex/iT6/EbtCiziiiBkODrkYywyzjb4C14VQIaNfz7IDYMva+wQ4ctYUbmb81sV48aVJ 1kSI1wuXm/h9ZzDtOzY7NdNxfNy8DCDJxV2NarvEZMC4Bp00RoVEFCoYZvHFNgXiPx6I +CTMk6+owS7dDjV+BDVPNdQeYM69oMQyeN3bYq0u5l8XfhoSDcCnEVfP2HsvOr0CDH1a cDsDhg81aBcMNNTcF35L5Do4g4u4hfMuOQfFIJgCQydWGMrRCXc8Ryfd5af0ryrtbi/R HawA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=REj3KT9K; 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 k11si545394oik.241.2020.03.09.09.56.40; Mon, 09 Mar 2020 09:56:51 -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=REj3KT9K; 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 S1727366AbgCIQ4J (ORCPT + 99 others); Mon, 9 Mar 2020 12:56:09 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45395 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727341AbgCIQ4G (ORCPT ); Mon, 9 Mar 2020 12:56:06 -0400 Received: by mail-pf1-f196.google.com with SMTP id 2so5063067pfg.12 for ; Mon, 09 Mar 2020 09:56:04 -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=DKBW8Eyy8NVtYJgHutHlswaK8NeRD9IAyJm/+12aBBY=; b=REj3KT9KCk7pmUAzQenlRZ2UdxDM55l7D4o43L3PCGSAW2igoKTdhOdGSHha/5ZV0k PWnirmLcaBYdBy+ACtOq048Ky2eKNeoaSFswZk4gUbnNj2EpUH3DERiyVDErdUcN5bL4 f7rGeupxtqCtvj2wmTCxeWyv/EgbYZAPatwSOsy69GjDytGquusfnE5lStT5PC2n+LB0 +deFikDuHSYPI2k3e8zYswywhoFtwypPlee3loaubnkMY59DP6jyRznBAFNfCb2Z4d3x 94ITFyNP6J5LaBX+WtURnXC0csngUwZMMW6VnLjRJqEnlG9otg0Wqxcm4esJikPDD970 cB4Q== 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=DKBW8Eyy8NVtYJgHutHlswaK8NeRD9IAyJm/+12aBBY=; b=cSecfLF/TEkoCi+yjbvgaaLeA8bIl4EpLAE9wshZKD98a0lRGFbiVFQmxLo9uMHBpL XERRPDlvCTVAVeNhQ0uYKgiwgPc8cMI1feKoy5JWQ4rg3/CA6lED+9X4KPLzavEeSPE1 pMrrwx1LLYP3rJzFVUEoCGFsKVnMFPg/oO9VdQWMthKFSE0VYAuAmDJMjrEF/IEGErKA HKjlYutmkaHoR6mkWEP7bdp6knZOPjHJ7uYXiLQ1buZw7Cpy/Uhop8zQ7vMb4SNBq1l7 9Epyz3q/l6XKRIlR7aFJbov+FXxYVyyUYqSRezquVWRMODNdR4BUKpEl78f6cViQq2aV AB/g== X-Gm-Message-State: ANhLgQ1sRYtN2I/916cLGtlP9e8OZF0vw4WwFQmo0yxyz7CYSl4bKNwB hf7cNEm/VS4AeZ+eD9lFt+sLag== X-Received: by 2002:a63:348b:: with SMTP id b133mr17387820pga.372.1583772964283; Mon, 09 Mar 2020 09:56:04 -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 cm2sm104013pjb.23.2020.03.09.09.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 09:56:03 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v3 7/9] riscv: add macro to get instruction length Date: Tue, 10 Mar 2020 00:55:42 +0800 Message-Id: <8f933bed0478a1b4029447e1f8eef2ce0aefed4b.1583772574.git.zong.li@sifive.com> X-Mailer: git-send-email 2.25.1 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.25.1