blob: d83f0e550769ade189917ef6ab620d150c3bd4a1 [file] [log] [blame]
njn61485ab2009-03-04 04:15:16 +00001
nethercote288b7662004-01-20 09:24:53 +00002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
njn61485ab2009-03-04 04:15:16 +00006// 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".
njn7fd6d382009-01-22 21:56:32 +000011//
nethercote362c0d22004-11-18 18:21:56 +000012// We return:
njn61485ab2009-03-04 04:15:16 +000013// - 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)
nethercote362c0d22004-11-18 18:21:56 +000017
njn7fd6d382009-01-22 21:56:32 +000018// Nb: When updating this file for a new architecture, add the name to
nethercote362c0d22004-11-18 18:21:56 +000019// 'all_archs' as well as adding go().
20
21#define False 0
22#define True 1
23typedef int Bool;
24
25char* all_archs[] = {
njn61485ab2009-03-04 04:15:16 +000026 "x86",
nethercote362c0d22004-11-18 18:21:56 +000027 "amd64",
njn10c122e2005-09-13 00:45:14 +000028 "ppc32",
sewardj0d4f8ac2006-01-02 16:24:03 +000029 "ppc64",
carll582d5822014-08-07 23:35:54 +000030 "ppc64le",
sewardjf08adb62010-01-04 10:31:41 +000031 "arm",
sewardj15e4e5c2014-08-26 21:06:31 +000032 "arm64",
sewardjb5b87402011-03-07 16:05:35 +000033 "s390x",
sewardj5db15402012-06-07 09:13:21 +000034 "mips32",
petarj4df0bfc2013-02-27 23:17:33 +000035 "mips64",
sewardj112711a2015-04-10 12:30:09 +000036 "tilegx",
nethercote362c0d22004-11-18 18:21:56 +000037 NULL
38};
nethercoteb625bcb2004-10-19 16:29:30 +000039
njn61485ab2009-03-04 04:15:16 +000040static Bool go(char* arch)
nethercoteb625bcb2004-10-19 16:29:30 +000041{
sewardj8eb8bab2015-07-21 14:44:28 +000042#if defined(VGP_x86_linux) || defined(VGP_x86_darwin) \
43 || defined(VGP_x86_solaris)
njn61485ab2009-03-04 04:15:16 +000044 if ( 0 == strcmp( arch, "x86" ) ) return True;
nethercote288b7662004-01-20 09:24:53 +000045
sewardj8eb8bab2015-07-21 14:44:28 +000046#elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) \
47 || defined(VGP_amd64_solaris)
florian5bdb9ec2012-05-06 03:51:00 +000048#if defined(VGA_SEC_x86)
njn61485ab2009-03-04 04:15:16 +000049 if ( 0 == strcmp( arch, "x86" ) ) return True;
florian5bdb9ec2012-05-06 03:51:00 +000050#endif
njn61485ab2009-03-04 04:15:16 +000051 if ( 0 == strcmp( arch, "amd64" ) ) return True;
52
53#elif defined(VGP_ppc32_linux)
54 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
55
carllcae0cc22014-08-07 23:17:29 +000056#elif defined(VGP_ppc64be_linux)
njn61485ab2009-03-04 04:15:16 +000057 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
florian5bdb9ec2012-05-06 03:51:00 +000058#if defined(VGA_SEC_ppc32)
njn61485ab2009-03-04 04:15:16 +000059 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
florian5bdb9ec2012-05-06 03:51:00 +000060#endif
njn61485ab2009-03-04 04:15:16 +000061
carll582d5822014-08-07 23:35:54 +000062#elif defined(VGP_ppc64le_linux)
63 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
64
sewardjb5b87402011-03-07 16:05:35 +000065#elif defined(VGP_s390x_linux)
66 if ( 0 == strcmp( arch, "s390x" ) ) return True;
67
sewardj59570ff2010-01-01 11:59:33 +000068#elif defined(VGP_arm_linux)
69 if ( 0 == strcmp( arch, "arm" ) ) return True;
70
sewardj599cd7a2014-03-01 11:20:33 +000071#elif defined(VGP_arm64_linux)
72 if ( 0 == strcmp( arch, "arm64" ) ) return True;
73
sewardj5db15402012-06-07 09:13:21 +000074#elif defined(VGP_mips32_linux)
75 if ( 0 == strcmp( arch, "mips32" ) ) return True;
76
petarj4df0bfc2013-02-27 23:17:33 +000077#elif defined(VGP_mips64_linux)
78 if ( 0 == strcmp( arch, "mips64" ) ) return True;
79
sewardj112711a2015-04-10 12:30:09 +000080#elif defined(VGP_tilegx_linux)
81 if ( 0 == strcmp( arch, "tilegx" ) ) return True;
82
njn61485ab2009-03-04 04:15:16 +000083#else
84# error Unknown platform
85#endif // VGP_*
sewardjc49ae752006-08-05 12:22:52 +000086
nethercote362c0d22004-11-18 18:21:56 +000087 return False;
nethercoteb625bcb2004-10-19 16:29:30 +000088}
nethercoteb625bcb2004-10-19 16:29:30 +000089
njn7fd6d382009-01-22 21:56:32 +000090//---------------------------------------------------------------------------
91// main
92//---------------------------------------------------------------------------
nethercoteb625bcb2004-10-19 16:29:30 +000093int main(int argc, char **argv)
94{
nethercote362c0d22004-11-18 18:21:56 +000095 int i;
nethercoteb625bcb2004-10-19 16:29:30 +000096 if ( argc != 2 ) {
njn61485ab2009-03-04 04:15:16 +000097 fprintf( stderr, "usage: arch_test <arch-type>\n" );
98 exit(3); // Usage error.
nethercoteb625bcb2004-10-19 16:29:30 +000099 }
nethercote362c0d22004-11-18 18:21:56 +0000100 if (go( argv[1] )) {
njn61485ab2009-03-04 04:15:16 +0000101 return 0; // Matched.
nethercote362c0d22004-11-18 18:21:56 +0000102 }
103 for (i = 0; NULL != all_archs[i]; i++) {
njn61485ab2009-03-04 04:15:16 +0000104 if ( 0 == strcmp( argv[1], all_archs[i] ) )
105 return 1; // Didn't match, but named another arch.
nethercote362c0d22004-11-18 18:21:56 +0000106 }
njn61485ab2009-03-04 04:15:16 +0000107 return 2; // Didn't match any archs.
nethercote288b7662004-01-20 09:24:53 +0000108}