binfmt_elf32.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * binfmt_elf32.c: Support 32-bit Sparc ELF binaries on Ultra.
  3. *
  4. * Copyright (C) 1995, 1996, 1997, 1998 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 1995, 1996, 1997, 1998 Jakub Jelinek (jj@ultra.linux.cz)
  6. */
  7. #define ELF_ARCH EM_SPARC
  8. #define ELF_CLASS ELFCLASS32
  9. #define ELF_DATA ELFDATA2MSB;
  10. /* For the most part we present code dumps in the format
  11. * Solaris does.
  12. */
  13. typedef unsigned int elf_greg_t;
  14. #define ELF_NGREG 38
  15. typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  16. /* Format is:
  17. * G0 --> G7
  18. * O0 --> O7
  19. * L0 --> L7
  20. * I0 --> I7
  21. * PSR, PC, nPC, Y, WIM, TBR
  22. */
  23. #include <asm/psrcompat.h>
  24. #define ELF_CORE_COPY_REGS(__elf_regs, __pt_regs) \
  25. do { unsigned int *dest = &(__elf_regs[0]); \
  26. struct pt_regs *src = (__pt_regs); \
  27. unsigned int __user *sp; \
  28. int i; \
  29. for(i = 0; i < 16; i++) \
  30. dest[i] = (unsigned int) src->u_regs[i];\
  31. /* Don't try this at home kids... */ \
  32. sp = (unsigned int __user *) (src->u_regs[14] & \
  33. 0x00000000fffffffc); \
  34. for(i = 0; i < 16; i++) \
  35. __get_user(dest[i+16], &sp[i]); \
  36. dest[32] = tstate_to_psr(src->tstate); \
  37. dest[33] = (unsigned int) src->tpc; \
  38. dest[34] = (unsigned int) src->tnpc; \
  39. dest[35] = src->y; \
  40. dest[36] = dest[37] = 0; /* XXX */ \
  41. } while(0);
  42. typedef struct {
  43. union {
  44. unsigned int pr_regs[32];
  45. unsigned long pr_dregs[16];
  46. } pr_fr;
  47. unsigned int __unused;
  48. unsigned int pr_fsr;
  49. unsigned char pr_qcnt;
  50. unsigned char pr_q_entrysize;
  51. unsigned char pr_en;
  52. unsigned int pr_q[64];
  53. } elf_fpregset_t;
  54. /* UltraSparc extensions. Still unused, but will be eventually. */
  55. typedef struct {
  56. unsigned int pr_type;
  57. unsigned int pr_align;
  58. union {
  59. struct {
  60. union {
  61. unsigned int pr_regs[32];
  62. unsigned long pr_dregs[16];
  63. long double pr_qregs[8];
  64. } pr_xfr;
  65. } pr_v8p;
  66. unsigned int pr_xfsr;
  67. unsigned int pr_fprs;
  68. unsigned int pr_xg[8];
  69. unsigned int pr_xo[8];
  70. unsigned long pr_tstate;
  71. unsigned int pr_filler[8];
  72. } pr_un;
  73. } elf_xregset_t;
  74. #define elf_check_arch(x) (((x)->e_machine == EM_SPARC) || ((x)->e_machine == EM_SPARC32PLUS))
  75. #define ELF_ET_DYN_BASE 0x70000000
  76. #include <asm/processor.h>
  77. #include <linux/module.h>
  78. #include <linux/config.h>
  79. #include <linux/elfcore.h>
  80. #include <linux/compat.h>
  81. #define elf_prstatus elf_prstatus32
  82. struct elf_prstatus32
  83. {
  84. struct elf_siginfo pr_info; /* Info associated with signal */
  85. short pr_cursig; /* Current signal */
  86. unsigned int pr_sigpend; /* Set of pending signals */
  87. unsigned int pr_sighold; /* Set of held signals */
  88. pid_t pr_pid;
  89. pid_t pr_ppid;
  90. pid_t pr_pgrp;
  91. pid_t pr_sid;
  92. struct compat_timeval pr_utime; /* User time */
  93. struct compat_timeval pr_stime; /* System time */
  94. struct compat_timeval pr_cutime; /* Cumulative user time */
  95. struct compat_timeval pr_cstime; /* Cumulative system time */
  96. elf_gregset_t pr_reg; /* GP registers */
  97. int pr_fpvalid; /* True if math co-processor being used. */
  98. };
  99. #define elf_prpsinfo elf_prpsinfo32
  100. struct elf_prpsinfo32
  101. {
  102. char pr_state; /* numeric process state */
  103. char pr_sname; /* char for pr_state */
  104. char pr_zomb; /* zombie */
  105. char pr_nice; /* nice val */
  106. unsigned int pr_flag; /* flags */
  107. u16 pr_uid;
  108. u16 pr_gid;
  109. pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
  110. /* Lots missing */
  111. char pr_fname[16]; /* filename of executable */
  112. char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
  113. };
  114. #include <linux/highuid.h>
  115. #undef NEW_TO_OLD_UID
  116. #undef NEW_TO_OLD_GID
  117. #define NEW_TO_OLD_UID(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
  118. #define NEW_TO_OLD_GID(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
  119. #include <linux/time.h>
  120. #undef cputime_to_timeval
  121. #define cputime_to_timeval cputime_to_compat_timeval
  122. static __inline__ void
  123. cputime_to_compat_timeval(const cputime_t cputime, struct compat_timeval *value)
  124. {
  125. unsigned long jiffies = cputime_to_jiffies(cputime);
  126. value->tv_usec = (jiffies % HZ) * (1000000L / HZ);
  127. value->tv_sec = jiffies / HZ;
  128. }
  129. #define elf_addr_t u32
  130. #undef start_thread
  131. #define start_thread start_thread32
  132. #define init_elf_binfmt init_elf32_binfmt
  133. MODULE_DESCRIPTION("Binary format loader for compatibility with 32bit SparcLinux binaries on the Ultra");
  134. MODULE_AUTHOR("Eric Youngdale, David S. Miller, Jakub Jelinek");
  135. #undef MODULE_DESCRIPTION
  136. #undef MODULE_AUTHOR
  137. #undef TASK_SIZE
  138. #define TASK_SIZE 0xf0000000
  139. #include "../../../fs/binfmt_elf.c"