1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6// This program determines which architectures that this Valgrind installation
7// supports, which depends on the what was chosen at configure-time.  For
8// example, if Valgrind is installed on an AMD64 machine but has been
9// configured with --enable-only32bit then this program will match "x86" but
10// not "amd64".
11//
12// We return:
13// - 0 if the machine matches the asked-for arch
14// - 1 if it doesn't match but does match the name of another arch
15// - 2 if it doesn't match the name of any arch
16// - 3 if there was a usage error (it also prints an error message)
17
18// Nb: When updating this file for a new architecture, add the name to
19// 'all_archs' as well as adding go().
20
21#define False  0
22#define True   1
23typedef int    Bool;
24
25char* all_archs[] = {
26   "x86",
27   "amd64",
28   "ppc32",
29   "ppc64",
30   "ppc64le",
31   "arm",
32   "arm64",
33   "s390x",
34   "mips32",
35   "mips64",
36   "tilegx",
37   NULL
38};
39
40static Bool go(char* arch)
41{
42#if defined(VGP_x86_linux) || defined(VGP_x86_darwin)
43   if ( 0 == strcmp( arch, "x86"   ) ) return True;
44
45#elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin)
46#if defined(VGA_SEC_x86)
47   if ( 0 == strcmp( arch, "x86"   ) ) return True;
48#endif
49   if ( 0 == strcmp( arch, "amd64" ) ) return True;
50
51#elif defined(VGP_ppc32_linux)
52   if ( 0 == strcmp( arch, "ppc32" ) ) return True;
53
54#elif defined(VGP_ppc64be_linux)
55   if ( 0 == strcmp( arch, "ppc64" ) ) return True;
56#if defined(VGA_SEC_ppc32)
57   if ( 0 == strcmp( arch, "ppc32" ) ) return True;
58#endif
59
60#elif defined(VGP_ppc64le_linux)
61   if ( 0 == strcmp( arch, "ppc64" ) ) return True;
62
63#elif defined(VGP_s390x_linux)
64   if ( 0 == strcmp( arch, "s390x" ) ) return True;
65
66#elif defined(VGP_arm_linux)
67   if ( 0 == strcmp( arch, "arm" ) ) return True;
68
69#elif defined(VGP_arm64_linux)
70   if ( 0 == strcmp( arch, "arm64" ) ) return True;
71
72#elif defined(VGP_mips32_linux)
73   if ( 0 == strcmp( arch, "mips32" ) ) return True;
74
75#elif defined(VGP_mips64_linux)
76   if ( 0 == strcmp( arch, "mips64" ) ) return True;
77
78#elif defined(VGP_tilegx_linux)
79   if ( 0 == strcmp( arch, "tilegx" ) ) return True;
80
81#else
82#  error Unknown platform
83#endif   // VGP_*
84
85   return False;
86}
87
88//---------------------------------------------------------------------------
89// main
90//---------------------------------------------------------------------------
91int main(int argc, char **argv)
92{
93   int i;
94   if ( argc != 2 ) {
95      fprintf( stderr, "usage: arch_test <arch-type>\n" );
96      exit(3);             // Usage error.
97   }
98   if (go( argv[1] )) {
99      return 0;            // Matched.
100   }
101   for (i = 0; NULL != all_archs[i]; i++) {
102      if ( 0 == strcmp( argv[1], all_archs[i] ) )
103         return 1;         // Didn't match, but named another arch.
104   }
105   return 2;               // Didn't match any archs.
106}
107