diff options
author | Paul Mackerras <paulus@samba.org> | 2008-08-29 21:43:47 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-09-15 14:08:38 -0400 |
commit | 549e8152de8039506f69c677a4546e5427aa6ae7 (patch) | |
tree | e03a4f46143a23045e456f96fc08beba12e73073 /arch/powerpc/include | |
parent | e31aa453bbc4886a7bd33e5c2afa526d6f55bd7a (diff) |
powerpc: Make the 64-bit kernel as a position-independent executable
This implements CONFIG_RELOCATABLE for 64-bit by making the kernel as
a position-independent executable (PIE) when it is set. This involves
processing the dynamic relocations in the image in the early stages of
booting, even if the kernel is being run at the address it is linked at,
since the linker does not necessarily fill in words in the image for
which there are dynamic relocations. (In fact the linker does fill in
such words for 64-bit executables, though not for 32-bit executables,
so in principle we could avoid calling relocate() entirely when we're
running a 64-bit kernel at the linked address.)
The dynamic relocations are processed by a new function relocate(addr),
where the addr parameter is the virtual address where the image will be
run. In fact we call it twice; once before calling prom_init, and again
when starting the main kernel. This means that reloc_offset() returns
0 in prom_init (since it has been relocated to the address it is running
at), which necessitated a few adjustments.
This also changes __va and __pa to use an equivalent definition that is
simpler. With the relocatable kernel, PAGE_OFFSET and MEMORY_START are
constants (for 64-bit) whereas PHYSICAL_START is a variable (and
KERNELBASE ideally should be too, but isn't yet).
With this, relocatable kernels still copy themselves down to physical
address 0 and run there.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/include')
-rw-r--r-- | arch/powerpc/include/asm/mmu-hash64.h | 2 | ||||
-rw-r--r-- | arch/powerpc/include/asm/page.h | 14 | ||||
-rw-r--r-- | arch/powerpc/include/asm/sections.h | 6 |
3 files changed, 17 insertions, 5 deletions
diff --git a/arch/powerpc/include/asm/mmu-hash64.h b/arch/powerpc/include/asm/mmu-hash64.h index c2df53c5ceb9..5a441742ffba 100644 --- a/arch/powerpc/include/asm/mmu-hash64.h +++ b/arch/powerpc/include/asm/mmu-hash64.h | |||
@@ -437,7 +437,7 @@ typedef struct { | |||
437 | }) | 437 | }) |
438 | #endif /* 1 */ | 438 | #endif /* 1 */ |
439 | 439 | ||
440 | /* This is only valid for addresses >= KERNELBASE */ | 440 | /* This is only valid for addresses >= PAGE_OFFSET */ |
441 | static inline unsigned long get_kernel_vsid(unsigned long ea, int ssize) | 441 | static inline unsigned long get_kernel_vsid(unsigned long ea, int ssize) |
442 | { | 442 | { |
443 | if (ssize == MMU_SEGSIZE_256M) | 443 | if (ssize == MMU_SEGSIZE_256M) |
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index e088545cb3f5..64e144505f65 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h | |||
@@ -71,15 +71,21 @@ | |||
71 | #define PAGE_OFFSET ASM_CONST(CONFIG_PAGE_OFFSET) | 71 | #define PAGE_OFFSET ASM_CONST(CONFIG_PAGE_OFFSET) |
72 | #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START)) | 72 | #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START)) |
73 | 73 | ||
74 | #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_FLATMEM) | 74 | #if defined(CONFIG_RELOCATABLE) |
75 | #ifndef __ASSEMBLY__ | 75 | #ifndef __ASSEMBLY__ |
76 | extern phys_addr_t memstart_addr; | 76 | extern phys_addr_t memstart_addr; |
77 | extern phys_addr_t kernstart_addr; | 77 | extern phys_addr_t kernstart_addr; |
78 | #endif | 78 | #endif |
79 | #define PHYSICAL_START kernstart_addr | 79 | #define PHYSICAL_START kernstart_addr |
80 | #define MEMORY_START memstart_addr | ||
81 | #else | 80 | #else |
82 | #define PHYSICAL_START ASM_CONST(CONFIG_PHYSICAL_START) | 81 | #define PHYSICAL_START ASM_CONST(CONFIG_PHYSICAL_START) |
82 | #endif | ||
83 | |||
84 | #ifdef CONFIG_PPC64 | ||
85 | #define MEMORY_START 0UL | ||
86 | #elif defined(CONFIG_RELOCATABLE) | ||
87 | #define MEMORY_START memstart_addr | ||
88 | #else | ||
83 | #define MEMORY_START (PHYSICAL_START + PAGE_OFFSET - KERNELBASE) | 89 | #define MEMORY_START (PHYSICAL_START + PAGE_OFFSET - KERNELBASE) |
84 | #endif | 90 | #endif |
85 | 91 | ||
@@ -92,8 +98,8 @@ extern phys_addr_t kernstart_addr; | |||
92 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) | 98 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
93 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) | 99 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
94 | 100 | ||
95 | #define __va(x) ((void *)((unsigned long)(x) - PHYSICAL_START + KERNELBASE)) | 101 | #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - MEMORY_START)) |
96 | #define __pa(x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE) | 102 | #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START) |
97 | 103 | ||
98 | /* | 104 | /* |
99 | * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, | 105 | * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, |
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h index 7710e9e6660f..baf318aec533 100644 --- a/arch/powerpc/include/asm/sections.h +++ b/arch/powerpc/include/asm/sections.h | |||
@@ -16,6 +16,12 @@ static inline int in_kernel_text(unsigned long addr) | |||
16 | return 0; | 16 | return 0; |
17 | } | 17 | } |
18 | 18 | ||
19 | static inline int overlaps_kernel_text(unsigned long start, unsigned long end) | ||
20 | { | ||
21 | return start < (unsigned long)__init_end && | ||
22 | (unsigned long)_stext < end; | ||
23 | } | ||
24 | |||
19 | #undef dereference_function_descriptor | 25 | #undef dereference_function_descriptor |
20 | void *dereference_function_descriptor(void *); | 26 | void *dereference_function_descriptor(void *); |
21 | 27 | ||