Path: blob/master/arch/mips/kernel/binfmt_elfo32.c
10820 views
/*1* Support for o32 Linux/MIPS ELF binaries.2*3* Copyright (C) 1999, 2001 Ralf Baechle4* Copyright (C) 1999, 2001 Silicon Graphics, Inc.5*6* Heavily inspired by the 32-bit Sparc compat code which is7* Copyright (C) 1995, 1996, 1997, 1998 David S. Miller ([email protected])8* Copyright (C) 1995, 1996, 1997, 1998 Jakub Jelinek ([email protected])9*/1011#define ELF_ARCH EM_MIPS12#define ELF_CLASS ELFCLASS3213#ifdef __MIPSEB__14#define ELF_DATA ELFDATA2MSB;15#else /* __MIPSEL__ */16#define ELF_DATA ELFDATA2LSB;17#endif1819/* ELF register definitions */20#define ELF_NGREG 4521#define ELF_NFPREG 332223typedef unsigned int elf_greg_t;24typedef elf_greg_t elf_gregset_t[ELF_NGREG];2526typedef double elf_fpreg_t;27typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];2829/*30* This is used to ensure we don't load something for the wrong architecture.31*/32#define elf_check_arch(hdr) \33({ \34int __res = 1; \35struct elfhdr *__h = (hdr); \36\37if (__h->e_machine != EM_MIPS) \38__res = 0; \39if (__h->e_ident[EI_CLASS] != ELFCLASS32) \40__res = 0; \41if ((__h->e_flags & EF_MIPS_ABI2) != 0) \42__res = 0; \43if (((__h->e_flags & EF_MIPS_ABI) != 0) && \44((__h->e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32)) \45__res = 0; \46\47__res; \48})4950#define TASK32_SIZE 0x7fff8000UL51#undef ELF_ET_DYN_BASE52#define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)5354#include <asm/processor.h>5556/*57* When this file is selected, we are definitely running a 64bit kernel.58* So using the right regs define in asm/reg.h59*/60#define WANT_COMPAT_REG_H6162/* These MUST be defined before elf.h gets included */63extern void elf32_core_copy_regs(elf_gregset_t grp, struct pt_regs *regs);64#define ELF_CORE_COPY_REGS(_dest, _regs) elf32_core_copy_regs(_dest, _regs);65#define ELF_CORE_COPY_TASK_REGS(_tsk, _dest) \66({ \67int __res = 1; \68elf32_core_copy_regs(*(_dest), task_pt_regs(_tsk)); \69__res; \70})7172#include <linux/module.h>73#include <linux/elfcore.h>74#include <linux/compat.h>75#include <linux/math64.h>7677#define elf_prstatus elf_prstatus3278struct elf_prstatus3279{80struct elf_siginfo pr_info; /* Info associated with signal */81short pr_cursig; /* Current signal */82unsigned int pr_sigpend; /* Set of pending signals */83unsigned int pr_sighold; /* Set of held signals */84pid_t pr_pid;85pid_t pr_ppid;86pid_t pr_pgrp;87pid_t pr_sid;88struct compat_timeval pr_utime; /* User time */89struct compat_timeval pr_stime; /* System time */90struct compat_timeval pr_cutime;/* Cumulative user time */91struct compat_timeval pr_cstime;/* Cumulative system time */92elf_gregset_t pr_reg; /* GP registers */93int pr_fpvalid; /* True if math co-processor being used. */94};9596#define elf_prpsinfo elf_prpsinfo3297struct elf_prpsinfo3298{99char pr_state; /* numeric process state */100char pr_sname; /* char for pr_state */101char pr_zomb; /* zombie */102char pr_nice; /* nice val */103unsigned int pr_flag; /* flags */104__kernel_uid_t pr_uid;105__kernel_gid_t pr_gid;106pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;107/* Lots missing */108char pr_fname[16]; /* filename of executable */109char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */110};111112#define elf_caddr_t u32113#define init_elf_binfmt init_elf32_binfmt114115#define jiffies_to_timeval jiffies_to_compat_timeval116static inline void117jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)118{119/*120* Convert jiffies to nanoseconds and separate with121* one divide.122*/123u64 nsec = (u64)jiffies * TICK_NSEC;124u32 rem;125value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);126value->tv_usec = rem / NSEC_PER_USEC;127}128129void elf32_core_copy_regs(elf_gregset_t grp, struct pt_regs *regs)130{131int i;132133for (i = 0; i < EF_R0; i++)134grp[i] = 0;135grp[EF_R0] = 0;136for (i = 1; i <= 31; i++)137grp[EF_R0 + i] = (elf_greg_t) regs->regs[i];138grp[EF_R26] = 0;139grp[EF_R27] = 0;140grp[EF_LO] = (elf_greg_t) regs->lo;141grp[EF_HI] = (elf_greg_t) regs->hi;142grp[EF_CP0_EPC] = (elf_greg_t) regs->cp0_epc;143grp[EF_CP0_BADVADDR] = (elf_greg_t) regs->cp0_badvaddr;144grp[EF_CP0_STATUS] = (elf_greg_t) regs->cp0_status;145grp[EF_CP0_CAUSE] = (elf_greg_t) regs->cp0_cause;146#ifdef EF_UNUSED0147grp[EF_UNUSED0] = 0;148#endif149}150151MODULE_DESCRIPTION("Binary format loader for compatibility with o32 Linux/MIPS binaries");152MODULE_AUTHOR("Ralf Baechle ([email protected])");153154#undef MODULE_DESCRIPTION155#undef MODULE_AUTHOR156157#undef TASK_SIZE158#define TASK_SIZE TASK_SIZE32159160#include "../../../fs/binfmt_elf.c"161162163