Skip to content

Commit d898d1a

Browse files
committed
Fix build on FreeBSD/powerpc*
This builds on the code added in 89a3f03. Since AT_PLATFORM is not available on FreeBSD, currently only architecture detection and CPU feature detection work.
1 parent c74a85d commit d898d1a

File tree

2 files changed

+130
-2
lines changed

2 files changed

+130
-2
lines changed

BUILD.bazel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ cc_library(
215215
PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
216216
PLATFORM_CPU_ARM64: ["src/impl_aarch64_linux_or_android.c"],
217217
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
218-
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
218+
PLATFORM_CPU_PPC: [
219+
"src/impl_ppc_freebsd.c",
220+
"src/impl_ppc_linux.c",
221+
],
219222
}),
220223
copts = C99_FLAGS,
221224
includes = INCLUDES,
@@ -259,7 +262,10 @@ cc_library(
259262
PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
260263
PLATFORM_CPU_ARM64: ["src/impl_aarch64_linux_or_android.c"],
261264
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
262-
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
265+
PLATFORM_CPU_PPC: [
266+
"src/impl_ppc_freebsd.c",
267+
"src/impl_ppc_linux.c",
268+
],
263269
}),
264270
hdrs = selects.with_or({
265271
PLATFORM_CPU_X86_64: [

src/impl_ppc_freebsd.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "cpu_features_macros.h"
16+
17+
#ifdef CPU_FEATURES_ARCH_PPC
18+
#ifdef CPU_FEATURES_OS_FREEBSD
19+
20+
#include "cpuinfo_ppc.h"
21+
22+
////////////////////////////////////////////////////////////////////////////////
23+
// Definitions for introspection.
24+
////////////////////////////////////////////////////////////////////////////////
25+
#define INTROSPECTION_TABLE \
26+
LINE(PPC_32, ppc32, "ppc32", PPC_FEATURE_32, 0) \
27+
LINE(PPC_64, ppc64, "ppc64", PPC_FEATURE_64, 0) \
28+
LINE(PPC_601_INSTR, ppc601, "ppc601", PPC_FEATURE_601_INSTR, 0) \
29+
LINE(PPC_HAS_ALTIVEC, altivec, "altivec", PPC_FEATURE_HAS_ALTIVEC, 0) \
30+
LINE(PPC_HAS_FPU, fpu, "fpu", PPC_FEATURE_HAS_FPU, 0) \
31+
LINE(PPC_HAS_MMU, mmu, "mmu", PPC_FEATURE_HAS_MMU, 0) \
32+
LINE(PPC_HAS_4xxMAC, mac_4xx, "4xxmac", PPC_FEATURE_HAS_4xxMAC, 0) \
33+
LINE(PPC_UNIFIED_CACHE, unifiedcache, "ucache", PPC_FEATURE_UNIFIED_CACHE, \
34+
0) \
35+
LINE(PPC_HAS_SPE, spe, "spe", PPC_FEATURE_HAS_SPE, 0) \
36+
LINE(PPC_HAS_EFP_SINGLE, efpsingle, "efpsingle", PPC_FEATURE_HAS_EFP_SINGLE, \
37+
0) \
38+
LINE(PPC_HAS_EFP_DOUBLE, efpdouble, "efpdouble", PPC_FEATURE_HAS_EFP_DOUBLE, \
39+
0) \
40+
LINE(PPC_NO_TB, no_tb, "notb", PPC_FEATURE_NO_TB, 0) \
41+
LINE(PPC_POWER4, power4, "power4", PPC_FEATURE_POWER4, 0) \
42+
LINE(PPC_POWER5, power5, "power5", PPC_FEATURE_POWER5, 0) \
43+
LINE(PPC_POWER5_PLUS, power5plus, "power5+", PPC_FEATURE_POWER5_PLUS, 0) \
44+
LINE(PPC_CELL, cell, "cellbe", PPC_FEATURE_CELL, 0) \
45+
LINE(PPC_BOOKE, booke, "booke", PPC_FEATURE_BOOKE, 0) \
46+
LINE(PPC_SMT, smt, "smt", PPC_FEATURE_SMT, 0) \
47+
LINE(PPC_ICACHE_SNOOP, icachesnoop, "ic_snoop", PPC_FEATURE_ICACHE_SNOOP, 0) \
48+
LINE(PPC_ARCH_2_05, arch205, "arch_2_05", PPC_FEATURE_ARCH_2_05, 0) \
49+
LINE(PPC_PA6T, pa6t, "pa6t", PPC_FEATURE_PA6T, 0) \
50+
LINE(PPC_HAS_DFP, dfp, "dfp", PPC_FEATURE_HAS_DFP, 0) \
51+
LINE(PPC_POWER6_EXT, power6ext, "power6x", PPC_FEATURE_POWER6_EXT, 0) \
52+
LINE(PPC_ARCH_2_06, arch206, "arch_2_06", PPC_FEATURE_ARCH_2_06, 0) \
53+
LINE(PPC_HAS_VSX, vsx, "vsx", PPC_FEATURE_HAS_VSX, 0) \
54+
LINE(PPC_PSERIES_PERFMON_COMPAT, pseries_perfmon_compat, "archpmu", \
55+
PPC_FEATURE_PSERIES_PERFMON_COMPAT, 0) \
56+
LINE(PPC_TRUE_LE, truele, "true_le", PPC_FEATURE_TRUE_LE, 0) \
57+
LINE(PPC_PPC_LE, ppcle, "ppcle", PPC_FEATURE_PPC_LE, 0) \
58+
LINE(PPC_ARCH_2_07, arch207, "arch_2_07", 0, PPC_FEATURE2_ARCH_2_07) \
59+
LINE(PPC_HTM, htm, "htm", 0, PPC_FEATURE2_HTM) \
60+
LINE(PPC_DSCR, dscr, "dscr", 0, PPC_FEATURE2_DSCR) \
61+
LINE(PPC_EBB, ebb, "ebb", 0, PPC_FEATURE2_EBB) \
62+
LINE(PPC_ISEL, isel, "isel", 0, PPC_FEATURE2_ISEL) \
63+
LINE(PPC_TAR, tar, "tar", 0, PPC_FEATURE2_TAR) \
64+
LINE(PPC_VEC_CRYPTO, vcrypto, "vcrypto", 0, PPC_FEATURE2_VEC_CRYPTO) \
65+
LINE(PPC_HTM_NOSC, htm_nosc, "htm-nosc", 0, PPC_FEATURE2_HTM_NOSC) \
66+
LINE(PPC_ARCH_3_00, arch300, "arch_3_00", 0, PPC_FEATURE2_ARCH_3_00) \
67+
LINE(PPC_HAS_IEEE128, ieee128, "ieee128", 0, PPC_FEATURE2_HAS_IEEE128) \
68+
LINE(PPC_DARN, darn, "darn", 0, PPC_FEATURE2_DARN) \
69+
LINE(PPC_SCV, scv, "scv", 0, PPC_FEATURE2_SCV) \
70+
LINE(PPC_HTM_NO_SUSPEND, htm_no_suspend, "htm-no-suspend", 0, \
71+
PPC_FEATURE2_HTM_NO_SUSPEND)
72+
#undef PPC // Remove conflict with compiler generated preprocessor
73+
#define INTROSPECTION_PREFIX PPC
74+
#define INTROSPECTION_ENUM_PREFIX PPC
75+
#include "define_introspection_and_hwcaps.inl"
76+
77+
////////////////////////////////////////////////////////////////////////////////
78+
// Implementation.
79+
////////////////////////////////////////////////////////////////////////////////
80+
81+
#include <stdbool.h>
82+
83+
#include "internal/bit_utils.h"
84+
#include "internal/filesystem.h"
85+
#include "internal/hwcaps.h"
86+
#include "internal/stack_line_reader.h"
87+
#include "internal/string_view.h"
88+
89+
static const PPCInfo kEmptyPPCInfo;
90+
91+
PPCInfo GetPPCInfo(void) {
92+
PPCInfo info = kEmptyPPCInfo;
93+
const HardwareCapabilities hwcaps = CpuFeatures_GetHardwareCapabilities();
94+
for (size_t i = 0; i < PPC_LAST_; ++i) {
95+
if (CpuFeatures_IsHwCapsSet(kHardwareCapabilities[i], hwcaps)) {
96+
kSetters[i](&info.features, true);
97+
}
98+
}
99+
return info;
100+
}
101+
102+
static const PPCPlatformStrings kEmptyPPCPlatformStrings;
103+
104+
PPCPlatformStrings GetPPCPlatformStrings(void) {
105+
PPCPlatformStrings strings = kEmptyPPCPlatformStrings;
106+
const char* platform = CpuFeatures_GetPlatformPointer();
107+
const char* base_platform = CpuFeatures_GetBasePlatformPointer();
108+
109+
if (platform != NULL)
110+
CpuFeatures_StringView_CopyString(str(platform), strings.type.platform,
111+
sizeof(strings.type.platform));
112+
if (base_platform != NULL)
113+
CpuFeatures_StringView_CopyString(str(base_platform),
114+
strings.type.base_platform,
115+
sizeof(strings.type.base_platform));
116+
117+
return strings;
118+
}
119+
120+
121+
#endif // CPU_FEATURES_OS_FREEBSD
122+
#endif // CPU_FEATURES_ARCH_PPC

0 commit comments

Comments
 (0)