Back to index

glibc  2.9
dl-procinfo.h
Go to the documentation of this file.
00001 /* Processor capability information handling macros.  PowerPC version.
00002    Copyright (C) 2005, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _DL_PROCINFO_H
00021 #define _DL_PROCINFO_H      1
00022 
00023 #include <ldsodefs.h>
00024 #include <sysdep.h>         /* This defines the PPC_FEATURE_* macros.  */
00025 
00026 /* There are 25 bits used, but they are bits 7..31.  */
00027 #define _DL_HWCAP_FIRST            7
00028 #define _DL_HWCAP_COUNT            32
00029 
00030 /* These bits influence library search.  */
00031 #define HWCAP_IMPORTANT            (PPC_FEATURE_HAS_ALTIVEC \
00032                             + PPC_FEATURE_HAS_DFP)
00033 
00034 #define _DL_PLATFORMS_COUNT 8
00035 
00036 #define _DL_FIRST_PLATFORM      32
00037 /* Mask to filter out platforms.  */
00038 #define _DL_HWCAP_PLATFORM      (((1ULL << _DL_PLATFORMS_COUNT) - 1) \
00039                                  << _DL_FIRST_PLATFORM)
00040 
00041 /* Platform bits (relative to _DL_FIRST_PLATFORM).  */
00042 #define PPC_PLATFORM_POWER4        0
00043 #define PPC_PLATFORM_PPC970        1
00044 #define PPC_PLATFORM_POWER5        2
00045 #define PPC_PLATFORM_POWER5_PLUS   3
00046 #define PPC_PLATFORM_POWER6        4
00047 #define PPC_PLATFORM_CELL_BE              5
00048 #define PPC_PLATFORM_POWER6X              6
00049 #define PPC_PLATFORM_POWER7        7
00050 
00051 static inline const char *
00052 __attribute__ ((unused))
00053 _dl_hwcap_string (int idx)
00054 {
00055   return GLRO(dl_powerpc_cap_flags)[idx - _DL_HWCAP_FIRST];
00056 }
00057 
00058 static inline const char *
00059 __attribute__ ((unused))
00060 _dl_platform_string (int idx)
00061 {
00062   return GLRO(dl_powerpc_platforms)[idx - _DL_FIRST_PLATFORM];
00063 }
00064 
00065 static inline int
00066 __attribute__ ((unused))
00067 _dl_string_hwcap (const char *str)
00068 {
00069   for (int i = _DL_HWCAP_FIRST; i < _DL_HWCAP_COUNT; ++i)
00070     if (strcmp (str, _dl_hwcap_string (i)) == 0)
00071       return i;
00072   return -1;
00073 }
00074 
00075 static inline int
00076 __attribute__ ((unused, always_inline))
00077 _dl_string_platform (const char *str)
00078 {
00079   if (str == NULL)
00080     return -1;
00081 
00082   if (strncmp (str, GLRO(dl_powerpc_platforms)[PPC_PLATFORM_POWER4], 5) == 0)
00083     {
00084       int ret;
00085       str += 5;
00086       switch (*str)
00087        {
00088        case '4':
00089          ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER4;
00090          break;
00091        case '5':
00092          ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER5;
00093          if (str[1] == '+')
00094            {
00095              ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER5_PLUS;
00096              ++str;
00097            }
00098          break;
00099        case '6':
00100          ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER6;
00101          if (str[1] == 'x')
00102            {
00103              ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER6X;
00104              ++str;
00105            }
00106          break;
00107        case '7':
00108          ret = _DL_FIRST_PLATFORM + PPC_PLATFORM_POWER7;
00109          break;
00110        default:
00111          return -1;
00112        }
00113       if (str[1] == '\0')
00114        return ret;
00115     }
00116   else if (strncmp (str, GLRO(dl_powerpc_platforms)[PPC_PLATFORM_PPC970],
00117                   3) == 0)
00118     {
00119       if (strcmp (str + 3, GLRO(dl_powerpc_platforms)[PPC_PLATFORM_PPC970]
00120                         + 3) == 0)
00121        return _DL_FIRST_PLATFORM + PPC_PLATFORM_PPC970;
00122       else if (strcmp (str + 3,
00123                      GLRO(dl_powerpc_platforms)[PPC_PLATFORM_CELL_BE] + 3)
00124               == 0)
00125        return _DL_FIRST_PLATFORM + PPC_PLATFORM_CELL_BE;
00126     }
00127 
00128   return -1;
00129 }
00130 
00131 #ifdef IS_IN_rtld
00132 static inline int
00133 __attribute__ ((unused))
00134 _dl_procinfo (int word)
00135 {
00136   _dl_printf ("AT_HWCAP:       ");
00137 
00138   for (int i = _DL_HWCAP_FIRST; i < _DL_HWCAP_COUNT; ++i)
00139     if (word & (1 << i))
00140       _dl_printf (" %s", _dl_hwcap_string (i));
00141 
00142   _dl_printf ("\n");
00143 
00144   return 0;
00145 }
00146 #endif
00147 
00148 #endif /* dl-procinfo.h */