linux-old/arch/s390x/kernel/binfmt_elf32.c
<<
>>
Prefs
   1/*
   2 * Support for 32-bit Linux for S390 ELF binaries.
   3 *
   4 * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
   5 * Author(s): Gerhard Tonn (ton@de.ibm.com)
   6 *
   7 * Heavily inspired by the 32-bit Sparc compat code which is
   8 * Copyright (C) 1995, 1996, 1997, 1998 David S. Miller (davem@redhat.com)
   9 * Copyright (C) 1995, 1996, 1997, 1998 Jakub Jelinek   (jj@ultra.linux.cz)
  10 */
  11
  12
  13#define __ASMS390_ELF_H
  14
  15/*
  16 * These are used to set parameters in the core dumps.
  17 */
  18#define ELF_CLASS       ELFCLASS32
  19#define ELF_DATA        ELFDATA2MSB
  20#define ELF_ARCH        EM_S390
  21
  22/*
  23 * This is used to ensure we don't load something for the wrong architecture.
  24 */
  25#define elf_check_arch(x) \
  26        (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
  27         && (x)->e_ident[EI_CLASS] == ELF_CLASS)
  28
  29/* ELF register definitions */
  30#define NUM_GPRS      16
  31#define NUM_FPRS      16
  32#define NUM_ACRS      16    
  33
  34#define TASK31_SIZE             (0x80000000UL)
  35
  36/* For SVR4/S390 the function pointer to be registered with `atexit` is
  37   passed in R14. */
  38#define ELF_PLAT_INIT(_r, load_addr) \
  39        do { \
  40        _r->gprs[14] = 0; \
  41        current->thread.flags |= S390_FLAG_31BIT; \
  42        } while(0)
  43
  44#define USE_ELF_CORE_DUMP
  45#define ELF_EXEC_PAGESIZE       4096
  46
  47/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
  48   use of this is to invoke "./ld.so someprog" to test out a new version of
  49   the loader.  We need to make sure that it is out of the way of the program
  50   that it will "exec", and that there is sufficient room for the brk.  */
  51
  52#define ELF_ET_DYN_BASE         ((TASK31_SIZE & 0x80000000) \
  53                                ? TASK31_SIZE / 3 * 2 \
  54                                : 2 * TASK31_SIZE / 3)     
  55
  56/* Wow, the "main" arch needs arch dependent functions too.. :) */
  57
  58/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
  59   now struct_user_regs, they are different) */
  60
  61#define ELF_CORE_COPY_REGS(pr_reg, regs)        \
  62        { \
  63        int i; \
  64        memcpy(&pr_reg.psw.mask, &regs->psw.mask, 4); \
  65        memcpy(&pr_reg.psw.addr, ((char*)&regs->psw.addr)+4, 4); \
  66        for(i=0; i<NUM_GPRS; i++) \
  67                pr_reg.gprs[i] = regs->gprs[i]; \
  68        for(i=0; i<NUM_ACRS; i++) \
  69                pr_reg.acrs[i] = regs->acrs[i]; \
  70        pr_reg.orig_gpr2 = regs->orig_gpr2; \
  71        }
  72
  73
  74
  75/* This yields a mask that user programs can use to figure out what
  76   instruction set this CPU supports. */
  77
  78#define ELF_HWCAP (0)
  79
  80/* This yields a string that ld.so will use to load implementation
  81   specific libraries for optimization.  This is more specific in
  82   intent than poking at uname or /proc/cpuinfo.
  83
  84   For the moment, we have only optimizations for the Intel generations,
  85   but that could change... */
  86
  87#define ELF_PLATFORM (NULL)
  88
  89#ifdef __KERNEL__
  90#define SET_PERSONALITY(ex, ibcs2)                      \
  91do {                                                    \
  92        if (ibcs2)                                      \
  93                set_personality(PER_SVR4);              \
  94        else if (current->personality != PER_LINUX32)   \
  95                set_personality(PER_LINUX);             \
  96} while (0)
  97#endif 
  98
  99#include "linux32.h"
 100
 101typedef _s390_fp_regs32 elf_fpregset_t;
 102
 103typedef struct
 104{
 105        
 106        _psw_t32        psw;
 107        __u32           gprs[__NUM_GPRS]; 
 108        __u32           acrs[__NUM_ACRS]; 
 109        __u32           orig_gpr2;
 110} s390_regs32;
 111typedef s390_regs32 elf_gregset_t;
 112
 113#include <asm/processor.h>
 114#include <linux/module.h>
 115#include <linux/config.h>
 116#include <linux/elfcore.h>
 117
 118int setup_arg_pages32(struct linux_binprm *bprm);
 119
 120struct timeval32
 121{
 122    int tv_sec, tv_usec;
 123};
 124
 125#define elf_prstatus elf_prstatus32
 126struct elf_prstatus32
 127{
 128        struct elf_siginfo pr_info;     /* Info associated with signal */
 129        short   pr_cursig;              /* Current signal */
 130        u32     pr_sigpend;     /* Set of pending signals */
 131        u32     pr_sighold;     /* Set of held signals */
 132        pid_t   pr_pid;
 133        pid_t   pr_ppid;
 134        pid_t   pr_pgrp;
 135        pid_t   pr_sid;
 136        struct timeval32 pr_utime;      /* User time */
 137        struct timeval32 pr_stime;      /* System time */
 138        struct timeval32 pr_cutime;     /* Cumulative user time */
 139        struct timeval32 pr_cstime;     /* Cumulative system time */
 140        elf_gregset_t pr_reg;   /* GP registers */
 141        int pr_fpvalid;         /* True if math co-processor being used.  */
 142};
 143
 144#define elf_prpsinfo elf_prpsinfo32
 145struct elf_prpsinfo32
 146{
 147        char    pr_state;       /* numeric process state */
 148        char    pr_sname;       /* char for pr_state */
 149        char    pr_zomb;        /* zombie */
 150        char    pr_nice;        /* nice val */
 151        u32     pr_flag;        /* flags */
 152        u16     pr_uid;
 153        u16     pr_gid;
 154        pid_t   pr_pid, pr_ppid, pr_pgrp, pr_sid;
 155        /* Lots missing */
 156        char    pr_fname[16];   /* filename of executable */
 157        char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
 158};
 159
 160#include <linux/highuid.h>
 161
 162#undef NEW_TO_OLD_UID
 163#undef NEW_TO_OLD_GID
 164#define NEW_TO_OLD_UID(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
 165#define NEW_TO_OLD_GID(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid) 
 166
 167#define elf_addr_t      u32
 168#define elf_caddr_t     u32
 169/*
 170#define init_elf_binfmt init_elf32_binfmt
 171*/
 172#undef CONFIG_BINFMT_ELF
 173#ifdef CONFIG_BINFMT_ELF32
 174#define CONFIG_BINFMT_ELF CONFIG_BINFMT_ELF32
 175#endif
 176#undef CONFIG_BINFMT_ELF_MODULE
 177#ifdef CONFIG_BINFMT_ELF32_MODULE
 178#define CONFIG_BINFMT_ELF_MODULE CONFIG_BINFMT_ELF32_MODULE
 179#endif
 180
 181#undef start_thread
 182#define start_thread                    start_thread31 
 183#define setup_arg_pages(bprm)           setup_arg_pages32(bprm)
 184#define elf_map                         elf_map32
 185
 186MODULE_DESCRIPTION("Binary format loader for compatibility with 32bit Linux for S390 binaries,"
 187                   " Copyright 2000 IBM Corporation"); 
 188MODULE_AUTHOR("Gerhard Tonn <ton@de.ibm.com>");
 189
 190#undef MODULE_DESCRIPTION
 191#undef MODULE_AUTHOR
 192
 193#include "../../../fs/binfmt_elf.c"
 194
 195static unsigned long
 196elf_map32 (struct file *filep, unsigned long addr, struct elf_phdr *eppnt, int prot, int type)
 197{
 198        unsigned long map_addr;
 199
 200        if(!addr)
 201                addr = 0x40000000;
 202
 203        down_write(&current->mm->mmap_sem);
 204        map_addr = do_mmap(filep, ELF_PAGESTART(addr),
 205                           eppnt->p_filesz + ELF_PAGEOFFSET(eppnt->p_vaddr), prot, type,
 206                           eppnt->p_offset - ELF_PAGEOFFSET(eppnt->p_vaddr));
 207        up_write(&current->mm->mmap_sem);
 208        return(map_addr);
 209}
 210
 211
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.