Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * ELF register definitions..
0004  */
0005 #ifndef _ASM_POWERPC_ELF_H
0006 #define _ASM_POWERPC_ELF_H
0007 
0008 #include <linux/sched.h>    /* for task_struct */
0009 #include <asm/page.h>
0010 #include <asm/string.h>
0011 #include <uapi/asm/elf.h>
0012 
0013 /*
0014  * This is used to ensure we don't load something for the wrong architecture.
0015  */
0016 #define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
0017 #define compat_elf_check_arch(x)    ((x)->e_machine == EM_PPC)
0018 
0019 #define CORE_DUMP_USE_REGSET
0020 #define ELF_EXEC_PAGESIZE   PAGE_SIZE
0021 
0022 /*
0023  * This is the base location for PIE (ET_DYN with INTERP) loads. On
0024  * 64-bit, this is raised to 4GB to leave the entire 32-bit address
0025  * space open for things that want to use the area for 32-bit pointers.
0026  */
0027 #define ELF_ET_DYN_BASE     (is_32bit_task() ? 0x000400000UL : \
0028                            0x100000000UL)
0029 
0030 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
0031 
0032 /*
0033  * Our registers are always unsigned longs, whether we're a 32 bit
0034  * process or 64 bit, on either a 64 bit or 32 bit kernel.
0035  *
0036  * This macro relies on elf_regs[i] having the right type to truncate to,
0037  * either u32 or u64.  It defines the body of the elf_core_copy_regs
0038  * function, either the native one with elf_gregset_t elf_regs or
0039  * the 32-bit one with elf_gregset_t32 elf_regs.
0040  */
0041 #define PPC_ELF_CORE_COPY_REGS(elf_regs, regs) \
0042     int i, nregs = min(sizeof(*regs) / sizeof(unsigned long), \
0043                (size_t)ELF_NGREG);            \
0044     for (i = 0; i < nregs; i++) \
0045         elf_regs[i] = ((unsigned long *) regs)[i]; \
0046     memset(&elf_regs[i], 0, (ELF_NGREG - i) * sizeof(elf_regs[0]))
0047 
0048 /* Common routine for both 32-bit and 64-bit native processes */
0049 static inline void ppc_elf_core_copy_regs(elf_gregset_t elf_regs,
0050                       struct pt_regs *regs)
0051 {
0052     PPC_ELF_CORE_COPY_REGS(elf_regs, regs);
0053 }
0054 #define ELF_CORE_COPY_REGS(gregs, regs) ppc_elf_core_copy_regs(gregs, regs);
0055 
0056 /* ELF_HWCAP yields a mask that user programs can use to figure out what
0057    instruction set this cpu supports.  This could be done in userspace,
0058    but it's not easy, and we've already done it here.  */
0059 # define ELF_HWCAP  (cur_cpu_spec->cpu_user_features)
0060 # define ELF_HWCAP2 (cur_cpu_spec->cpu_user_features2)
0061 
0062 /* This yields a string that ld.so will use to load implementation
0063    specific libraries for optimization.  This is more specific in
0064    intent than poking at uname or /proc/cpuinfo.  */
0065 
0066 #define ELF_PLATFORM    (cur_cpu_spec->platform)
0067 
0068 /* While ELF_PLATFORM indicates the ISA supported by the platform, it
0069  * may not accurately reflect the underlying behavior of the hardware
0070  * (as in the case of running in Power5+ compatibility mode on a
0071  * Power6 machine).  ELF_BASE_PLATFORM allows ld.so to load libraries
0072  * that are tuned for the real hardware.
0073  */
0074 #define ELF_BASE_PLATFORM (powerpc_base_platform)
0075 
0076 #ifdef __powerpc64__
0077 # define ELF_PLAT_INIT(_r, load_addr)   do {    \
0078     _r->gpr[2] = load_addr;         \
0079 } while (0)
0080 #endif /* __powerpc64__ */
0081 
0082 #ifdef __powerpc64__
0083 # define SET_PERSONALITY(ex)                    \
0084 do {                                \
0085     if (((ex).e_flags & 0x3) == 2)              \
0086         set_thread_flag(TIF_ELF2ABI);           \
0087     else                            \
0088         clear_thread_flag(TIF_ELF2ABI);         \
0089     if ((ex).e_ident[EI_CLASS] == ELFCLASS32)       \
0090         set_thread_flag(TIF_32BIT);         \
0091     else                            \
0092         clear_thread_flag(TIF_32BIT);           \
0093     if (personality(current->personality) != PER_LINUX32)   \
0094         set_personality(PER_LINUX |         \
0095             (current->personality & (~PER_MASK)));  \
0096 } while (0)
0097 /*
0098  * An executable for which elf_read_implies_exec() returns TRUE will
0099  * have the READ_IMPLIES_EXEC personality flag set automatically. This
0100  * is only required to work around bugs in old 32bit toolchains. Since
0101  * the 64bit ABI has never had these issues dont enable the workaround
0102  * even if we have an executable stack.
0103  */
0104 # define elf_read_implies_exec(ex, exec_stk) (is_32bit_task() ? \
0105         (exec_stk == EXSTACK_DEFAULT) : 0)
0106 #else 
0107 # define elf_read_implies_exec(ex, exec_stk) (exec_stk == EXSTACK_DEFAULT)
0108 #endif /* __powerpc64__ */
0109 
0110 extern int dcache_bsize;
0111 extern int icache_bsize;
0112 extern int ucache_bsize;
0113 
0114 /* vDSO has arch_setup_additional_pages */
0115 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
0116 struct linux_binprm;
0117 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
0118                        int uses_interp);
0119 #define VDSO_AUX_ENT(a,b) NEW_AUX_ENT(a,b)
0120 
0121 /* 1GB for 64bit, 8MB for 32bit */
0122 #define STACK_RND_MASK (is_32bit_task() ? \
0123     (0x7ff >> (PAGE_SHIFT - 12)) : \
0124     (0x3ffff >> (PAGE_SHIFT - 12)))
0125 
0126 #ifdef CONFIG_SPU_BASE
0127 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
0128 #define NT_SPU      1
0129 
0130 #define ARCH_HAVE_EXTRA_ELF_NOTES
0131 
0132 #endif /* CONFIG_SPU_BASE */
0133 
0134 #ifdef CONFIG_PPC64
0135 
0136 #define get_cache_geometry(level) \
0137     (ppc64_caches.level.assoc << 16 | ppc64_caches.level.line_size)
0138 
0139 #define ARCH_DLINFO_CACHE_GEOMETRY                  \
0140     NEW_AUX_ENT(AT_L1I_CACHESIZE, ppc64_caches.l1i.size);       \
0141     NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, get_cache_geometry(l1i)); \
0142     NEW_AUX_ENT(AT_L1D_CACHESIZE, ppc64_caches.l1d.size);       \
0143     NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, get_cache_geometry(l1d)); \
0144     NEW_AUX_ENT(AT_L2_CACHESIZE, ppc64_caches.l2.size);     \
0145     NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, get_cache_geometry(l2));   \
0146     NEW_AUX_ENT(AT_L3_CACHESIZE, ppc64_caches.l3.size);     \
0147     NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, get_cache_geometry(l3))
0148 
0149 #else
0150 #define ARCH_DLINFO_CACHE_GEOMETRY
0151 #endif
0152 
0153 /*
0154  * The requirements here are:
0155  * - keep the final alignment of sp (sp & 0xf)
0156  * - make sure the 32-bit value at the first 16 byte aligned position of
0157  *   AUXV is greater than 16 for glibc compatibility.
0158  *   AT_IGNOREPPC is used for that.
0159  * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
0160  *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
0161  * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes
0162  */
0163 #define COMMON_ARCH_DLINFO                      \
0164 do {                                    \
0165     /* Handle glibc compatibility. */               \
0166     NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);            \
0167     NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);            \
0168     /* Cache size items */                      \
0169     NEW_AUX_ENT(AT_DCACHEBSIZE, dcache_bsize);          \
0170     NEW_AUX_ENT(AT_ICACHEBSIZE, icache_bsize);          \
0171     NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
0172     VDSO_AUX_ENT(AT_SYSINFO_EHDR, (unsigned long)current->mm->context.vdso);\
0173     ARCH_DLINFO_CACHE_GEOMETRY;                 \
0174 } while (0)
0175 
0176 #define ARCH_DLINFO                         \
0177 do {                                    \
0178     COMMON_ARCH_DLINFO;                     \
0179     NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size());       \
0180 } while (0)
0181 
0182 #define COMPAT_ARCH_DLINFO                      \
0183 do {                                    \
0184     COMMON_ARCH_DLINFO;                     \
0185     NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size_compat());    \
0186 } while (0)
0187 
0188 /* Relocate the kernel image to @final_address */
0189 void relocate(unsigned long final_address);
0190 
0191 struct func_desc {
0192     unsigned long addr;
0193     unsigned long toc;
0194     unsigned long env;
0195 };
0196 
0197 #endif /* _ASM_POWERPC_ELF_H */