blob: f6206e3ef382dd1a34101d30a98a60f7e0aba27f [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",
nethercote362c0d22004-11-18 18:21:56 +000030 NULL
31};
nethercoteb625bcb2004-10-19 16:29:30 +000032
njn61485ab2009-03-04 04:15:16 +000033static Bool go(char* arch)
nethercoteb625bcb2004-10-19 16:29:30 +000034{
njn61485ab2009-03-04 04:15:16 +000035#if defined(VGP_x86_linux)
36 if ( 0 == strcmp( arch, "x86" ) ) return True;
nethercote288b7662004-01-20 09:24:53 +000037
njn61485ab2009-03-04 04:15:16 +000038#elif defined(VGP_amd64_linux)
39 if ( 0 == strcmp( arch, "x86" ) ) return True;
40 if ( 0 == strcmp( arch, "amd64" ) ) return True;
41
42#elif defined(VGP_ppc32_linux)
43 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
44
45#elif defined(VGP_ppc64_linux)
46 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
47 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
48
49#elif defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
50 if (sizeof(void*) == 8) {
51 /* CPU is in 64-bit mode */
52 if ( 0 == strcmp( arch, "ppc64" ) ) return True;
53 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
nethercoteb625bcb2004-10-19 16:29:30 +000054 } else {
njn61485ab2009-03-04 04:15:16 +000055 if ( 0 == strcmp( arch, "ppc32" ) ) return True;
nethercote288b7662004-01-20 09:24:53 +000056 }
57
njn61485ab2009-03-04 04:15:16 +000058#else
59# error Unknown platform
60#endif // VGP_*
sewardjc49ae752006-08-05 12:22:52 +000061
nethercote362c0d22004-11-18 18:21:56 +000062 return False;
nethercoteb625bcb2004-10-19 16:29:30 +000063}
nethercoteb625bcb2004-10-19 16:29:30 +000064
njn7fd6d382009-01-22 21:56:32 +000065//---------------------------------------------------------------------------
66// main
67//---------------------------------------------------------------------------
nethercoteb625bcb2004-10-19 16:29:30 +000068int main(int argc, char **argv)
69{
nethercote362c0d22004-11-18 18:21:56 +000070 int i;
nethercoteb625bcb2004-10-19 16:29:30 +000071 if ( argc != 2 ) {
njn61485ab2009-03-04 04:15:16 +000072 fprintf( stderr, "usage: arch_test <arch-type>\n" );
73 exit(3); // Usage error.
nethercoteb625bcb2004-10-19 16:29:30 +000074 }
nethercote362c0d22004-11-18 18:21:56 +000075 if (go( argv[1] )) {
njn61485ab2009-03-04 04:15:16 +000076 return 0; // Matched.
nethercote362c0d22004-11-18 18:21:56 +000077 }
78 for (i = 0; NULL != all_archs[i]; i++) {
njn61485ab2009-03-04 04:15:16 +000079 if ( 0 == strcmp( argv[1], all_archs[i] ) )
80 return 1; // Didn't match, but named another arch.
nethercote362c0d22004-11-18 18:21:56 +000081 }
njn61485ab2009-03-04 04:15:16 +000082 return 2; // Didn't match any archs.
nethercote288b7662004-01-20 09:24:53 +000083}