ArchInfo.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "util/ArchInfo.h"
  16. #include "util/Endian.h"
  17. /*
  18. Autogenerated list of arch-info, using the following:
  19. #include "linux/elf-em.h"
  20. #include "linux/audit.h"
  21. #include "stdio.h"
  22. #define EM_OPENRISC 92
  23. static const struct { char* name; unsigned int id; } archs[] = {
  24. #include "arch.x"
  25. {0}
  26. };
  27. int main()
  28. {
  29. int i;
  30. for (i=0; archs[i].name; i++) {
  31. printf("#define ArchInfo_%s 0x%08x\n", archs[i].name, archs[i].id);
  32. }
  33. return 0;
  34. }
  35. echo '#include "linux/audit.h"' | gcc -E -dM - | grep '#define AUDIT_ARCH' | \
  36. awk '{print "{ .name=\""$2"\", .id="$2" },"}' > arch.x
  37. gcc arch.c
  38. ./a.out
  39. */
  40. #define ArchInfo_AUDIT_ARCH_SPARC64 0x8000002b
  41. #define ArchInfo_AUDIT_ARCH_MIPS 0x00000008
  42. #define ArchInfo_AUDIT_ARCH_S390 0x00000016
  43. #define ArchInfo_AUDIT_ARCH_PPC64 0x80000015
  44. #define ArchInfo_AUDIT_ARCH_SHEL64 0xc000002a
  45. #define ArchInfo_AUDIT_ARCH_SH 0x0000002a
  46. #define ArchInfo_AUDIT_ARCH_PARISC64 0x8000000f
  47. #define ArchInfo_AUDIT_ARCH_MIPSEL64 0xc0000008
  48. #define ArchInfo_AUDIT_ARCH_MIPS64N32 0xa0000008
  49. #define ArchInfo_AUDIT_ARCH_IA64 0xc0000032
  50. #define ArchInfo_AUDIT_ARCH_PARISC 0x0000000f
  51. #define ArchInfo_AUDIT_ARCH_MIPS64 0x80000008
  52. #define ArchInfo_AUDIT_ARCH_PPC64LE 0xc0000015
  53. #define ArchInfo_AUDIT_ARCH_ALPHA 0xc0009026
  54. #define ArchInfo_AUDIT_ARCH_MIPSEL 0x40000008
  55. #define ArchInfo_AUDIT_ARCH_SPARC 0x00000002
  56. #define ArchInfo_AUDIT_ARCH_I386 0x40000003
  57. #define ArchInfo_AUDIT_ARCH_OPENRISC 0x0000005c
  58. #define ArchInfo_AUDIT_ARCH_AARCH64 0xc00000b7
  59. #define ArchInfo_AUDIT_ARCH_FRV 0x00005441
  60. #define ArchInfo_AUDIT_ARCH_ARM 0x40000028
  61. #define ArchInfo_AUDIT_ARCH_X86_64 0xc000003e
  62. #define ArchInfo_AUDIT_ARCH_ARMEB 0x00000028
  63. #define ArchInfo_AUDIT_ARCH_M68K 0x00000004
  64. #define ArchInfo_AUDIT_ARCH_S390X 0x80000016
  65. #define ArchInfo_AUDIT_ARCH_PPC 0x00000014
  66. #define ArchInfo_AUDIT_ARCH_SH64 0x8000002a
  67. #define ArchInfo_AUDIT_ARCH_MIPSEL64N32 0xe0000008
  68. #define ArchInfo_AUDIT_ARCH_SHEL 0x4000002a
  69. #define ArchInfo_AUDIT_ARCH_M32R 0x00000058
  70. #define ArchInfo_AUDIT_ARCH_CRIS 0x4000004c
  71. /**
  72. * Manually generated detection routine...
  73. */
  74. #if defined(__amd64__) || defined(__x86_64__) || defined(__AMD64__) || \
  75. defined(_M_X64) || defined(__amd64)
  76. #define ARCH ArchInfo_AUDIT_ARCH_X86_64
  77. #define ARCHSTR "amd64"
  78. #elif defined(__i386__) || defined(__x86__) || defined(__X86__) || \
  79. defined(_M_IX86) || defined(__i386)
  80. #define ARCH ArchInfo_AUDIT_ARCH_I386
  81. #define ARCHSTR "i386"
  82. #elif defined(__aarch64__)
  83. #define ARCH ArchInfo_AUDIT_ARCH_AARCH64
  84. #define ARCHSTR "arm64"
  85. #elif defined(__ARM_EABI__) || defined(__arm__)
  86. #if defined(Endian_BIG)
  87. #define ARCH ArchInfo_AUDIT_ARCH_ARMEB
  88. #define ARCHSTR "armeb"
  89. #elif defined(Endian_LITTLE)
  90. #define ARCH ArchInfo_AUDIT_ARCH_ARM
  91. #define ARCHSTR "armel"
  92. #else
  93. #error unknown endian
  94. #endif
  95. #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
  96. #define ARCH ArchInfo_AUDIT_ARCH_PPC64
  97. #define ARCHSTR "ppc64"
  98. #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
  99. #define ARCH ArchInfo_AUDIT_ARCH_PPC
  100. #define ARCHSTR "ppc"
  101. #elif defined(__sparcv9__) || defined(__sparcv9)
  102. #define ARCH ArchInfo_AUDIT_ARCH_SPARC64
  103. #define ARCHSTR "sparc64"
  104. Assert_compileTime(sizeof(long) == 8);
  105. #elif defined(__sparc_v8__)
  106. #define ARCH ArchInfo_AUDIT_ARCH_SPARC
  107. #define ARCHSTR "sparc"
  108. Assert_compileTime(sizeof(long) == 4);
  109. #elif defined(__sparc__) || defined(__sparc)
  110. #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
  111. #define ARCH ArchInfo_AUDIT_ARCH_SPARC64
  112. #define ARCHSTR "sparc64"
  113. #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
  114. #define ARCH ArchInfo_AUDIT_ARCH_SPARC
  115. #define ARCHSTR "sparc"
  116. #else
  117. #error unknown bit width
  118. #endif
  119. #elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
  120. #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
  121. #if defined(Endian_BIG)
  122. #define ARCH ArchInfo_AUDIT_ARCH_MIPS64
  123. #define ARCHSTR "mips64"
  124. #elif defined(Endian_LITTLE)
  125. #define ARCH ArchInfo_AUDIT_ARCH_MIPSEL64
  126. #define ARCHSTR "mipsel64"
  127. #else
  128. #error unknown endian
  129. #endif
  130. #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
  131. #if defined(Endian_BIG)
  132. #define ARCH ArchInfo_AUDIT_ARCH_MIPS
  133. #define ARCHSTR "mips"
  134. #elif defined(Endian_LITTLE)
  135. #define ARCH ArchInfo_AUDIT_ARCH_MIPSEL
  136. #define ARCHSTR "mipsel"
  137. #else
  138. #error unknown endian
  139. #endif
  140. #else
  141. #error unknown bit width
  142. #endif
  143. #else
  144. #error architecture unknown
  145. #endif
  146. uint32_t ArchInfo_getAuditArch()
  147. {
  148. return ARCH;
  149. }
  150. char* ArchInfo_getArchStr()
  151. {
  152. return ARCHSTR;
  153. }