binfmt_elfo32.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Support for o32 Linux/MIPS ELF binaries.
  4. * Author: Ralf Baechle (ralf@linux-mips.org)
  5. *
  6. * Copyright (C) 1999, 2001 Ralf Baechle
  7. * Copyright (C) 1999, 2001 Silicon Graphics, Inc.
  8. *
  9. * Heavily inspired by the 32-bit Sparc compat code which is
  10. * Copyright (C) 1995, 1996, 1997, 1998 David S. Miller (davem@redhat.com)
  11. * Copyright (C) 1995, 1996, 1997, 1998 Jakub Jelinek (jj@ultra.linux.cz)
  12. */
  13. #define ELF_ARCH EM_MIPS
  14. #define ELF_CLASS ELFCLASS32
  15. #ifdef __MIPSEB__
  16. #define ELF_DATA ELFDATA2MSB;
  17. #else /* __MIPSEL__ */
  18. #define ELF_DATA ELFDATA2LSB;
  19. #endif
  20. /* ELF register definitions */
  21. #define ELF_NGREG 45
  22. #define ELF_NFPREG 33
  23. typedef unsigned int elf_greg_t;
  24. typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  25. typedef double elf_fpreg_t;
  26. typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
  27. /*
  28. * This is used to ensure we don't load something for the wrong architecture.
  29. */
  30. #define elf_check_arch elfo32_check_arch
  31. #ifdef CONFIG_KVM_GUEST
  32. #define TASK32_SIZE 0x3fff8000UL
  33. #else
  34. #define TASK32_SIZE 0x7fff8000UL
  35. #endif
  36. #undef ELF_ET_DYN_BASE
  37. #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
  38. #include <asm/processor.h>
  39. #include <linux/elfcore.h>
  40. #include <linux/compat.h>
  41. #include <linux/math64.h>
  42. #define elf_prstatus elf_prstatus32
  43. struct elf_prstatus32
  44. {
  45. struct elf_siginfo pr_info; /* Info associated with signal */
  46. short pr_cursig; /* Current signal */
  47. unsigned int pr_sigpend; /* Set of pending signals */
  48. unsigned int pr_sighold; /* Set of held signals */
  49. pid_t pr_pid;
  50. pid_t pr_ppid;
  51. pid_t pr_pgrp;
  52. pid_t pr_sid;
  53. struct old_timeval32 pr_utime; /* User time */
  54. struct old_timeval32 pr_stime; /* System time */
  55. struct old_timeval32 pr_cutime;/* Cumulative user time */
  56. struct old_timeval32 pr_cstime;/* Cumulative system time */
  57. elf_gregset_t pr_reg; /* GP registers */
  58. int pr_fpvalid; /* True if math co-processor being used. */
  59. };
  60. #define elf_prpsinfo elf_prpsinfo32
  61. struct elf_prpsinfo32
  62. {
  63. char pr_state; /* numeric process state */
  64. char pr_sname; /* char for pr_state */
  65. char pr_zomb; /* zombie */
  66. char pr_nice; /* nice val */
  67. unsigned int pr_flag; /* flags */
  68. __kernel_uid_t pr_uid;
  69. __kernel_gid_t pr_gid;
  70. pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
  71. /* Lots missing */
  72. char pr_fname[16]; /* filename of executable */
  73. char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
  74. };
  75. #define elf_caddr_t u32
  76. #define init_elf_binfmt init_elf32_binfmt
  77. #define jiffies_to_timeval jiffies_to_old_timeval32
  78. static inline void
  79. jiffies_to_old_timeval32(unsigned long jiffies, struct old_timeval32 *value)
  80. {
  81. /*
  82. * Convert jiffies to nanoseconds and separate with
  83. * one divide.
  84. */
  85. u64 nsec = (u64)jiffies * TICK_NSEC;
  86. u32 rem;
  87. value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
  88. value->tv_usec = rem / NSEC_PER_USEC;
  89. }
  90. #undef TASK_SIZE
  91. #define TASK_SIZE TASK_SIZE32
  92. #undef ns_to_timeval
  93. #define ns_to_timeval ns_to_old_timeval32
  94. #include "../../../fs/binfmt_elf.c"