Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / mono-hwcap-ppc.c
1 /**
2  * \file
3  * PowerPC hardware feature detection
4  *
5  * Authors:
6  *    Alex Rønne Petersen (alexrp@xamarin.com)
7  *    Elijah Taylor (elijahtaylor@google.com)
8  *    Miguel de Icaza (miguel@xamarin.com)
9  *    Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com)
10  *    Paolo Molaro (lupus@xamarin.com)
11  *    Rodrigo Kumpera (kumpera@gmail.com)
12  *    Sebastien Pouliot (sebastien@xamarin.com)
13  *    Zoltan Varga (vargaz@xamarin.com)
14  *
15  * Copyright 2003 Ximian, Inc.
16  * Copyright 2003-2011 Novell, Inc
17  * Copyright 2006 Broadcom
18  * Copyright 2007-2008 Andreas Faerber
19  * Copyright 2011-2013 Xamarin Inc
20  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
21  */
22
23 #include "mono/utils/mono-hwcap.h"
24
25 #if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
26 #include <string.h>
27 #include <sys/auxv.h>
28 #endif
29
30 void
31 mono_hwcap_arch_init (void)
32 {
33 #if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
34         unsigned long hwcap;
35         unsigned long platform;
36
37         if ((hwcap = getauxval(AT_HWCAP))) {
38                 /* PPC_FEATURE_ICACHE_SNOOP */
39                 if (hwcap & 0x00002000)
40                         mono_hwcap_ppc_has_icache_snoop = TRUE;
41
42                 /* PPC_FEATURE_POWER4, PPC_FEATURE_POWER5, PPC_FEATURE_POWER5_PLUS,
43                    PPC_FEATURE_CELL_BE, PPC_FEATURE_PA6T, PPC_FEATURE_ARCH_2_05 */
44                 if (hwcap & (0x00080000 | 0x00040000 | 0x00020000 | 0x00010000 | 0x00000800 | 0x00001000))
45                         mono_hwcap_ppc_is_isa_2x = TRUE;
46
47                 /* PPC_FEATURE_64 */
48                 if (hwcap & 0x40000000)
49                         mono_hwcap_ppc_is_isa_64 = TRUE;
50
51                 /* PPC_FEATURE_POWER6_EXT */
52                 if (hwcap & 0x00000200)
53                         mono_hwcap_ppc_has_move_fpr_gpr = TRUE;
54         }
55
56         if ((platform = getauxval(AT_PLATFORM))) {
57                 const char *str = (const char *) platform;
58
59                 if (!strcmp (str, "ppc970") || (!strncmp (str, "power", 5) && str [5] >= '4' && str [5] <= '7'))
60                         mono_hwcap_ppc_has_multiple_ls_units = TRUE;
61         }
62 #endif
63 }