From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 1/3] arm64: head.S: replace early literals with constant immediates
Date: Mon, 16 Mar 2015 16:23:41 +0100 [thread overview]
Message-ID: <1426519423-28263-2-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1426519423-28263-1-git-send-email-ard.biesheuvel@linaro.org>
In preparation of making the kernel relocatable, replace literal
symbol references with immediate constants. This is necessary, as
the literals will not be populated with meaningful values until
after the relocation code has executed.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/arm64/kernel/efi-entry.S | 2 +-
arch/arm64/kernel/head.S | 36 +++++++++++++++---------------------
2 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S
index 8ce9b0577442..f78e6a1de825 100644
--- a/arch/arm64/kernel/efi-entry.S
+++ b/arch/arm64/kernel/efi-entry.S
@@ -61,7 +61,7 @@ ENTRY(efi_stub_entry)
*/
mov x20, x0 // DTB address
ldr x0, [sp, #16] // relocated _text address
- ldr x21, =stext_offset
+ movz x21, #:abs_g0:stext_offset
add x21, x0, x21
/*
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 9c856f2aa7a5..1ea3cd2aba34 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -46,11 +46,9 @@
#error TEXT_OFFSET must be less than 2MB
#endif
- .macro pgtbl, ttb0, ttb1, virt_to_phys
- ldr \ttb1, =swapper_pg_dir
- ldr \ttb0, =idmap_pg_dir
- add \ttb1, \ttb1, \virt_to_phys
- add \ttb0, \ttb0, \virt_to_phys
+ .macro pgtbl, ttb0, ttb1
+ adrp \ttb1, swapper_pg_dir
+ adrp \ttb0, idmap_pg_dir
.endm
#ifdef CONFIG_ARM64_64K_PAGES
@@ -63,7 +61,7 @@
#define TABLE_SHIFT PUD_SHIFT
#endif
-#define KERNEL_START KERNEL_RAM_VADDR
+#define KERNEL_START _text
#define KERNEL_END _end
/*
@@ -322,7 +320,7 @@ ENDPROC(stext)
* been enabled
*/
__create_page_tables:
- pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses
+ pgtbl x25, x26 // idmap_pg_dir and swapper_pg_dir addresses
mov x27, lr
/*
@@ -351,8 +349,7 @@ __create_page_tables:
* Create the identity mapping.
*/
mov x0, x25 // idmap_pg_dir
- ldr x3, =KERNEL_START
- add x3, x3, x28 // __pa(KERNEL_START)
+ adr_l x3, KERNEL_START // __pa(KERNEL_START)
#ifndef CONFIG_ARM64_VA_BITS_48
#define EXTRA_SHIFT (PGDIR_SHIFT + PAGE_SHIFT - 3)
@@ -391,9 +388,8 @@ __create_page_tables:
#endif
create_pgd_entry x0, x3, x5, x6
- ldr x6, =KERNEL_END
mov x5, x3 // __pa(KERNEL_START)
- add x6, x6, x28 // __pa(KERNEL_END)
+ adr_l x6, KERNEL_END // __pa(KERNEL_END)
create_block_map x0, x7, x3, x5, x6
/*
@@ -402,8 +398,10 @@ __create_page_tables:
mov x0, x26 // swapper_pg_dir
mov x5, #PAGE_OFFSET
create_pgd_entry x0, x5, x3, x6
- ldr x6, =KERNEL_END
+ adr_l x6, KERNEL_END
mov x3, x24 // phys offset
+ sub x6, x6, x3 // kernel memsize
+ add x6, x6, x5 // __va(KERNEL_END)
create_block_map x0, x7, x3, x5, x6
/*
@@ -538,8 +536,7 @@ ENDPROC(el2_setup)
* in x20. See arch/arm64/include/asm/virt.h for more info.
*/
ENTRY(set_cpu_boot_mode_flag)
- ldr x1, =__boot_cpu_mode // Compute __boot_cpu_mode
- add x1, x1, x28
+ adr_l x1, __boot_cpu_mode // Compute __boot_cpu_mode
cmp w20, #BOOT_CPU_MODE_EL2
b.ne 1f
add x1, x1, #4
@@ -598,7 +595,7 @@ ENTRY(secondary_startup)
/*
* Common entry point for secondary CPUs.
*/
- pgtbl x25, x26, x28 // x25=TTBR0, x26=TTBR1
+ pgtbl x25, x26 // x25=TTBR0, x26=TTBR1
bl __cpu_setup // initialise processor
ldr x21, =secondary_data
@@ -655,17 +652,14 @@ ENDPROC(__turn_mmu_on)
* Calculate the start of physical memory.
*/
__calc_phys_offset:
- adr x0, 1f
- ldp x1, x2, [x0]
+ adrp x0, KERNEL_START // __pa(KERNEL_START)
+ ldr x1, =KERNEL_RAM_VADDR // __va(KERNEL_START)
+ mov x2, PAGE_OFFSET
sub x28, x0, x1 // x28 = PHYS_OFFSET - PAGE_OFFSET
add x24, x2, x28 // x24 = PHYS_OFFSET
ret
ENDPROC(__calc_phys_offset)
- .align 3
-1: .quad .
- .quad PAGE_OFFSET
-
/*
* Exception handling. Something went wrong and we can't proceed. We ought to
* tell the user, but since we don't have any guarantee that we're even
--
1.8.3.2
next prev parent reply other threads:[~2015-03-16 15:23 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-16 15:23 [RFC PATCH 0/3] arm64: relocatable kernel proof of concept Ard Biesheuvel
2015-03-16 15:23 ` Ard Biesheuvel [this message]
2015-03-16 17:14 ` [RFC PATCH 1/3] arm64: head.S: replace early literals with constant immediates Mark Rutland
2015-03-17 7:01 ` Ard Biesheuvel
2015-03-16 15:23 ` [RFC PATCH 2/3] arm64: add support for relocatable kernel Ard Biesheuvel
2015-03-16 15:23 ` [RFC PATCH 3/3] arm64/efi: use relocated kernel Ard Biesheuvel
2015-03-16 16:09 ` [RFC PATCH 0/3] arm64: relocatable kernel proof of concept Mark Rutland
2015-03-16 16:45 ` Ard Biesheuvel
2015-03-16 17:33 ` Mark Rutland
2015-03-16 17:43 ` Ard Biesheuvel
2015-03-17 16:20 ` Mark Rutland
2015-03-16 23:19 ` Kees Cook
2015-03-17 7:38 ` Ard Biesheuvel
2015-03-17 16:35 ` Mark Rutland
2015-03-17 16:40 ` Ard Biesheuvel
2015-03-17 16:43 ` Mark Rutland
2015-03-23 15:36 ` [PATCH 0/4] RFC: split text and linear mappings using tagged pointers Ard Biesheuvel
2015-03-23 15:36 ` [PATCH 1/4] arm64: use tagged pointers to distinguish kernel text from the linear mapping Ard Biesheuvel
2015-03-25 14:04 ` Catalin Marinas
2015-03-26 1:27 ` Mark Rutland
2015-03-23 15:36 ` [PATCH 2/4] arm64: fixmap: move translation tables to dedicated region Ard Biesheuvel
2015-03-26 1:28 ` Mark Rutland
2015-03-26 6:20 ` Ard Biesheuvel
2015-03-30 14:34 ` Mark Rutland
2015-03-23 15:36 ` [PATCH 3/4] arm64: move kernel text below PAGE_OFFSET Ard Biesheuvel
2015-03-25 14:10 ` Catalin Marinas
2015-03-23 15:36 ` [PATCH 4/4] arm64: align PHYS_OFFSET to block size Ard Biesheuvel
2015-03-25 14:14 ` Catalin Marinas
2015-03-26 6:23 ` Ard Biesheuvel
2015-03-25 14:59 ` Catalin Marinas
2015-03-26 6:22 ` Ard Biesheuvel
2015-03-27 13:16 ` Ard Biesheuvel
2015-03-30 13:49 ` Catalin Marinas
2015-03-30 14:00 ` Ard Biesheuvel
2015-03-30 14:55 ` Mark Rutland
2015-03-30 15:00 ` Catalin Marinas
2015-03-30 18:08 ` Ard Biesheuvel
2015-03-31 14:49 ` Catalin Marinas
2015-03-31 16:19 ` Catalin Marinas
2015-03-31 16:46 ` Catalin Marinas
2015-03-26 1:26 ` [PATCH 0/4] RFC: split text and linear mappings using tagged pointers Mark Rutland
2015-03-26 6:09 ` 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=1426519423-28263-2-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).