1 /* This file is part of the GNU C Library.
2    Copyright (C) 2013-2021 Free Software Foundation, Inc.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #include <ldsodefs.h>
19 
20 /* The code checks if _rtld_global_ro was realocated before trying to access
21    the dl_hwcap field. The assembly is to make the compiler not optimize the
22    test (&_rtld_global_ro != NULL), which is always true in ISO C (but not
23    in that case since _rtld_global_ro might not been realocated yet).  */
24 #if defined(SHARED) && !IS_IN (rtld)
25 # define __GLRO(value) \
26   ({ volatile void **__p = (volatile void**)(&_rtld_global_ro);	\
27     unsigned long int __ret;					\
28      asm ("# x in %0" : "+r" (__p));				\
29      __ret = (__p) ? GLRO(value) : 0;				\
30      __ret; })
31 #else
32 # define __GLRO(value)  GLRO(value)
33 #endif
34 
35 /* dl_hwcap contains only the latest supported ISA, the macro checks which is
36    and fills the previous ones.  */
37 #define INIT_ARCH() \
38   unsigned long int hwcap = __GLRO(dl_hwcap); 			\
39   unsigned long int __attribute__((unused)) hwcap2 = __GLRO(dl_hwcap2); \
40   bool __attribute__((unused)) use_cached_memopt =		\
41     __GLRO(dl_powerpc_cpu_features.use_cached_memopt);		\
42   if (hwcap & PPC_FEATURE_ARCH_2_06)				\
43     hwcap |= PPC_FEATURE_ARCH_2_05 |				\
44 	     PPC_FEATURE_POWER5_PLUS |				\
45 	     PPC_FEATURE_POWER5 |				\
46 	     PPC_FEATURE_POWER4;				\
47   else if (hwcap & PPC_FEATURE_ARCH_2_05)			\
48     hwcap |= PPC_FEATURE_POWER5_PLUS |				\
49 	     PPC_FEATURE_POWER5 |				\
50 	     PPC_FEATURE_POWER4;				\
51   else if (hwcap & PPC_FEATURE_POWER5_PLUS)			\
52     hwcap |= PPC_FEATURE_POWER5 |				\
53 	     PPC_FEATURE_POWER4;				\
54   else if (hwcap & PPC_FEATURE_POWER5)				\
55     hwcap |= PPC_FEATURE_POWER4;
56