0515d61d54111d4c094ea296a926bf966e043fee
[sfrench/cifs-2.6.git] / include / asm-i386 / elf.h
1 #ifndef __ASMi386_ELF_H
2 #define __ASMi386_ELF_H
3
4 /*
5  * ELF register definitions..
6  */
7
8 #include <asm/ptrace.h>
9 #include <asm/user.h>
10 #include <asm/auxvec.h>
11
12 #include <linux/utsname.h>
13
14 #define R_386_NONE      0
15 #define R_386_32        1
16 #define R_386_PC32      2
17 #define R_386_GOT32     3
18 #define R_386_PLT32     4
19 #define R_386_COPY      5
20 #define R_386_GLOB_DAT  6
21 #define R_386_JMP_SLOT  7
22 #define R_386_RELATIVE  8
23 #define R_386_GOTOFF    9
24 #define R_386_GOTPC     10
25 #define R_386_NUM       11
26
27 typedef unsigned long elf_greg_t;
28
29 #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t))
30 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
31
32 typedef struct user_i387_struct elf_fpregset_t;
33 typedef struct user_fxsr_struct elf_fpxregset_t;
34
35 /*
36  * This is used to ensure we don't load something for the wrong architecture.
37  */
38 #define elf_check_arch(x) \
39         (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
40
41 /*
42  * These are used to set parameters in the core dumps.
43  */
44 #define ELF_CLASS       ELFCLASS32
45 #define ELF_DATA        ELFDATA2LSB
46 #define ELF_ARCH        EM_386
47
48 #ifdef __KERNEL__
49
50 #include <asm/processor.h>
51 #include <asm/system.h>         /* for savesegment */
52 #include <asm/desc.h>
53
54 /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
55    contains a pointer to a function which might be registered using `atexit'.
56    This provides a mean for the dynamic linker to call DT_FINI functions for
57    shared libraries that have been loaded before the code runs.
58
59    A value of 0 tells we have no such handler. 
60
61    We might as well make sure everything else is cleared too (except for %esp),
62    just to make things more deterministic.
63  */
64 #define ELF_PLAT_INIT(_r, load_addr)    do { \
65         _r->ebx = 0; _r->ecx = 0; _r->edx = 0; \
66         _r->esi = 0; _r->edi = 0; _r->ebp = 0; \
67         _r->eax = 0; \
68 } while (0)
69
70 #define USE_ELF_CORE_DUMP
71 #define ELF_EXEC_PAGESIZE       4096
72
73 /* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
74    use of this is to invoke "./ld.so someprog" to test out a new version of
75    the loader.  We need to make sure that it is out of the way of the program
76    that it will "exec", and that there is sufficient room for the brk.  */
77
78 #define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
79
80 /* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
81    now struct_user_regs, they are different) */
82
83 #define ELF_CORE_COPY_REGS(pr_reg, regs)                \
84         pr_reg[0] = regs->ebx;                          \
85         pr_reg[1] = regs->ecx;                          \
86         pr_reg[2] = regs->edx;                          \
87         pr_reg[3] = regs->esi;                          \
88         pr_reg[4] = regs->edi;                          \
89         pr_reg[5] = regs->ebp;                          \
90         pr_reg[6] = regs->eax;                          \
91         pr_reg[7] = regs->xds;                          \
92         pr_reg[8] = regs->xes;                          \
93         savesegment(fs,pr_reg[9]);                      \
94         pr_reg[10] = regs->xgs;                         \
95         pr_reg[11] = regs->orig_eax;                    \
96         pr_reg[12] = regs->eip;                         \
97         pr_reg[13] = regs->xcs;                         \
98         pr_reg[14] = regs->eflags;                      \
99         pr_reg[15] = regs->esp;                         \
100         pr_reg[16] = regs->xss;
101
102 /* This yields a mask that user programs can use to figure out what
103    instruction set this CPU supports.  This could be done in user space,
104    but it's not easy, and we've already done it here.  */
105
106 #define ELF_HWCAP       (boot_cpu_data.x86_capability[0])
107
108 /* This yields a string that ld.so will use to load implementation
109    specific libraries for optimization.  This is more specific in
110    intent than poking at uname or /proc/cpuinfo.
111
112    For the moment, we have only optimizations for the Intel generations,
113    but that could change... */
114
115 #define ELF_PLATFORM  (utsname()->machine)
116
117 #define SET_PERSONALITY(ex, ibcs2) do { } while (0)
118
119 /*
120  * An executable for which elf_read_implies_exec() returns TRUE will
121  * have the READ_IMPLIES_EXEC personality flag set automatically.
122  */
123 #define elf_read_implies_exec(ex, executable_stack)     (executable_stack != EXSTACK_DISABLE_X)
124
125 struct task_struct;
126
127 extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
128 extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
129 extern int dump_task_extended_fpu (struct task_struct *, struct user_fxsr_struct *);
130
131 #define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
132 #define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs)
133 #define ELF_CORE_COPY_XFPREGS(tsk, elf_xfpregs) dump_task_extended_fpu(tsk, elf_xfpregs)
134
135 #define VDSO_HIGH_BASE          (__fix_to_virt(FIX_VDSO))
136 #define VDSO_BASE               ((unsigned long)current->mm->context.vdso)
137
138 #ifdef CONFIG_COMPAT_VDSO
139 # define VDSO_COMPAT_BASE       VDSO_HIGH_BASE
140 # define VDSO_PRELINK           VDSO_HIGH_BASE
141 #else
142 # define VDSO_COMPAT_BASE       VDSO_BASE
143 # define VDSO_PRELINK           0
144 #endif
145
146 #define VDSO_SYM(x) \
147                 (VDSO_COMPAT_BASE + (unsigned long)(x) - VDSO_PRELINK)
148
149 #define VDSO_HIGH_EHDR          ((const struct elfhdr *) VDSO_HIGH_BASE)
150 #define VDSO_EHDR               ((const struct elfhdr *) VDSO_COMPAT_BASE)
151
152 extern void __kernel_vsyscall;
153
154 #define VDSO_ENTRY              VDSO_SYM(&__kernel_vsyscall)
155
156 #ifndef CONFIG_COMPAT_VDSO
157 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
158 struct linux_binprm;
159 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
160                                        int executable_stack);
161 #endif
162
163 extern unsigned int vdso_enabled;
164
165 #define ARCH_DLINFO                                             \
166 do if (vdso_enabled) {                                          \
167                 NEW_AUX_ENT(AT_SYSINFO, VDSO_ENTRY);            \
168                 NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_COMPAT_BASE); \
169 } while (0)
170
171 /*
172  * These macros parameterize elf_core_dump in fs/binfmt_elf.c to write out
173  * extra segments containing the vsyscall DSO contents.  Dumping its
174  * contents makes post-mortem fully interpretable later without matching up
175  * the same kernel and hardware config to see what PC values meant.
176  * Dumping its extra ELF program headers includes all the other information
177  * a debugger needs to easily find how the vsyscall DSO was being used.
178  */
179 #define ELF_CORE_EXTRA_PHDRS            (VDSO_HIGH_EHDR->e_phnum)
180 #define ELF_CORE_WRITE_EXTRA_PHDRS                                            \
181 do {                                                                          \
182         const struct elf_phdr *const vsyscall_phdrs =                         \
183                 (const struct elf_phdr *) (VDSO_HIGH_BASE                     \
184                                            + VDSO_HIGH_EHDR->e_phoff);    \
185         int i;                                                                \
186         Elf32_Off ofs = 0;                                                    \
187         for (i = 0; i < VDSO_HIGH_EHDR->e_phnum; ++i) {               \
188                 struct elf_phdr phdr = vsyscall_phdrs[i];                     \
189                 if (phdr.p_type == PT_LOAD) {                                 \
190                         BUG_ON(ofs != 0);                                     \
191                         ofs = phdr.p_offset = offset;                         \
192                         phdr.p_memsz = PAGE_ALIGN(phdr.p_memsz);              \
193                         phdr.p_filesz = phdr.p_memsz;                         \
194                         offset += phdr.p_filesz;                              \
195                 }                                                             \
196                 else                                                          \
197                         phdr.p_offset += ofs;                                 \
198                 phdr.p_paddr = 0; /* match other core phdrs */                \
199                 DUMP_WRITE(&phdr, sizeof(phdr));                              \
200         }                                                                     \
201 } while (0)
202 #define ELF_CORE_WRITE_EXTRA_DATA                                             \
203 do {                                                                          \
204         const struct elf_phdr *const vsyscall_phdrs =                         \
205                 (const struct elf_phdr *) (VDSO_HIGH_BASE                     \
206                                            + VDSO_HIGH_EHDR->e_phoff);    \
207         int i;                                                                \
208         for (i = 0; i < VDSO_HIGH_EHDR->e_phnum; ++i) {               \
209                 if (vsyscall_phdrs[i].p_type == PT_LOAD)                      \
210                         DUMP_WRITE((void *) vsyscall_phdrs[i].p_vaddr,        \
211                                    PAGE_ALIGN(vsyscall_phdrs[i].p_memsz));    \
212         }                                                                     \
213 } while (0)
214
215 #endif
216
217 #endif