1
0

ArchInfo.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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(__ARM_EABI__) || defined(__arm__)
  83. #if defined(Endian_BIG)
  84. #define ARCH ArchInfo_AUDIT_ARCH_ARMEB
  85. #define ARCHSTR "armeb"
  86. #elif defined(Endian_LITTLE)
  87. #define ARCH ArchInfo_AUDIT_ARCH_ARM
  88. #define ARCHSTR "armel"
  89. #else
  90. #error unknown endian
  91. #endif
  92. #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
  93. #define ARCH ArchInfo_AUDIT_ARCH_PPC64
  94. #define ARCHSTR "ppc64"
  95. #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
  96. #define ARCH ArchInfo_AUDIT_ARCH_PPC
  97. #define ARCHSTR "ppc"
  98. #elif defined(__sparcv9__) || defined(__sparcv9)
  99. #define ARCH ArchInfo_AUDIT_ARCH_SPARC64
  100. #define ARCHSTR "sparc64"
  101. Assert_compileTime(sizeof(long) == 8);
  102. #elif defined(__sparc_v8__)
  103. #define ARCH ArchInfo_AUDIT_ARCH_SPARC
  104. #define ARCHSTR "sparc"
  105. Assert_compileTime(sizeof(long) == 4);
  106. #elif defined(__sparc__) || defined(__sparc)
  107. #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
  108. #define ARCH ArchInfo_AUDIT_ARCH_SPARC64
  109. #define ARCHSTR "sparc64"
  110. #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
  111. #define ARCH ArchInfo_AUDIT_ARCH_SPARC
  112. #define ARCHSTR "sparc"
  113. #else
  114. #error unknown bit width
  115. #endif
  116. #elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
  117. #if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 8
  118. #if defined(Endian_BIG)
  119. #define ARCH ArchInfo_AUDIT_ARCH_MIPS64
  120. #define ARCHSTR "mips64"
  121. #elif defined(Endian_LITTLE)
  122. #define ARCH ArchInfo_AUDIT_ARCH_MIPSEL64
  123. #define ARCHSTR "mipsel64"
  124. #else
  125. #error unknown endian
  126. #endif
  127. #elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4
  128. #if defined(Endian_BIG)
  129. #define ARCH ArchInfo_AUDIT_ARCH_MIPS
  130. #define ARCHSTR "mips"
  131. #elif defined(Endian_LITTLE)
  132. #define ARCH ArchInfo_AUDIT_ARCH_MIPSEL
  133. #define ARCHSTR "mipsel"
  134. #else
  135. #error unknown endian
  136. #endif
  137. #else
  138. #error unknown bit width
  139. #endif
  140. #else
  141. #error architecture unknown
  142. #endif
  143. uint32_t ArchInfo_getAuditArch()
  144. {
  145. return ARCH;
  146. }
  147. char* ArchInfo_getArchStr()
  148. {
  149. return ARCHSTR;
  150. }