From patchwork Wed Oct 9 14:29:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 3009181 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 760DABF924 for ; Wed, 9 Oct 2013 14:32:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37D7620240 for ; Wed, 9 Oct 2013 14:32:42 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5A9E200F7 for ; Wed, 9 Oct 2013 14:32:40 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTunL-0005XK-UI; Wed, 09 Oct 2013 14:31:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTumx-0004vP-MG; Wed, 09 Oct 2013 14:30:59 +0000 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21] helo=cam-smtp0.cambridge.arm.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VTumN-0004qR-Ga for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2013 14:30:25 +0000 Received: from e103592.cambridge.arm.com (e103592.cambridge.arm.com [10.1.203.33]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id r99ETrZn001453; Wed, 9 Oct 2013 15:29:54 +0100 From: Dave Martin To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 2/4] ARM: Add common compile-time swab32 for asm code Date: Wed, 9 Oct 2013 15:29:51 +0100 Message-Id: <1381328993-12724-3-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1381328993-12724-1-git-send-email-Dave.Martin@arm.com> References: <1381328993-12724-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131009_103023_874246_20AD7DC0 X-CRM114-Status: GOOD ( 12.62 ) X-Spam-Score: -2.8 (--) Cc: Nicolas Pitre , Lorenzo Pieralisi , Ben Dooks , Victor Kamensky X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP doesn't work for asm code, yet swabbing constants for asm is still useful, such as when writing code which needs to build with different target endiannesses. This patch adds a simple asm_swab32() macro so that this operation doesn't need to be reinvented repeatedly. Since already defines this operation, this patch lifts the definition into assembler.h and makes opcodes.h use it. The other swab variants defined by opcodes.h could be transferred too, but there is no clear need for that yet. Signed-off-by: Dave Martin --- arch/arm/include/asm/assembler.h | 23 +++++++++++++++++++++++ arch/arm/include/asm/opcodes.h | 9 +++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index a71d117..860256c 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -380,4 +380,27 @@ THUMB( orr \reg , \reg , #PSR_T_BIT ) #endif /* __ASSEMBLY__ */ +/* + * Use asm_swab32() only for compile-time swabbing of constants for + * assembly code. in inline asm, the argument is a string + * representation of an expression which will be passed through to the + * assembler, so it can't contain embedded C expressions or preprocessor + * macros. Macros would need to be pre-expanded using __stringify(). + */ +#ifdef __ASSEMBLY__ +#define __asm_swab32(x) ( \ + (((x) >> 24) & 0x000000ff) \ + | (((x) >> 8) & 0x0000ff00) \ + | (((x) << 8) & 0x00ff0000) \ + | (((x) << 24) & 0xff000000) \ +) +#else /* ! __ASSEMBLY__ */ +#define __asm_swab32(x) "( " \ + "(((" x ") >> 24) & 0x000000ff) " \ + "| (((" x ") >> 8) & 0x0000ff00) " \ + "| (((" x ") << 8) & 0x00ff0000) " \ + "| (((" x ") << 24) & 0xff000000) " \ +")" +#endif /* ! __ASSEMBLY__ */ + #endif /* __ASM_ASSEMBLER_H__ */ diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h index e796c59..b2e93c9 100644 --- a/arch/arm/include/asm/opcodes.h +++ b/arch/arm/include/asm/opcodes.h @@ -9,6 +9,8 @@ #ifndef __ASM_ARM_OPCODES_H #define __ASM_ARM_OPCODES_H +#include + #ifndef __ASSEMBLY__ #include extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); @@ -24,12 +26,7 @@ extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr); * These are only intended for use by this header: don't use them directly, * because they will be suboptimal in most cases. */ -#define ___asm_opcode_swab32(x) ( \ - (((x) << 24) & 0xFF000000) \ - | (((x) << 8) & 0x00FF0000) \ - | (((x) >> 8) & 0x0000FF00) \ - | (((x) >> 24) & 0x000000FF) \ -) +#define ___asm_opcode_swab32(x) __asm_swab32(x) #define ___asm_opcode_swab16(x) ( \ (((x) << 8) & 0xFF00) \ | (((x) >> 8) & 0x00FF) \