1 /* Linux/ARM version of processor capability information handling macros.
2    Copyright (C) 2001-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #ifndef _DL_PROCINFO_H
20 #define _DL_PROCINFO_H	1
21 
22 #include <ldsodefs.h>
23 #include <sysdep.h>
24 
25 #define _DL_HWCAP_COUNT 27
26 
27 /* Low 22 bits are allocated in HWCAP.  */
28 #define _DL_HWCAP_LAST		21
29 
30 /* Low 5 bits are allocated in HWCAP2.  */
31 #define _DL_HWCAP2_LAST		4
32 
33 /* The kernel provides platform data but it is not interesting.  */
34 #define _DL_HWCAP_PLATFORM	0
35 
36 
37 static inline const char *
38 __attribute__ ((unused))
_dl_hwcap_string(int idx)39 _dl_hwcap_string (int idx)
40 {
41   return GLRO(dl_arm_cap_flags)[idx];
42 };
43 
44 static inline int
45 __attribute__ ((unused))
_dl_procinfo(unsigned int type,unsigned long int word)46 _dl_procinfo (unsigned int type, unsigned long int word)
47 {
48   switch(type)
49     {
50     case AT_HWCAP:
51       _dl_printf ("AT_HWCAP:       ");
52 
53       for (int i = 0; i <= _DL_HWCAP_LAST; ++i)
54 	if (word & (1 << i))
55 	  _dl_printf (" %s", _dl_hwcap_string (i));
56       break;
57     case AT_HWCAP2:
58       {
59 	unsigned int offset = _DL_HWCAP_LAST + 1;
60 
61 	_dl_printf ("AT_HWCAP2:      ");
62 
63 	for (int i = 0; i <= _DL_HWCAP2_LAST; ++i)
64 	  if (word & (1 << i))
65 	    _dl_printf (" %s", _dl_hwcap_string (offset + i));
66 	break;
67       }
68     default:
69       /* Fallback to generic output mechanism.  */
70       return -1;
71     }
72   _dl_printf ("\n");
73   return 0;
74 }
75 
76 #define HWCAP_IMPORTANT		(HWCAP_ARM_VFP | HWCAP_ARM_NEON)
77 
78 static inline int
79 __attribute__ ((unused))
_dl_string_hwcap(const char * str)80 _dl_string_hwcap (const char *str)
81 {
82   for (int i = 0; i < _DL_HWCAP_COUNT; i++)
83     {
84       if (strcmp (str, _dl_hwcap_string (i)) == 0)
85 	return i;
86     }
87   return -1;
88 };
89 
90 #define _dl_string_platform(str) (-1)
91 
92 #endif /* dl-procinfo.h */
93