Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | 009ec2a9 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | #ifndef __UM_ELF_I386_H |
| 6 | #define __UM_ELF_I386_H |
| 7 | |
Jeff Dike | 8192ab4 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 8 | #include <asm/user.h> |
Jeff Dike | 058ac30 | 2007-10-16 01:27:17 -0700 | [diff] [blame] | 9 | #include "skas.h" |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 10 | |
| 11 | #define R_386_NONE 0 |
| 12 | #define R_386_32 1 |
| 13 | #define R_386_PC32 2 |
| 14 | #define R_386_GOT32 3 |
| 15 | #define R_386_PLT32 4 |
| 16 | #define R_386_COPY 5 |
| 17 | #define R_386_GLOB_DAT 6 |
| 18 | #define R_386_JMP_SLOT 7 |
| 19 | #define R_386_RELATIVE 8 |
| 20 | #define R_386_GOTOFF 9 |
| 21 | #define R_386_GOTPC 10 |
| 22 | #define R_386_NUM 11 |
| 23 | |
| 24 | typedef unsigned long elf_greg_t; |
| 25 | |
| 26 | #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t)) |
| 27 | typedef elf_greg_t elf_gregset_t[ELF_NGREG]; |
| 28 | |
| 29 | typedef struct user_i387_struct elf_fpregset_t; |
| 30 | |
| 31 | /* |
| 32 | * This is used to ensure we don't load something for the wrong architecture. |
| 33 | */ |
| 34 | #define elf_check_arch(x) \ |
| 35 | (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486)) |
| 36 | |
| 37 | #define ELF_CLASS ELFCLASS32 |
| 38 | #define ELF_DATA ELFDATA2LSB |
| 39 | #define ELF_ARCH EM_386 |
| 40 | |
| 41 | #define ELF_PLAT_INIT(regs, load_addr) do { \ |
| 42 | PT_REGS_EBX(regs) = 0; \ |
| 43 | PT_REGS_ECX(regs) = 0; \ |
| 44 | PT_REGS_EDX(regs) = 0; \ |
| 45 | PT_REGS_ESI(regs) = 0; \ |
| 46 | PT_REGS_EDI(regs) = 0; \ |
| 47 | PT_REGS_EBP(regs) = 0; \ |
| 48 | PT_REGS_EAX(regs) = 0; \ |
Jeff Dike | 009ec2a9 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 49 | } while (0) |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 50 | |
| 51 | #define USE_ELF_CORE_DUMP |
| 52 | #define ELF_EXEC_PAGESIZE 4096 |
| 53 | |
| 54 | #define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3) |
| 55 | |
| 56 | /* Shamelessly stolen from include/asm-i386/elf.h */ |
| 57 | |
| 58 | #define ELF_CORE_COPY_REGS(pr_reg, regs) do { \ |
| 59 | pr_reg[0] = PT_REGS_EBX(regs); \ |
| 60 | pr_reg[1] = PT_REGS_ECX(regs); \ |
| 61 | pr_reg[2] = PT_REGS_EDX(regs); \ |
| 62 | pr_reg[3] = PT_REGS_ESI(regs); \ |
| 63 | pr_reg[4] = PT_REGS_EDI(regs); \ |
| 64 | pr_reg[5] = PT_REGS_EBP(regs); \ |
| 65 | pr_reg[6] = PT_REGS_EAX(regs); \ |
| 66 | pr_reg[7] = PT_REGS_DS(regs); \ |
| 67 | pr_reg[8] = PT_REGS_ES(regs); \ |
| 68 | /* fake once used fs and gs selectors? */ \ |
| 69 | pr_reg[9] = PT_REGS_DS(regs); \ |
| 70 | pr_reg[10] = PT_REGS_DS(regs); \ |
| 71 | pr_reg[11] = PT_REGS_SYSCALL_NR(regs); \ |
| 72 | pr_reg[12] = PT_REGS_IP(regs); \ |
| 73 | pr_reg[13] = PT_REGS_CS(regs); \ |
| 74 | pr_reg[14] = PT_REGS_EFLAGS(regs); \ |
| 75 | pr_reg[15] = PT_REGS_SP(regs); \ |
| 76 | pr_reg[16] = PT_REGS_SS(regs); \ |
Jeff Dike | 009ec2a9 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 77 | } while (0); |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 78 | |
Jeff Dike | 8192ab4 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 79 | extern int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu); |
Jeff Dike | 058ac30 | 2007-10-16 01:27:17 -0700 | [diff] [blame] | 80 | |
| 81 | #define ELF_CORE_COPY_FPREGS(t, fpu) elf_core_copy_fpregs(t, fpu) |
| 82 | |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 83 | extern long elf_aux_hwcap; |
| 84 | #define ELF_HWCAP (elf_aux_hwcap) |
| 85 | |
| 86 | extern char * elf_aux_platform; |
| 87 | #define ELF_PLATFORM (elf_aux_platform) |
| 88 | |
Jeff Dike | 009ec2a9 | 2008-02-04 22:30:53 -0800 | [diff] [blame] | 89 | #define SET_PERSONALITY(ex, ibcs2) do { } while (0) |
Bodo Stroesser | dbc35cc7 | 2005-05-05 16:15:35 -0700 | [diff] [blame] | 90 | |
| 91 | extern unsigned long vsyscall_ehdr; |
| 92 | extern unsigned long vsyscall_end; |
| 93 | extern unsigned long __kernel_vsyscall; |
| 94 | |
| 95 | #define VSYSCALL_BASE vsyscall_ehdr |
| 96 | #define VSYSCALL_END vsyscall_end |
| 97 | |
| 98 | /* |
| 99 | * This is the range that is readable by user mode, and things |
| 100 | * acting like user mode such as get_user_pages. |
| 101 | */ |
| 102 | #define FIXADDR_USER_START VSYSCALL_BASE |
| 103 | #define FIXADDR_USER_END VSYSCALL_END |
| 104 | |
| 105 | /* |
| 106 | * Architecture-neutral AT_ values in 0-17, leave some room |
| 107 | * for more of them, start the x86-specific ones at 32. |
| 108 | */ |
| 109 | #define AT_SYSINFO 32 |
| 110 | #define AT_SYSINFO_EHDR 33 |
| 111 | |
| 112 | #define ARCH_DLINFO \ |
| 113 | do { \ |
| 114 | if ( vsyscall_ehdr ) { \ |
| 115 | NEW_AUX_ENT(AT_SYSINFO, __kernel_vsyscall); \ |
| 116 | NEW_AUX_ENT(AT_SYSINFO_EHDR, vsyscall_ehdr); \ |
| 117 | } \ |
| 118 | } while (0) |
| 119 | |
| 120 | /* |
| 121 | * These macros parameterize elf_core_dump in fs/binfmt_elf.c to write out |
| 122 | * extra segments containing the vsyscall DSO contents. Dumping its |
| 123 | * contents makes post-mortem fully interpretable later without matching up |
| 124 | * the same kernel and hardware config to see what PC values meant. |
| 125 | * Dumping its extra ELF program headers includes all the other information |
| 126 | * a debugger needs to easily find how the vsyscall DSO was being used. |
| 127 | */ |
| 128 | #define ELF_CORE_EXTRA_PHDRS \ |
| 129 | (vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0 ) |
| 130 | |
| 131 | #define ELF_CORE_WRITE_EXTRA_PHDRS \ |
| 132 | if ( vsyscall_ehdr ) { \ |
| 133 | const struct elfhdr *const ehdrp = (struct elfhdr *)vsyscall_ehdr; \ |
| 134 | const struct elf_phdr *const phdrp = \ |
| 135 | (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); \ |
| 136 | int i; \ |
| 137 | Elf32_Off ofs = 0; \ |
| 138 | for (i = 0; i < ehdrp->e_phnum; ++i) { \ |
| 139 | struct elf_phdr phdr = phdrp[i]; \ |
| 140 | if (phdr.p_type == PT_LOAD) { \ |
| 141 | ofs = phdr.p_offset = offset; \ |
| 142 | offset += phdr.p_filesz; \ |
| 143 | } \ |
| 144 | else \ |
| 145 | phdr.p_offset += ofs; \ |
| 146 | phdr.p_paddr = 0; /* match other core phdrs */ \ |
| 147 | DUMP_WRITE(&phdr, sizeof(phdr)); \ |
| 148 | } \ |
| 149 | } |
| 150 | #define ELF_CORE_WRITE_EXTRA_DATA \ |
| 151 | if ( vsyscall_ehdr ) { \ |
| 152 | const struct elfhdr *const ehdrp = (struct elfhdr *)vsyscall_ehdr; \ |
| 153 | const struct elf_phdr *const phdrp = \ |
| 154 | (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); \ |
| 155 | int i; \ |
| 156 | for (i = 0; i < ehdrp->e_phnum; ++i) { \ |
| 157 | if (phdrp[i].p_type == PT_LOAD) \ |
| 158 | DUMP_WRITE((void *) phdrp[i].p_vaddr, \ |
| 159 | phdrp[i].p_filesz); \ |
| 160 | } \ |
| 161 | } |
| 162 | |
| 163 | #endif |