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", |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 30 | NULL |
| 31 | }; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 32 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 33 | static Bool go(char* arch) |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 34 | { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 35 | #if defined(VGP_x86_linux) |
| 36 | if ( 0 == strcmp( arch, "x86" ) ) return True; |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 37 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 38 | #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; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 54 | } else { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 55 | if ( 0 == strcmp( arch, "ppc32" ) ) return True; |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 56 | } |
| 57 | |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 58 | #else |
| 59 | # error Unknown platform |
| 60 | #endif // VGP_* |
sewardj | c49ae75 | 2006-08-05 12:22:52 +0000 | [diff] [blame] | 61 | |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 62 | return False; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 63 | } |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 64 | |
njn | 7fd6d38 | 2009-01-22 21:56:32 +0000 | [diff] [blame] | 65 | //--------------------------------------------------------------------------- |
| 66 | // main |
| 67 | //--------------------------------------------------------------------------- |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 68 | int main(int argc, char **argv) |
| 69 | { |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 70 | int i; |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 71 | if ( argc != 2 ) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 72 | fprintf( stderr, "usage: arch_test <arch-type>\n" ); |
| 73 | exit(3); // Usage error. |
nethercote | b625bcb | 2004-10-19 16:29:30 +0000 | [diff] [blame] | 74 | } |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 75 | if (go( argv[1] )) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 76 | return 0; // Matched. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 77 | } |
| 78 | for (i = 0; NULL != all_archs[i]; i++) { |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 79 | if ( 0 == strcmp( argv[1], all_archs[i] ) ) |
| 80 | return 1; // Didn't match, but named another arch. |
nethercote | 362c0d2 | 2004-11-18 18:21:56 +0000 | [diff] [blame] | 81 | } |
njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame] | 82 | return 2; // Didn't match any archs. |
nethercote | 288b766 | 2004-01-20 09:24:53 +0000 | [diff] [blame] | 83 | } |