From patchwork Thu Mar 19 09:01:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46017 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 96C6621515 for ; Thu, 19 Mar 2015 09:04:05 +0000 (UTC) Received: by lams18 with SMTP id s18sf11424416lam.2 for ; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=qVuhUCsTX3hAfuR6Q8UoYgGJ+U5D4W8WWHbBKyRyTws=; b=JDnTkIN5ysDeGqQeYQ0IFxIbonHnU+RxjSinyEfF5d8Z84Lr0qL2kEKUGdb0JaYleg bXoNFxKOvPklasP6e9hGTBALYma2uM0w0wkNXaMW4qFZG0c50umH2lYiISv/aomVZgY8 rS2GptanwlLNfcZv3udF2i1RL0Q+2J2iDS1U1ggd0r6cypFQ2S2SE36tcEIeH3rkoPi1 rKmdfhX1o3oEcqck+g5lQeE477eyDuSrUMFNIYuietqdsqeaB5nYogktiRrcCt/uhneI eR9eFNjwk/i1yPJSH/6OkItEy9ZRkMfs324c+9AOECnVIK7FhSIx2KcNby9sQfZRpRU6 j9Eg== X-Gm-Message-State: ALoCoQm18Y9bFpCoEJXX13wBoePjSadO38tGmuyM7u9NYWj7ag6dDWGfrJF7LZszsL7P2BXf9cxw X-Received: by 10.152.19.67 with SMTP id c3mr10553415lae.7.1426755844598; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.106 with SMTP id w10ls271076laz.62.gmail; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) X-Received: by 10.112.219.135 with SMTP id po7mr66947803lbc.111.1426755844450; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id yd8si475597lbb.144.2015.03.19.02.04.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 02:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbcgn8 with SMTP id gn8so47841445lbc.2 for ; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr49017138lbc.36.1426755844324; Thu, 19 Mar 2015 02:04:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp249183lbj; Thu, 19 Mar 2015 02:04:03 -0700 (PDT) X-Received: by 10.66.235.169 with SMTP id un9mr168656157pac.45.1426755842167; Thu, 19 Mar 2015 02:04:02 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id d17si1463676pdf.186.2015.03.19.02.04.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 02:04:02 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YYWL5-0000qZ-MZ; Thu, 19 Mar 2015 09:02:03 +0000 Received: from mail-we0-f179.google.com ([74.125.82.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YYWL1-0000ly-9c for linux-arm-kernel@lists.infradead.org; Thu, 19 Mar 2015 09:02:00 +0000 Received: by wegp1 with SMTP id p1so51722179weg.1 for ; Thu, 19 Mar 2015 02:01:34 -0700 (PDT) X-Received: by 10.180.20.43 with SMTP id k11mr14056321wie.93.1426755694904; Thu, 19 Mar 2015 02:01:34 -0700 (PDT) Received: from ards-macbook-pro.local (62.82.106.185.static.user.ono.com. [62.82.106.185]) by mx.google.com with ESMTPSA id ps4sm1042279wjc.31.2015.03.19.02.01.33 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 02:01:34 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, nico@linaro.org Subject: [PATCH] ARM: add macro to perform far branches (b/bl) Date: Thu, 19 Mar 2015 10:01:29 +0100 Message-Id: <1426755689-24220-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150319_020159_530120_2F1D81BF X-CRM114-Status: GOOD ( 13.93 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.179 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.179 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 OK, so this is what I came up with in the end. I dropped b_abs/bl_abs as they are not needed anymore, now that b_far/bl_far are emitted without any explicit or implicit literals. I updated the ARCH check so that movw/movt/ really only gets used on v7 targeted builds. I also updated the v7 variant to use bx instead of adding with the PC as destination register, as this is deprecated by the ARM ARM. --------------------8<----------------------- These macros execute PC-relative branches, but with a larger reach than the 24 bits that are available in the b and bl opcodes. Acked-by: Nicolas Pitre Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/assembler.h | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index f67fd3afebdf..1b9a630f93e0 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -88,6 +88,17 @@ #endif /* + * The program counter is always ahead of the address of the currently + * executing instruction by PC_BIAS bytes, whose value differs depending + * on the execution mode. + */ +#ifdef CONFIG_THUMB2_KERNEL +#define PC_BIAS 4 +#else +#define PC_BIAS 8 +#endif + +/* * Enable and disable interrupts */ #if __LINUX_ARM_ARCH__ >= 6 @@ -108,6 +119,39 @@ .endm #endif + /* + * Macros to emit relative conditional branches that may exceed the + * range of the 24-bit immediate of the ordinary b/bl instructions. + * NOTE: this doesn't work with locally defined symbols, as they + * lack the ARM/Thumb annotation (even if they are annotated as + * functions) + */ + .macro b_far, target, r, c=, b=bx +#if __LINUX_ARM_ARCH__ >= 7 + movt\c \r, #:upper16:(\target - (8888f + PC_BIAS)) + movw\c \r, #:lower16:(\target - (8888f + PC_BIAS)) +8888: add\c \r, \r, pc + \b\c \r +#else + /* + * Compute the PC-relative offset of \target. We need to correct for + * the bias when reading the PC at label 8888, and for the offset + * between the place of the read and the place of the relocation. + */ +8888: add\c \r, pc, #:pc_g0_nc:(\target - PC_BIAS + (. - 8888b)) + add\c \r, \r, #:pc_g1_nc:(\target - PC_BIAS + (. - 8888b)) + add\c pc, \r, #:pc_g2:(\target - PC_BIAS + (. - 8888b)) +#endif + .endm + + .macro bl_far, target, c= +#if __LINUX_ARM_ARCH__ < 7 + adr\c lr, 8887f +#endif + b_far \target, ip, \c, blx +8887: + .endm + .macro asm_trace_hardirqs_off #if defined(CONFIG_TRACE_IRQFLAGS) stmdb sp!, {r0-r3, ip, lr}