From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: add macro to perform far branches (b/bl)
Date: Thu, 19 Mar 2015 10:01:29 +0100 [thread overview]
Message-ID: <1426755689-24220-1-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <CAKv+Gu9cU_cgD4AgndKKiFsCjkUyB9MKyP3kieZAY7y4t9kofw@mail.gmail.com>
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 <nico@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
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}
--
1.8.3.2
next prev parent reply other threads:[~2015-03-19 9:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 12:07 [PATCH v2 0/8] ARM kernel size fixes Ard Biesheuvel
2015-03-13 12:07 ` [PATCH v2 1/8] ARM: replace PROCINFO embedded branch with relative offset Ard Biesheuvel
2015-04-19 16:59 ` Joachim Eastwood
2015-04-19 17:08 ` Russell King - ARM Linux
2015-04-19 17:41 ` Ard Biesheuvel
2015-04-19 19:28 ` Russell King - ARM Linux
2015-04-19 19:45 ` Joachim Eastwood
2015-04-19 21:52 ` Ard Biesheuvel
2015-04-19 19:24 ` Joachim Eastwood
2015-03-13 12:07 ` [PATCH v2 2/8] ARM: move HYP text to end of .text section Ard Biesheuvel
2015-03-13 12:07 ` [PATCH v2 3/8] ARM: add macro to perform far branches (b/bl) Ard Biesheuvel
2015-03-13 16:40 ` Russell King - ARM Linux
2015-03-17 20:35 ` Ard Biesheuvel
2015-03-18 10:07 ` Ard Biesheuvel
2015-03-19 9:01 ` Ard Biesheuvel [this message]
2015-03-13 12:07 ` [PATCH v2 4/8] ARM: use bl_far to call __hyp_stub_install_secondary from the .data section Ard Biesheuvel
2015-03-13 12:07 ` [PATCH v2 5/8] ARM: move the .idmap.text section closer to .head.text Ard Biesheuvel
2015-03-13 12:07 ` [PATCH v2 6/8] asm-generic: introduce .text.fixup input section Ard Biesheuvel
2015-03-18 18:58 ` Arnd Bergmann
2015-03-13 12:07 ` [PATCH v2 7/8] ARM: keep .text and .fixup regions together Ard Biesheuvel
2015-03-13 12:07 ` [PATCH v2 8/8] kallsyms: allow kallsyms data to reside in the .data section Ard Biesheuvel
2015-03-18 7:54 ` [PATCH v2 0/8] ARM kernel size fixes Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426755689-24220-1-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).