1*1965aae3SH. Peter Anvin #ifndef _ASM_X86_ELF_H 2*1965aae3SH. Peter Anvin #define _ASM_X86_ELF_H 3bb898558SAl Viro 4bb898558SAl Viro /* 5bb898558SAl Viro * ELF register definitions.. 6bb898558SAl Viro */ 7bb898558SAl Viro 8bb898558SAl Viro #include <asm/ptrace.h> 9bb898558SAl Viro #include <asm/user.h> 10bb898558SAl Viro #include <asm/auxvec.h> 11bb898558SAl Viro 12bb898558SAl Viro typedef unsigned long elf_greg_t; 13bb898558SAl Viro 14bb898558SAl Viro #define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) 15bb898558SAl Viro typedef elf_greg_t elf_gregset_t[ELF_NGREG]; 16bb898558SAl Viro 17bb898558SAl Viro typedef struct user_i387_struct elf_fpregset_t; 18bb898558SAl Viro 19bb898558SAl Viro #ifdef __i386__ 20bb898558SAl Viro 21bb898558SAl Viro typedef struct user_fxsr_struct elf_fpxregset_t; 22bb898558SAl Viro 23bb898558SAl Viro #define R_386_NONE 0 24bb898558SAl Viro #define R_386_32 1 25bb898558SAl Viro #define R_386_PC32 2 26bb898558SAl Viro #define R_386_GOT32 3 27bb898558SAl Viro #define R_386_PLT32 4 28bb898558SAl Viro #define R_386_COPY 5 29bb898558SAl Viro #define R_386_GLOB_DAT 6 30bb898558SAl Viro #define R_386_JMP_SLOT 7 31bb898558SAl Viro #define R_386_RELATIVE 8 32bb898558SAl Viro #define R_386_GOTOFF 9 33bb898558SAl Viro #define R_386_GOTPC 10 34bb898558SAl Viro #define R_386_NUM 11 35bb898558SAl Viro 36bb898558SAl Viro /* 37bb898558SAl Viro * These are used to set parameters in the core dumps. 38bb898558SAl Viro */ 39bb898558SAl Viro #define ELF_CLASS ELFCLASS32 40bb898558SAl Viro #define ELF_DATA ELFDATA2LSB 41bb898558SAl Viro #define ELF_ARCH EM_386 42bb898558SAl Viro 43bb898558SAl Viro #else 44bb898558SAl Viro 45bb898558SAl Viro /* x86-64 relocation types */ 46bb898558SAl Viro #define R_X86_64_NONE 0 /* No reloc */ 47bb898558SAl Viro #define R_X86_64_64 1 /* Direct 64 bit */ 48bb898558SAl Viro #define R_X86_64_PC32 2 /* PC relative 32 bit signed */ 49bb898558SAl Viro #define R_X86_64_GOT32 3 /* 32 bit GOT entry */ 50bb898558SAl Viro #define R_X86_64_PLT32 4 /* 32 bit PLT address */ 51bb898558SAl Viro #define R_X86_64_COPY 5 /* Copy symbol at runtime */ 52bb898558SAl Viro #define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ 53bb898558SAl Viro #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ 54bb898558SAl Viro #define R_X86_64_RELATIVE 8 /* Adjust by program base */ 55bb898558SAl Viro #define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative 56bb898558SAl Viro offset to GOT */ 57bb898558SAl Viro #define R_X86_64_32 10 /* Direct 32 bit zero extended */ 58bb898558SAl Viro #define R_X86_64_32S 11 /* Direct 32 bit sign extended */ 59bb898558SAl Viro #define R_X86_64_16 12 /* Direct 16 bit zero extended */ 60bb898558SAl Viro #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ 61bb898558SAl Viro #define R_X86_64_8 14 /* Direct 8 bit sign extended */ 62bb898558SAl Viro #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ 63bb898558SAl Viro 64bb898558SAl Viro #define R_X86_64_NUM 16 65bb898558SAl Viro 66bb898558SAl Viro /* 67bb898558SAl Viro * These are used to set parameters in the core dumps. 68bb898558SAl Viro */ 69bb898558SAl Viro #define ELF_CLASS ELFCLASS64 70bb898558SAl Viro #define ELF_DATA ELFDATA2LSB 71bb898558SAl Viro #define ELF_ARCH EM_X86_64 72bb898558SAl Viro 73bb898558SAl Viro #endif 74bb898558SAl Viro 75bb898558SAl Viro #include <asm/vdso.h> 76bb898558SAl Viro 77bb898558SAl Viro extern unsigned int vdso_enabled; 78bb898558SAl Viro 79bb898558SAl Viro /* 80bb898558SAl Viro * This is used to ensure we don't load something for the wrong architecture. 81bb898558SAl Viro */ 82bb898558SAl Viro #define elf_check_arch_ia32(x) \ 83bb898558SAl Viro (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486)) 84bb898558SAl Viro 85bb898558SAl Viro #include <asm/processor.h> 86bb898558SAl Viro #include <asm/system.h> 87bb898558SAl Viro 88bb898558SAl Viro #ifdef CONFIG_X86_32 89bb898558SAl Viro #include <asm/desc.h> 90bb898558SAl Viro 91bb898558SAl Viro #define elf_check_arch(x) elf_check_arch_ia32(x) 92bb898558SAl Viro 93bb898558SAl Viro /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx 94bb898558SAl Viro contains a pointer to a function which might be registered using `atexit'. 95bb898558SAl Viro This provides a mean for the dynamic linker to call DT_FINI functions for 96bb898558SAl Viro shared libraries that have been loaded before the code runs. 97bb898558SAl Viro 98bb898558SAl Viro A value of 0 tells we have no such handler. 99bb898558SAl Viro 100bb898558SAl Viro We might as well make sure everything else is cleared too (except for %esp), 101bb898558SAl Viro just to make things more deterministic. 102bb898558SAl Viro */ 103bb898558SAl Viro #define ELF_PLAT_INIT(_r, load_addr) \ 104bb898558SAl Viro do { \ 105bb898558SAl Viro _r->bx = 0; _r->cx = 0; _r->dx = 0; \ 106bb898558SAl Viro _r->si = 0; _r->di = 0; _r->bp = 0; \ 107bb898558SAl Viro _r->ax = 0; \ 108bb898558SAl Viro } while (0) 109bb898558SAl Viro 110bb898558SAl Viro /* 111bb898558SAl Viro * regs is struct pt_regs, pr_reg is elf_gregset_t (which is 112bb898558SAl Viro * now struct_user_regs, they are different) 113bb898558SAl Viro */ 114bb898558SAl Viro 115bb898558SAl Viro #define ELF_CORE_COPY_REGS(pr_reg, regs) \ 116bb898558SAl Viro do { \ 117bb898558SAl Viro pr_reg[0] = regs->bx; \ 118bb898558SAl Viro pr_reg[1] = regs->cx; \ 119bb898558SAl Viro pr_reg[2] = regs->dx; \ 120bb898558SAl Viro pr_reg[3] = regs->si; \ 121bb898558SAl Viro pr_reg[4] = regs->di; \ 122bb898558SAl Viro pr_reg[5] = regs->bp; \ 123bb898558SAl Viro pr_reg[6] = regs->ax; \ 124bb898558SAl Viro pr_reg[7] = regs->ds & 0xffff; \ 125bb898558SAl Viro pr_reg[8] = regs->es & 0xffff; \ 126bb898558SAl Viro pr_reg[9] = regs->fs & 0xffff; \ 127bb898558SAl Viro savesegment(gs, pr_reg[10]); \ 128bb898558SAl Viro pr_reg[11] = regs->orig_ax; \ 129bb898558SAl Viro pr_reg[12] = regs->ip; \ 130bb898558SAl Viro pr_reg[13] = regs->cs & 0xffff; \ 131bb898558SAl Viro pr_reg[14] = regs->flags; \ 132bb898558SAl Viro pr_reg[15] = regs->sp; \ 133bb898558SAl Viro pr_reg[16] = regs->ss & 0xffff; \ 134bb898558SAl Viro } while (0); 135bb898558SAl Viro 136bb898558SAl Viro #define ELF_PLATFORM (utsname()->machine) 137bb898558SAl Viro #define set_personality_64bit() do { } while (0) 138bb898558SAl Viro 139bb898558SAl Viro #else /* CONFIG_X86_32 */ 140bb898558SAl Viro 141bb898558SAl Viro /* 142bb898558SAl Viro * This is used to ensure we don't load something for the wrong architecture. 143bb898558SAl Viro */ 144bb898558SAl Viro #define elf_check_arch(x) \ 145bb898558SAl Viro ((x)->e_machine == EM_X86_64) 146bb898558SAl Viro 147bb898558SAl Viro #define compat_elf_check_arch(x) elf_check_arch_ia32(x) 148bb898558SAl Viro 149bb898558SAl Viro static inline void start_ia32_thread(struct pt_regs *regs, u32 ip, u32 sp) 150bb898558SAl Viro { 151bb898558SAl Viro loadsegment(fs, 0); 152bb898558SAl Viro loadsegment(ds, __USER32_DS); 153bb898558SAl Viro loadsegment(es, __USER32_DS); 154bb898558SAl Viro load_gs_index(0); 155bb898558SAl Viro regs->ip = ip; 156bb898558SAl Viro regs->sp = sp; 157bb898558SAl Viro regs->flags = X86_EFLAGS_IF; 158bb898558SAl Viro regs->cs = __USER32_CS; 159bb898558SAl Viro regs->ss = __USER32_DS; 160bb898558SAl Viro } 161bb898558SAl Viro 162bb898558SAl Viro static inline void elf_common_init(struct thread_struct *t, 163bb898558SAl Viro struct pt_regs *regs, const u16 ds) 164bb898558SAl Viro { 165bb898558SAl Viro regs->ax = regs->bx = regs->cx = regs->dx = 0; 166bb898558SAl Viro regs->si = regs->di = regs->bp = 0; 167bb898558SAl Viro regs->r8 = regs->r9 = regs->r10 = regs->r11 = 0; 168bb898558SAl Viro regs->r12 = regs->r13 = regs->r14 = regs->r15 = 0; 169bb898558SAl Viro t->fs = t->gs = 0; 170bb898558SAl Viro t->fsindex = t->gsindex = 0; 171bb898558SAl Viro t->ds = t->es = ds; 172bb898558SAl Viro } 173bb898558SAl Viro 174bb898558SAl Viro #define ELF_PLAT_INIT(_r, load_addr) \ 175bb898558SAl Viro do { \ 176bb898558SAl Viro elf_common_init(¤t->thread, _r, 0); \ 177bb898558SAl Viro clear_thread_flag(TIF_IA32); \ 178bb898558SAl Viro } while (0) 179bb898558SAl Viro 180bb898558SAl Viro #define COMPAT_ELF_PLAT_INIT(regs, load_addr) \ 181bb898558SAl Viro elf_common_init(¤t->thread, regs, __USER_DS) 182bb898558SAl Viro 183bb898558SAl Viro #define compat_start_thread(regs, ip, sp) \ 184bb898558SAl Viro do { \ 185bb898558SAl Viro start_ia32_thread(regs, ip, sp); \ 186bb898558SAl Viro set_fs(USER_DS); \ 187bb898558SAl Viro } while (0) 188bb898558SAl Viro 189bb898558SAl Viro #define COMPAT_SET_PERSONALITY(ex) \ 190bb898558SAl Viro do { \ 191bb898558SAl Viro if (test_thread_flag(TIF_IA32)) \ 192bb898558SAl Viro clear_thread_flag(TIF_ABI_PENDING); \ 193bb898558SAl Viro else \ 194bb898558SAl Viro set_thread_flag(TIF_ABI_PENDING); \ 195bb898558SAl Viro current->personality |= force_personality32; \ 196bb898558SAl Viro } while (0) 197bb898558SAl Viro 198bb898558SAl Viro #define COMPAT_ELF_PLATFORM ("i686") 199bb898558SAl Viro 200bb898558SAl Viro /* 201bb898558SAl Viro * regs is struct pt_regs, pr_reg is elf_gregset_t (which is 202bb898558SAl Viro * now struct_user_regs, they are different). Assumes current is the process 203bb898558SAl Viro * getting dumped. 204bb898558SAl Viro */ 205bb898558SAl Viro 206bb898558SAl Viro #define ELF_CORE_COPY_REGS(pr_reg, regs) \ 207bb898558SAl Viro do { \ 208bb898558SAl Viro unsigned v; \ 209bb898558SAl Viro (pr_reg)[0] = (regs)->r15; \ 210bb898558SAl Viro (pr_reg)[1] = (regs)->r14; \ 211bb898558SAl Viro (pr_reg)[2] = (regs)->r13; \ 212bb898558SAl Viro (pr_reg)[3] = (regs)->r12; \ 213bb898558SAl Viro (pr_reg)[4] = (regs)->bp; \ 214bb898558SAl Viro (pr_reg)[5] = (regs)->bx; \ 215bb898558SAl Viro (pr_reg)[6] = (regs)->r11; \ 216bb898558SAl Viro (pr_reg)[7] = (regs)->r10; \ 217bb898558SAl Viro (pr_reg)[8] = (regs)->r9; \ 218bb898558SAl Viro (pr_reg)[9] = (regs)->r8; \ 219bb898558SAl Viro (pr_reg)[10] = (regs)->ax; \ 220bb898558SAl Viro (pr_reg)[11] = (regs)->cx; \ 221bb898558SAl Viro (pr_reg)[12] = (regs)->dx; \ 222bb898558SAl Viro (pr_reg)[13] = (regs)->si; \ 223bb898558SAl Viro (pr_reg)[14] = (regs)->di; \ 224bb898558SAl Viro (pr_reg)[15] = (regs)->orig_ax; \ 225bb898558SAl Viro (pr_reg)[16] = (regs)->ip; \ 226bb898558SAl Viro (pr_reg)[17] = (regs)->cs; \ 227bb898558SAl Viro (pr_reg)[18] = (regs)->flags; \ 228bb898558SAl Viro (pr_reg)[19] = (regs)->sp; \ 229bb898558SAl Viro (pr_reg)[20] = (regs)->ss; \ 230bb898558SAl Viro (pr_reg)[21] = current->thread.fs; \ 231bb898558SAl Viro (pr_reg)[22] = current->thread.gs; \ 232bb898558SAl Viro asm("movl %%ds,%0" : "=r" (v)); (pr_reg)[23] = v; \ 233bb898558SAl Viro asm("movl %%es,%0" : "=r" (v)); (pr_reg)[24] = v; \ 234bb898558SAl Viro asm("movl %%fs,%0" : "=r" (v)); (pr_reg)[25] = v; \ 235bb898558SAl Viro asm("movl %%gs,%0" : "=r" (v)); (pr_reg)[26] = v; \ 236bb898558SAl Viro } while (0); 237bb898558SAl Viro 238bb898558SAl Viro /* I'm not sure if we can use '-' here */ 239bb898558SAl Viro #define ELF_PLATFORM ("x86_64") 240bb898558SAl Viro extern void set_personality_64bit(void); 241bb898558SAl Viro extern unsigned int sysctl_vsyscall32; 242bb898558SAl Viro extern int force_personality32; 243bb898558SAl Viro 244bb898558SAl Viro #endif /* !CONFIG_X86_32 */ 245bb898558SAl Viro 246bb898558SAl Viro #define CORE_DUMP_USE_REGSET 247bb898558SAl Viro #define USE_ELF_CORE_DUMP 248bb898558SAl Viro #define ELF_EXEC_PAGESIZE 4096 249bb898558SAl Viro 250bb898558SAl Viro /* This is the location that an ET_DYN program is loaded if exec'ed. Typical 251bb898558SAl Viro use of this is to invoke "./ld.so someprog" to test out a new version of 252bb898558SAl Viro the loader. We need to make sure that it is out of the way of the program 253bb898558SAl Viro that it will "exec", and that there is sufficient room for the brk. */ 254bb898558SAl Viro 255bb898558SAl Viro #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) 256bb898558SAl Viro 257bb898558SAl Viro /* This yields a mask that user programs can use to figure out what 258bb898558SAl Viro instruction set this CPU supports. This could be done in user space, 259bb898558SAl Viro but it's not easy, and we've already done it here. */ 260bb898558SAl Viro 261bb898558SAl Viro #define ELF_HWCAP (boot_cpu_data.x86_capability[0]) 262bb898558SAl Viro 263bb898558SAl Viro /* This yields a string that ld.so will use to load implementation 264bb898558SAl Viro specific libraries for optimization. This is more specific in 265bb898558SAl Viro intent than poking at uname or /proc/cpuinfo. 266bb898558SAl Viro 267bb898558SAl Viro For the moment, we have only optimizations for the Intel generations, 268bb898558SAl Viro but that could change... */ 269bb898558SAl Viro 270bb898558SAl Viro #define SET_PERSONALITY(ex) set_personality_64bit() 271bb898558SAl Viro 272bb898558SAl Viro /* 273bb898558SAl Viro * An executable for which elf_read_implies_exec() returns TRUE will 274bb898558SAl Viro * have the READ_IMPLIES_EXEC personality flag set automatically. 275bb898558SAl Viro */ 276bb898558SAl Viro #define elf_read_implies_exec(ex, executable_stack) \ 277bb898558SAl Viro (executable_stack != EXSTACK_DISABLE_X) 278bb898558SAl Viro 279bb898558SAl Viro struct task_struct; 280bb898558SAl Viro 281bb898558SAl Viro #define ARCH_DLINFO_IA32(vdso_enabled) \ 282bb898558SAl Viro do { \ 283bb898558SAl Viro if (vdso_enabled) { \ 284bb898558SAl Viro NEW_AUX_ENT(AT_SYSINFO, VDSO_ENTRY); \ 285bb898558SAl Viro NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE); \ 286bb898558SAl Viro } \ 287bb898558SAl Viro } while (0) 288bb898558SAl Viro 289bb898558SAl Viro #ifdef CONFIG_X86_32 290bb898558SAl Viro 291bb898558SAl Viro #define VDSO_HIGH_BASE (__fix_to_virt(FIX_VDSO)) 292bb898558SAl Viro 293bb898558SAl Viro #define ARCH_DLINFO ARCH_DLINFO_IA32(vdso_enabled) 294bb898558SAl Viro 295bb898558SAl Viro /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ 296bb898558SAl Viro 297bb898558SAl Viro #else /* CONFIG_X86_32 */ 298bb898558SAl Viro 299bb898558SAl Viro #define VDSO_HIGH_BASE 0xffffe000U /* CONFIG_COMPAT_VDSO address */ 300bb898558SAl Viro 301bb898558SAl Viro /* 1GB for 64bit, 8MB for 32bit */ 302bb898558SAl Viro #define STACK_RND_MASK (test_thread_flag(TIF_IA32) ? 0x7ff : 0x3fffff) 303bb898558SAl Viro 304bb898558SAl Viro #define ARCH_DLINFO \ 305bb898558SAl Viro do { \ 306bb898558SAl Viro if (vdso_enabled) \ 307bb898558SAl Viro NEW_AUX_ENT(AT_SYSINFO_EHDR, \ 308bb898558SAl Viro (unsigned long)current->mm->context.vdso); \ 309bb898558SAl Viro } while (0) 310bb898558SAl Viro 311bb898558SAl Viro #define AT_SYSINFO 32 312bb898558SAl Viro 313bb898558SAl Viro #define COMPAT_ARCH_DLINFO ARCH_DLINFO_IA32(sysctl_vsyscall32) 314bb898558SAl Viro 315bb898558SAl Viro #define COMPAT_ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) 316bb898558SAl Viro 317bb898558SAl Viro #endif /* !CONFIG_X86_32 */ 318bb898558SAl Viro 319bb898558SAl Viro #define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso) 320bb898558SAl Viro 321bb898558SAl Viro #define VDSO_ENTRY \ 322bb898558SAl Viro ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall)) 323bb898558SAl Viro 324bb898558SAl Viro struct linux_binprm; 325bb898558SAl Viro 326bb898558SAl Viro #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 327bb898558SAl Viro extern int arch_setup_additional_pages(struct linux_binprm *bprm, 328bb898558SAl Viro int executable_stack); 329bb898558SAl Viro 330bb898558SAl Viro extern int syscall32_setup_pages(struct linux_binprm *, int exstack); 331bb898558SAl Viro #define compat_arch_setup_additional_pages syscall32_setup_pages 332bb898558SAl Viro 333bb898558SAl Viro extern unsigned long arch_randomize_brk(struct mm_struct *mm); 334bb898558SAl Viro #define arch_randomize_brk arch_randomize_brk 335bb898558SAl Viro 336*1965aae3SH. Peter Anvin #endif /* _ASM_X86_ELF_H */ 337