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