njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 1 | |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 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". |
njn | 7fd6d38 | 2009-01-22 21:56:32 +0000 | [diff] [blame] | 11 | // |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 12 | // We return: |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 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) |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 17 | |
njn | 7fd6d38 | 2009-01-22 21:56:32 +0000 | [diff] [blame] | 18 | // Nb: When updating this file for a new architecture, add the name to |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 19 | // 'all_archs' as well as adding go(). |
| 20 | |
| 21 | #define False 0 |
| 22 | #define True 1 |
| 23 | typedef int Bool; |
| 24 | |
| 25 | char* all_archs[] = { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 26 | "x86", |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 27 | "amd64", |
njn | 10c122e | 2005-09-13 00:45:14 +0000 | [diff] [blame] | 28 | "ppc32", |
sewardj | 0d4f8ac | 2006-01-02 16:24:03 +0000 | [diff] [blame] | 29 | "ppc64", |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 30 | "ppc64le", |
sewardj | f08adb6 | 2010-01-04 10:31:41 +0000 | [diff] [blame] | 31 | "arm", |
sewardj | 15e4e5c | 2014-08-26 21:06:31 +0000 | [diff] [blame] | 32 | "arm64", |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 33 | "s390x", |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 34 | "mips32", |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 35 | "mips64", |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 36 | NULL |
| 37 | }; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 38 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 39 | static Bool go(char* arch) |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 40 | { |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 41 | #if defined(VGP_x86_linux) || defined(VGP_x86_darwin) \ |
| 42 | || defined(VGP_x86_solaris) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 43 | if ( 0 == strcmp( arch, "x86" ) ) return True; |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 44 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 45 | #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) \ |
| 46 | || defined(VGP_amd64_solaris) |
florian | 5bdb9ec | 2012-05-06 03:51:00 +0000 | [diff] [blame] | 47 | #if defined(VGA_SEC_x86) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 48 | if ( 0 == strcmp( arch, "x86" ) ) return True; |
florian | 5bdb9ec | 2012-05-06 03:51:00 +0000 | [diff] [blame] | 49 | #endif |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 50 | if ( 0 == strcmp( arch, "amd64" ) ) return True; |
| 51 | |
| 52 | #elif defined(VGP_ppc32_linux) |
| 53 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
| 54 | |
carll | cae0cc2 | 2014-08-07 23:17:29 +0000 | [diff] [blame] | 55 | #elif defined(VGP_ppc64be_linux) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 56 | if ( 0 == strcmp( arch, "ppc64" ) ) return True; |
florian | 5bdb9ec | 2012-05-06 03:51:00 +0000 | [diff] [blame] | 57 | #if defined(VGA_SEC_ppc32) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 58 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
florian | 5bdb9ec | 2012-05-06 03:51:00 +0000 | [diff] [blame] | 59 | #endif |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 60 | |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 61 | #elif defined(VGP_ppc64le_linux) |
| 62 | if ( 0 == strcmp( arch, "ppc64" ) ) return True; |
| 63 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 64 | #elif defined(VGP_s390x_linux) |
| 65 | if ( 0 == strcmp( arch, "s390x" ) ) return True; |
| 66 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 67 | #elif defined(VGP_arm_linux) |
| 68 | if ( 0 == strcmp( arch, "arm" ) ) return True; |
| 69 | |
sewardj | 599cd7a | 2014-03-01 11:20:33 +0000 | [diff] [blame] | 70 | #elif defined(VGP_arm64_linux) |
| 71 | if ( 0 == strcmp( arch, "arm64" ) ) return True; |
| 72 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 73 | #elif defined(VGP_mips32_linux) |
| 74 | if ( 0 == strcmp( arch, "mips32" ) ) return True; |
| 75 | |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 76 | #elif defined(VGP_mips64_linux) |
| 77 | if ( 0 == strcmp( arch, "mips64" ) ) return True; |
| 78 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 79 | #else |
| 80 | # error Unknown platform |
| 81 | #endif // VGP_* |
sewardj | c49ae75 | 2006-08-05 12:22:52 +0000 | [diff] [blame] | 82 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 83 | return False; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 84 | } |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 85 | |
njn | 7fd6d38 | 2009-01-22 21:56:32 +0000 | [diff] [blame] | 86 | //--------------------------------------------------------------------------- |
| 87 | // main |
| 88 | //--------------------------------------------------------------------------- |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 89 | int main(int argc, char **argv) |
| 90 | { |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 91 | int i; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 92 | if ( argc != 2 ) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 93 | fprintf( stderr, "usage: arch_test <arch-type>\n" ); |
| 94 | exit(3); // Usage error. |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 95 | } |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 96 | if (go( argv[1] )) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 97 | return 0; // Matched. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 98 | } |
| 99 | for (i = 0; NULL != all_archs[i]; i++) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 100 | if ( 0 == strcmp( argv[1], all_archs[i] ) ) |
| 101 | return 1; // Didn't match, but named another arch. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 102 | } |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 103 | return 2; // Didn't match any archs. |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 104 | } |