blob: 548d9a411a0d6dcbe3f0b8d2890c7d08dc68a7f9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ELF register definitions..
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
David Howellsc3617f72012-10-09 09:47:26 +01009#ifndef _ASM_POWERPC_ELF_H
10#define _ASM_POWERPC_ELF_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
David Howellsc3617f72012-10-09 09:47:26 +010012#include <linux/sched.h> /* for task_struct */
13#include <asm/page.h>
14#include <asm/string.h>
15#include <uapi/asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
18 * This is used to ensure we don't load something for the wrong architecture.
19 */
20#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
Roland McGrath01e31db2008-01-02 17:03:11 -080021#define compat_elf_check_arch(x) ((x)->e_machine == EM_PPC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Roland McGrath81970382007-12-20 03:58:12 -080023#define CORE_DUMP_USE_REGSET
Olof Johansson637a6ff2005-09-20 13:47:41 +100024#define ELF_EXEC_PAGESIZE PAGE_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Kees Cook47ebb092017-07-10 15:52:47 -070026/*
27 * This is the base location for PIE (ET_DYN with INTERP) loads. On
28 * 64-bit, this is raised to 4GB to leave the entire 32-bit address
29 * space open for things that want to use the area for 32-bit pointers.
30 */
31#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \
32 0x100000000UL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Rusty Russell918d0352013-11-20 22:15:01 +110034#define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
35
Roland McGrath5f149cf2007-10-16 23:26:55 -070036/*
37 * Our registers are always unsigned longs, whether we're a 32 bit
38 * process or 64 bit, on either a 64 bit or 32 bit kernel.
39 *
40 * This macro relies on elf_regs[i] having the right type to truncate to,
41 * either u32 or u64. It defines the body of the elf_core_copy_regs
42 * function, either the native one with elf_gregset_t elf_regs or
43 * the 32-bit one with elf_gregset_t32 elf_regs.
44 */
45#define PPC_ELF_CORE_COPY_REGS(elf_regs, regs) \
46 int i, nregs = min(sizeof(*regs) / sizeof(unsigned long), \
47 (size_t)ELF_NGREG); \
48 for (i = 0; i < nregs; i++) \
49 elf_regs[i] = ((unsigned long *) regs)[i]; \
50 memset(&elf_regs[i], 0, (ELF_NGREG - i) * sizeof(elf_regs[0]))
51
52/* Common routine for both 32-bit and 64-bit native processes */
Becky Brucea99eb2e2005-09-19 19:17:27 -050053static inline void ppc_elf_core_copy_regs(elf_gregset_t elf_regs,
Roland McGrath5f149cf2007-10-16 23:26:55 -070054 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Roland McGrath5f149cf2007-10-16 23:26:55 -070056 PPC_ELF_CORE_COPY_REGS(elf_regs, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
Becky Brucea99eb2e2005-09-19 19:17:27 -050058#define ELF_CORE_COPY_REGS(gregs, regs) ppc_elf_core_copy_regs(gregs, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Mark Nelson1f7d6662007-10-16 23:25:40 -070060typedef elf_vrregset_t elf_fpxregset_t;
61
Becky Brucea99eb2e2005-09-19 19:17:27 -050062/* ELF_HWCAP yields a mask that user programs can use to figure out what
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 instruction set this cpu supports. This could be done in userspace,
64 but it's not easy, and we've already done it here. */
Becky Brucea99eb2e2005-09-19 19:17:27 -050065# define ELF_HWCAP (cur_cpu_spec->cpu_user_features)
Michael Neuling21713642013-04-17 17:33:11 +000066# define ELF_HWCAP2 (cur_cpu_spec->cpu_user_features2)
Paul Mackerras80f15dc2006-01-14 10:11:39 +110067
68/* This yields a string that ld.so will use to load implementation
69 specific libraries for optimization. This is more specific in
70 intent than poking at uname or /proc/cpuinfo. */
71
72#define ELF_PLATFORM (cur_cpu_spec->platform)
73
Nathan Lynch9115d132008-07-16 09:58:51 +100074/* While ELF_PLATFORM indicates the ISA supported by the platform, it
75 * may not accurately reflect the underlying behavior of the hardware
76 * (as in the case of running in Power5+ compatibility mode on a
77 * Power6 machine). ELF_BASE_PLATFORM allows ld.so to load libraries
78 * that are tuned for the real hardware.
79 */
80#define ELF_BASE_PLATFORM (powerpc_base_platform)
81
Kumar Gala400d2212005-09-27 15:13:12 -050082#ifdef __powerpc64__
Paul Mackerras06d67d52005-10-10 22:29:05 +100083# define ELF_PLAT_INIT(_r, load_addr) do { \
84 _r->gpr[2] = load_addr; \
Becky Brucea99eb2e2005-09-19 19:17:27 -050085} while (0)
Becky Brucea99eb2e2005-09-19 19:17:27 -050086#endif /* __powerpc64__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Becky Brucea99eb2e2005-09-19 19:17:27 -050088#ifdef __powerpc64__
Martin Schwidefsky0b592682008-10-16 15:39:57 +020089# define SET_PERSONALITY(ex) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070090do { \
Rusty Russell373c76d2013-11-20 22:15:00 +110091 if (((ex).e_flags & 0x3) == 2) \
92 set_thread_flag(TIF_ELF2ABI); \
Jeff Bailey1efc5632014-05-17 15:05:43 +000093 else \
94 clear_thread_flag(TIF_ELF2ABI); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
Andreas Schwab94f28da2010-01-30 10:20:59 +000096 set_thread_flag(TIF_32BIT); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 else \
Andreas Schwab94f28da2010-01-30 10:20:59 +000098 clear_thread_flag(TIF_32BIT); \
Paul Mackerrasce10d972005-06-08 21:59:15 +100099 if (personality(current->personality) != PER_LINUX32) \
Eric B Munsona91a03e2008-07-01 02:12:13 +1000100 set_personality(PER_LINUX | \
101 (current->personality & (~PER_MASK))); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*
104 * An executable for which elf_read_implies_exec() returns TRUE will
Anton Blancharda2f95a52005-05-01 08:58:45 -0700105 * have the READ_IMPLIES_EXEC personality flag set automatically. This
106 * is only required to work around bugs in old 32bit toolchains. Since
107 * the 64bit ABI has never had these issues dont enable the workaround
108 * even if we have an executable stack.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
Denis Kirjanovcab175f2010-08-27 03:49:11 +0000110# define elf_read_implies_exec(ex, exec_stk) (is_32bit_task() ? \
Kumar Galad89ebca2009-04-28 03:32:36 +0000111 (exec_stk == EXSTACK_DEFAULT) : 0)
Becky Brucea99eb2e2005-09-19 19:17:27 -0500112#else
Kumar Galad89ebca2009-04-28 03:32:36 +0000113# define elf_read_implies_exec(ex, exec_stk) (exec_stk == EXSTACK_DEFAULT)
Becky Brucea99eb2e2005-09-19 19:17:27 -0500114#endif /* __powerpc64__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116extern int dcache_bsize;
117extern int icache_bsize;
118extern int ucache_bsize;
119
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +1100120/* vDSO has arch_setup_additional_pages */
121#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122struct linux_binprm;
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +1100123extern int arch_setup_additional_pages(struct linux_binprm *bprm,
Martin Schwidefskyfc5243d2008-12-25 13:38:35 +0100124 int uses_interp);
Phil Carmody497888c2011-07-14 15:07:13 +0300125#define VDSO_AUX_ENT(a,b) NEW_AUX_ENT(a,b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Anton Blanchard2dadb982009-02-22 01:50:02 +0000127/* 1GB for 64bit, 8MB for 32bit */
128#define STACK_RND_MASK (is_32bit_task() ? \
129 (0x7ff >> (PAGE_SHIFT - 12)) : \
130 (0x3ffff >> (PAGE_SHIFT - 12)))
131
Arnd Bergmanne0555952006-11-27 19:18:55 +0100132#ifdef CONFIG_SPU_BASE
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100133/* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
134#define NT_SPU 1
135
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100136#define ARCH_HAVE_EXTRA_ELF_NOTES
Michael Ellermane5501492007-09-19 14:38:12 +1000137
138#endif /* CONFIG_SPU_BASE */
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100139
Benjamin Herrenschmidt98a5f362017-02-03 17:20:07 +1100140#ifdef CONFIG_PPC64
141
142#define get_cache_geometry(level) \
143 (ppc64_caches.level.assoc << 16 | ppc64_caches.level.line_size)
144
145#define ARCH_DLINFO_CACHE_GEOMETRY \
146 NEW_AUX_ENT(AT_L1I_CACHESIZE, ppc64_caches.l1i.size); \
147 NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, get_cache_geometry(l1i)); \
Michael Ellerman9c7a0082017-03-06 21:51:32 +1100148 NEW_AUX_ENT(AT_L1D_CACHESIZE, ppc64_caches.l1d.size); \
149 NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, get_cache_geometry(l1d)); \
Benjamin Herrenschmidt98a5f362017-02-03 17:20:07 +1100150 NEW_AUX_ENT(AT_L2_CACHESIZE, ppc64_caches.l2.size); \
151 NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, get_cache_geometry(l2)); \
152 NEW_AUX_ENT(AT_L3_CACHESIZE, ppc64_caches.l3.size); \
153 NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, get_cache_geometry(l3))
154
155#else
156#define ARCH_DLINFO_CACHE_GEOMETRY
157#endif
158
Benjamin Herrenschmidt2a196e22017-01-08 17:31:42 -0600159/*
160 * The requirements here are:
161 * - keep the final alignment of sp (sp & 0xf)
162 * - make sure the 32-bit value at the first 16 byte aligned position of
163 * AUXV is greater than 16 for glibc compatibility.
164 * AT_IGNOREPPC is used for that.
165 * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
166 * even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
167 * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes
168 */
169#define ARCH_DLINFO \
170do { \
171 /* Handle glibc compatibility. */ \
172 NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
173 NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
174 /* Cache size items */ \
175 NEW_AUX_ENT(AT_DCACHEBSIZE, dcache_bsize); \
176 NEW_AUX_ENT(AT_ICACHEBSIZE, icache_bsize); \
177 NEW_AUX_ENT(AT_UCACHEBSIZE, ucache_bsize); \
178 VDSO_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso_base); \
Benjamin Herrenschmidt98a5f362017-02-03 17:20:07 +1100179 ARCH_DLINFO_CACHE_GEOMETRY; \
Benjamin Herrenschmidt2a196e22017-01-08 17:31:42 -0600180} while (0)
181
Becky Brucea99eb2e2005-09-19 19:17:27 -0500182#endif /* _ASM_POWERPC_ELF_H */