1#ifndef __PPC64_ELF_H
2#define __PPC64_ELF_H
3
4/*
5 * ELF register definitions..
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12#include <asm/ptrace.h>
13
14#define ELF_NGREG	48	/* includes nip, msr, lr, etc. */
15#define ELF_NFPREG	33	/* includes fpscr */
16#define ELF_NVRREG	33	/* includes vscr */
17
18typedef unsigned long elf_greg_t64;
19typedef elf_greg_t64 elf_gregset_t64[ELF_NGREG];
20
21typedef unsigned int elf_greg_t32;
22typedef elf_greg_t32 elf_gregset_t32[ELF_NGREG];
23
24/*
25 * These are used to set parameters in the core dumps.
26 */
27#ifndef ELF_ARCH
28# define ELF_ARCH	EM_PPC64
29# define ELF_CLASS	ELFCLASS64
30# define ELF_DATA	ELFDATA2MSB
31  typedef elf_greg_t64 elf_greg_t;
32  typedef elf_gregset_t64 elf_gregset_t;
33# define elf_addr_t unsigned long
34# define elf_caddr_t char *
35#else
36  /* Assumption: ELF_ARCH == EM_PPC and ELF_CLASS == ELFCLASS32 */
37  typedef elf_greg_t32 elf_greg_t;
38  typedef elf_gregset_t32 elf_gregset_t;
39# define elf_addr_t u32
40# define elf_caddr_t u32
41#endif
42
43typedef double elf_fpreg_t;
44typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
45
46/*
47 * This is used to ensure we don't load something for the wrong architecture.
48 */
49#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
50
51#define USE_ELF_CORE_DUMP
52#define ELF_EXEC_PAGESIZE	4096
53
54/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
55   use of this is to invoke "./ld.so someprog" to test out a new version of
56   the loader.  We need to make sure that it is out of the way of the program
57   that it will "exec", and that there is sufficient room for the brk.  */
58
59#define ELF_ET_DYN_BASE         (0x08000000)
60
61/* Common routine for both 32-bit and 64-bit processes */
62#define ELF_CORE_COPY_REGS(gregs, regs) elf_core_copy_regs(gregs, regs);
63static inline void
64elf_core_copy_regs(elf_gregset_t dstRegs, struct pt_regs* srcRegs)
65{
66	int i;
67
68	int numGPRS = ((sizeof(struct pt_regs)/sizeof(elf_greg_t64)) < ELF_NGREG) ? (sizeof(struct pt_regs)/sizeof(elf_greg_t64)) : ELF_NGREG;
69
70	for (i=0; i < numGPRS; i++)
71		dstRegs[i] = (elf_greg_t)((elf_greg_t64 *)srcRegs)[i];
72}
73
74/* This yields a mask that user programs can use to figure out what
75   instruction set this cpu supports.  This could be done in userspace,
76   but it's not easy, and we've already done it here.  */
77
78#define ELF_HWCAP	(0)
79
80/* This yields a string that ld.so will use to load implementation
81   specific libraries for optimization.  This is more specific in
82   intent than poking at uname or /proc/cpuinfo.
83
84   For the moment, we have only optimizations for the Intel generations,
85   but that could change... */
86
87#define ELF_PLATFORM	(NULL)
88
89
90#define ELF_PLAT_INIT(_r, load_addr)	do { \
91	memset(_r->gpr, 0, sizeof(_r->gpr)); \
92	_r->ctr = _r->link = _r->xer = _r->ccr = 0; \
93	_r->gpr[2] = load_addr; \
94} while (0)
95
96
97
98#ifdef __KERNEL__
99#define SET_PERSONALITY(ex, ibcs2)				\
100do {	if ((ex).e_ident[EI_CLASS] == ELFCLASS32)		\
101		current->thread.flags |= PPC_FLAG_32BIT;	\
102	else							\
103		current->thread.flags &= ~PPC_FLAG_32BIT;	\
104	if (ibcs2)						\
105		set_personality(PER_SVR4);			\
106	else if (current->personality != PER_LINUX32)		\
107		set_personality(PER_LINUX);			\
108} while (0)
109#endif
110
111/*
112 * We need to put in some extra aux table entries to tell glibc what
113 * the cache block size is, so it can use the dcbz instruction safely.
114 */
115#define AT_DCACHEBSIZE		19
116#define AT_ICACHEBSIZE		20
117#define AT_UCACHEBSIZE		21
118/* A special ignored type value for PPC, for glibc compatibility.  */
119#define AT_IGNOREPPC		22
120
121extern int dcache_bsize;
122extern int icache_bsize;
123extern int ucache_bsize;
124
125/*
126 * The requirements here are:
127 * - keep the final alignment of sp (sp & 0xf)
128 * - make sure the 32-bit value at the first 16 byte aligned position of
129 *   AUXV is greater than 16 for glibc compatibility.
130 *   AT_IGNOREPPC is used for that.
131 * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
132 *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
133 */
134#define DLINFO_ARCH_ITEMS	3
135#define ARCH_DLINFO							\
136do {									\
137	sp -= DLINFO_ARCH_ITEMS * 2;					\
138	NEW_AUX_ENT(0, AT_DCACHEBSIZE, dcache_bsize);			\
139	NEW_AUX_ENT(1, AT_ICACHEBSIZE, icache_bsize);			\
140	NEW_AUX_ENT(2, AT_UCACHEBSIZE, ucache_bsize);			\
141	/*								\
142	 * Now handle glibc compatibility.				\
143	 */								\
144	sp -= 2*2;							\
145	NEW_AUX_ENT(0, AT_IGNOREPPC, AT_IGNOREPPC);			\
146	NEW_AUX_ENT(1, AT_IGNOREPPC, AT_IGNOREPPC);			\
147 } while (0)
148
149#endif /* __PPC64_ELF_H */
150