1 | /* powerpc HWCAP/HWCAP2 and AT_PLATFORM data pre-processing. |
2 | Copyright (C) 2015-2024 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 | #include <unistd.h> |
20 | #include <shlib-compat.h> |
21 | #include <dl-procinfo.h> |
22 | #include <cpu-features.c> |
23 | |
24 | tcbhead_t __tcb __attribute__ ((visibility ("hidden" ))); |
25 | |
26 | /* This function parses the HWCAP/HWCAP2 fields, adding the previous supported |
27 | ISA bits, as well as converting the AT_PLATFORM string to a number. This |
28 | data is stored in two global variables that can be used later by the |
29 | powerpc-specific code to store it into the TCB. */ |
30 | void |
31 | __tcb_parse_hwcap_and_convert_at_platform (void) |
32 | { |
33 | |
34 | uint64_t h1, h2, h3, h4; |
35 | |
36 | /* Read AT_PLATFORM string from auxv and convert it to a number. */ |
37 | __tcb.at_platform = _dl_string_platform (GLRO (dl_platform)); |
38 | |
39 | /* Read HWCAP and HWCAP2 from auxv. */ |
40 | h1 = GLRO (dl_hwcap); |
41 | h2 = GLRO (dl_hwcap2); |
42 | h3 = GLRO (dl_hwcap3); |
43 | h4 = GLRO (dl_hwcap4); |
44 | |
45 | /* hwcap contains only the latest supported ISA, the code checks which is |
46 | and fills the previous supported ones. */ |
47 | |
48 | if (h2 & PPC_FEATURE2_ARCH_2_07) |
49 | h1 |= PPC_FEATURE_ARCH_2_06 |
50 | | PPC_FEATURE_ARCH_2_05 |
51 | | PPC_FEATURE_POWER5_PLUS |
52 | | PPC_FEATURE_POWER5 |
53 | | PPC_FEATURE_POWER4; |
54 | else if (h1 & PPC_FEATURE_ARCH_2_06) |
55 | h1 |= PPC_FEATURE_ARCH_2_05 |
56 | | PPC_FEATURE_POWER5_PLUS |
57 | | PPC_FEATURE_POWER5 |
58 | | PPC_FEATURE_POWER4; |
59 | else if (h1 & PPC_FEATURE_ARCH_2_05) |
60 | h1 |= PPC_FEATURE_POWER5_PLUS |
61 | | PPC_FEATURE_POWER5 |
62 | | PPC_FEATURE_POWER4; |
63 | else if (h1 & PPC_FEATURE_POWER5_PLUS) |
64 | h1 |= PPC_FEATURE_POWER5 |
65 | | PPC_FEATURE_POWER4; |
66 | else if (h1 & PPC_FEATURE_POWER5) |
67 | h1 |= PPC_FEATURE_POWER4; |
68 | |
69 | uint64_t array_hwcaps[] = { h1, h2, h3, h4 }; |
70 | init_cpu_features (cpu_features: &GLRO(dl_powerpc_cpu_features), array_hwcaps); |
71 | |
72 | /* Consolidate both HWCAP and HWCAP2 into a single doubleword so that |
73 | we can read both in a single load later. */ |
74 | __tcb.hwcap = (h1 << 32) | (h2 & 0xffffffff); |
75 | |
76 | /* Consolidate both HWCAP3 and HWCAP4 into a single doubleword so that |
77 | we can read both in a single load later. */ |
78 | __tcb.hwcap_extn = (h3 << 32) | (h4 & 0xffffffff); |
79 | |
80 | } |
81 | #if IS_IN (rtld) |
82 | versioned_symbol (ld, __tcb_parse_hwcap_and_convert_at_platform, \ |
83 | __parse_hwcap_and_convert_at_platform, GLIBC_2_23); |
84 | versioned_symbol (ld, __tcb_parse_hwcap_and_convert_at_platform, \ |
85 | __parse_hwcap_3_4_and_convert_at_platform, GLIBC_2_39); |
86 | #endif |
87 | |
88 | /* Export __parse_hwcap_and_convert_at_platform in libc.a. This is used by |
89 | GCC to make sure that the HWCAP/Platform bits are stored in the TCB when |
90 | using __builtin_cpu_is()/__builtin_cpu_supports() in the static case. */ |
91 | #ifndef SHARED |
92 | weak_alias (__tcb_parse_hwcap_and_convert_at_platform, \ |
93 | __parse_hwcap_and_convert_at_platform); |
94 | weak_alias (__tcb_parse_hwcap_and_convert_at_platform, \ |
95 | __parse_hwcap_3_4_and_convert_at_platform); |
96 | #endif |
97 | |