Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1211035pxb; Wed, 6 Apr 2022 11:25:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKRy1aEKYZDpsn3gmb6GJhFxuaTdXzGFxsE35EACFFOkBjAGF6+7QWy4OX0eDCydFFvxvZ X-Received: by 2002:a63:6bc9:0:b0:386:2e2b:41a2 with SMTP id g192-20020a636bc9000000b003862e2b41a2mr8215728pgc.444.1649269530749; Wed, 06 Apr 2022 11:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649269530; cv=none; d=google.com; s=arc-20160816; b=l0DNQTUOZlyvhY0I6Xz9ASwI3cgupWzhP04BYoB0dP2ScZAlOt4mMfMO5sseBtsGfg ZqmDG7BPHh82C5Y1ZreFFry134LS7G0napLxRYIXPyZRM1uB8GP6JtuCx0DzoEu1A0pX B5F7vWto58pEvIzEJtodZO0vVDOT3ipqYfVRcxQUmk2yfXpPL8a7tQXYxb9BefFbcium nII1sAtHQzLa1VD2uQllvvd4ATMSmgAz9lW+g8S0JscMhHifhpdPjFPnTE10Ql1DitHD Q16DSC/nu6/USBZFT9dZ9/UB6Qt/iElUDFWsa8STIoeO9oLNHw5Zy3sNyarNDbA/KokU mPqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7L4CscAxHjT9+S06VgylL4T75oAwygflWZqD7rsWtc4=; b=FuC8CTAQEu8umClatC+E3QCas8sRzjFCSNjY22h4n9wo/mfOa8Kw/7DmWgctCK14vW 30ewMv6y9RZnAVCKMM35YvoaBbqzt2uUbB+tEtA/llNIr1y28eBMYHMk8SIkT+Zq9amf kBufw6oc4AYxFpPNJjuFb7sXo793q7bgGeVhLtDqmlwoC16Rva5+L0BGBHoMhAwetKiH E6Lz/tHopu9IHti6rkWi3zrlNq7n6WX/7o16YIDb/L3hq1dMYMqGRI9zhaBtl+g8rgp/ OFBY/viRHk7ZGrNze7WwuaBqllY66jT8hFxaOsGw621nPP+94TvQvyZTPvzSSiXiFGkZ ZBmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id p10-20020a170902e74a00b001546b3da72esi17567515plf.71.2022.04.06.11.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 11:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1FAD1B370B; Wed, 6 Apr 2022 11:08:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239761AbiDFSKB (ORCPT + 99 others); Wed, 6 Apr 2022 14:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240513AbiDFSIE (ORCPT ); Wed, 6 Apr 2022 14:08:04 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C3E0F12298F; Wed, 6 Apr 2022 09:46:23 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA8DB12FC; Wed, 6 Apr 2022 09:46:23 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.218]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 095903F73B; Wed, 6 Apr 2022 09:46:22 -0700 (PDT) From: James Morse To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: James Morse , Catalin Marinas Subject: [stable:PATCH v4.9.309 24/43] arm64: Add helper to decode register from instruction Date: Wed, 6 Apr 2022 17:45:27 +0100 Message-Id: <20220406164546.1888528-24-james.morse@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220406164546.1888528-1-james.morse@arm.com> References: <0220406164217.1888053-1-james.morse@arm.com> <20220406164546.1888528-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suzuki K Poulose commit 8c2dcbd2c4443bad0b4242fb62baa47b260b8f79 upstream. Add a helper to extract the register field from a given instruction. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Reviewed-by: Catalin Marinas Signed-off-by: Suzuki K Poulose Signed-off-by: Will Deacon Signed-off-by: James Morse --- arch/arm64/include/asm/insn.h | 2 ++ arch/arm64/kernel/insn.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h index bc853663dd51..aecc07e09a18 100644 --- a/arch/arm64/include/asm/insn.h +++ b/arch/arm64/include/asm/insn.h @@ -332,6 +332,8 @@ bool aarch64_insn_is_branch(u32 insn); u64 aarch64_insn_decode_immediate(enum aarch64_insn_imm_type type, u32 insn); u32 aarch64_insn_encode_immediate(enum aarch64_insn_imm_type type, u32 insn, u64 imm); +u32 aarch64_insn_decode_register(enum aarch64_insn_register_type type, + u32 insn); u32 aarch64_insn_gen_branch_imm(unsigned long pc, unsigned long addr, enum aarch64_insn_branch_type type); u32 aarch64_insn_gen_comp_branch_imm(unsigned long pc, unsigned long addr, diff --git a/arch/arm64/kernel/insn.c b/arch/arm64/kernel/insn.c index 6f2ac4fc66ca..755b3dd3073e 100644 --- a/arch/arm64/kernel/insn.c +++ b/arch/arm64/kernel/insn.c @@ -418,6 +418,35 @@ u32 __kprobes aarch64_insn_encode_immediate(enum aarch64_insn_imm_type type, return insn; } +u32 aarch64_insn_decode_register(enum aarch64_insn_register_type type, + u32 insn) +{ + int shift; + + switch (type) { + case AARCH64_INSN_REGTYPE_RT: + case AARCH64_INSN_REGTYPE_RD: + shift = 0; + break; + case AARCH64_INSN_REGTYPE_RN: + shift = 5; + break; + case AARCH64_INSN_REGTYPE_RT2: + case AARCH64_INSN_REGTYPE_RA: + shift = 10; + break; + case AARCH64_INSN_REGTYPE_RM: + shift = 16; + break; + default: + pr_err("%s: unknown register type encoding %d\n", __func__, + type); + return 0; + } + + return (insn >> shift) & GENMASK(4, 0); +} + static u32 aarch64_insn_encode_register(enum aarch64_insn_register_type type, u32 insn, enum aarch64_insn_register reg) -- 2.30.2