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", |
sewardj | f08adb6 | 2010-01-04 10:31:41 +0000 | [diff] [blame] | 30 | "arm", |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 31 | NULL |
| 32 | }; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 33 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 34 | static Bool go(char* arch) |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 35 | { |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 36 | #if defined(VGP_x86_linux) || defined(VGP_x86_darwin) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 37 | if ( 0 == strcmp( arch, "x86" ) ) return True; |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 38 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 39 | #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 40 | if ( 0 == strcmp( arch, "x86" ) ) return True; |
| 41 | if ( 0 == strcmp( arch, "amd64" ) ) return True; |
| 42 | |
| 43 | #elif defined(VGP_ppc32_linux) |
| 44 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
| 45 | |
| 46 | #elif defined(VGP_ppc64_linux) |
| 47 | if ( 0 == strcmp( arch, "ppc64" ) ) return True; |
| 48 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
| 49 | |
| 50 | #elif defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) |
| 51 | if (sizeof(void*) == 8) { |
| 52 | /* CPU is in 64-bit mode */ |
| 53 | if ( 0 == strcmp( arch, "ppc64" ) ) return True; |
| 54 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 55 | } else { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 56 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 57 | } |
| 58 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 59 | #elif defined(VGP_arm_linux) |
| 60 | if ( 0 == strcmp( arch, "arm" ) ) return True; |
| 61 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 62 | #else |
| 63 | # error Unknown platform |
| 64 | #endif // VGP_* |
sewardj | c49ae75 | 2006-08-05 12:22:52 +0000 | [diff] [blame] | 65 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 66 | return False; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 67 | } |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 68 | |
njn | 7fd6d38 | 2009-01-22 21:56:32 +0000 | [diff] [blame] | 69 | //--------------------------------------------------------------------------- |
| 70 | // main |
| 71 | //--------------------------------------------------------------------------- |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 72 | int main(int argc, char **argv) |
| 73 | { |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 74 | int i; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 75 | if ( argc != 2 ) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 76 | fprintf( stderr, "usage: arch_test <arch-type>\n" ); |
| 77 | exit(3); // Usage error. |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 78 | } |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 79 | if (go( argv[1] )) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 80 | return 0; // Matched. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 81 | } |
| 82 | for (i = 0; NULL != all_archs[i]; i++) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 83 | if ( 0 == strcmp( argv[1], all_archs[i] ) ) |
| 84 | return 1; // Didn't match, but named another arch. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 85 | } |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 86 | return 2; // Didn't match any archs. |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 87 | } |