summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2024-07-21 16:49:27 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2024-07-21 16:49:27 +0000
commit6a6bc3bb306577a83b20fd7e6fdd3470f9ff4e7f (patch)
tree3072c62ec8c3acd9a1f4637d76911655bdd07874 /sys/arch
parent7a95bae0c24964c0f3a7ba5578ca59ad8f39b663 (diff)
Export basic HWCAP bits to let applications detect Altivec & VSX on powerpc64
Input from miod@ and gkoehler@, tests & ok gkoehler@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/powerpc64/include/cpu.h6
-rw-r--r--sys/arch/powerpc64/include/elf.h54
-rw-r--r--sys/arch/powerpc64/powerpc64/cpu.c9
3 files changed, 62 insertions, 7 deletions
diff --git a/sys/arch/powerpc64/include/cpu.h b/sys/arch/powerpc64/include/cpu.h
index fe0394f457b..d773d0bdc95 100644
--- a/sys/arch/powerpc64/include/cpu.h
+++ b/sys/arch/powerpc64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.37 2024/06/09 21:15:29 jca Exp $ */
+/* $OpenBSD: cpu.h,v 1.38 2024/07/21 16:49:26 jca Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -41,6 +41,7 @@
*/
#include <machine/cpufunc.h>
+#include <machine/elf.h>
#include <machine/frame.h>
#include <machine/intr.h>
#include <machine/psl.h>
@@ -177,9 +178,6 @@ void signotify(struct proc *);
extern uint32_t cpu_features;
extern uint32_t cpu_features2;
-#define PPC_FEATURE2_ARCH_3_00 0x00800000
-#define PPC_FEATURE2_DARN 0x00200000
-
void cpu_init_features(void);
void cpu_init(void);
diff --git a/sys/arch/powerpc64/include/elf.h b/sys/arch/powerpc64/include/elf.h
index a3503ab099b..a7f54488f63 100644
--- a/sys/arch/powerpc64/include/elf.h
+++ b/sys/arch/powerpc64/include/elf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:49 jca Exp $ */
+/* $OpenBSD: elf.h,v 1.2 2024/07/21 16:49:26 jca Exp $ */
/*
* This file is in the public domain.
@@ -8,7 +8,57 @@
#define _MACHINE_ELF_H_
/*
- * TODO FreeBSD puts PPC_FEATURE* in cpu.h
+ * CPU Feature Attributes
+ *
+ * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector,
+ * and are exported to userland via the elf_aux_info(3) function.
*/
+#ifdef _KERNEL
+# define __HAVE_CPU_HWCAP
+# define __HAVE_CPU_HWCAP2
+extern unsigned long hwcap;
+extern unsigned long hwcap2;
+#endif /* _KERNEL */
+
+#define PPC_FEATURE_32 0x80000000 /* Always true */
+#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */
+#define PPC_FEATURE_601_INSTR 0x20000000
+#define PPC_FEATURE_HAS_ALTIVEC 0x10000000
+#define PPC_FEATURE_HAS_FPU 0x08000000
+#define PPC_FEATURE_HAS_MMU 0x04000000
+#define PPC_FEATURE_UNIFIED_CACHE 0x01000000
+#define PPC_FEATURE_HAS_SPE 0x00800000
+#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000
+#define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000
+#define PPC_FEATURE_NO_TB 0x00100000
+#define PPC_FEATURE_POWER4 0x00080000
+#define PPC_FEATURE_POWER5 0x00040000
+#define PPC_FEATURE_POWER5_PLUS 0x00020000
+#define PPC_FEATURE_CELL 0x00010000
+#define PPC_FEATURE_BOOKE 0x00008000
+#define PPC_FEATURE_SMT 0x00004000
+#define PPC_FEATURE_ICACHE_SNOOP 0x00002000
+#define PPC_FEATURE_ARCH_2_05 0x00001000
+#define PPC_FEATURE_HAS_DFP 0x00000400
+#define PPC_FEATURE_POWER6_EXT 0x00000200
+#define PPC_FEATURE_ARCH_2_06 0x00000100
+#define PPC_FEATURE_HAS_VSX 0x00000080
+#define PPC_FEATURE_TRUE_LE 0x00000002
+#define PPC_FEATURE_PPC_LE 0x00000001
+
+#define PPC_FEATURE2_ARCH_2_07 0x80000000
+#define PPC_FEATURE2_HTM 0x40000000
+#define PPC_FEATURE2_DSCR 0x20000000
+#define PPC_FEATURE2_EBB 0x10000000
+#define PPC_FEATURE2_ISEL 0x08000000
+#define PPC_FEATURE2_TAR 0x04000000
+#define PPC_FEATURE2_HAS_VEC_CRYPTO 0x02000000
+#define PPC_FEATURE2_HTM_NOSC 0x01000000
+#define PPC_FEATURE2_ARCH_3_00 0x00800000
+#define PPC_FEATURE2_HAS_IEEE128 0x00400000
+#define PPC_FEATURE2_DARN 0x00200000
+#define PPC_FEATURE2_SCV 0x00100000
+#define PPC_FEATURE2_HTM_NOSUSPEND 0x00080000
+
#endif /* !_MACHINE_ELF_H_ */
diff --git a/sys/arch/powerpc64/powerpc64/cpu.c b/sys/arch/powerpc64/powerpc64/cpu.c
index 3f0bd032eab..252356be0c6 100644
--- a/sys/arch/powerpc64/powerpc64/cpu.c
+++ b/sys/arch/powerpc64/powerpc64/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.28 2023/10/24 13:20:10 claudio Exp $ */
+/* $OpenBSD: cpu.c,v 1.29 2024/07/21 16:49:26 jca Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -226,6 +226,10 @@ cpu_init_features(void)
{
uint32_t pvr = mfpvr();
+ cpu_features = PPC_FEATURE_32 | PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU |
+ PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_ALTIVEC |
+ PPC_FEATURE_HAS_VSX;
+
switch (CPU_VERSION(pvr)) {
case CPU_IBMPOWER9:
case CPU_IBMPOWER9P:
@@ -233,6 +237,9 @@ cpu_init_features(void)
cpu_features2 |= PPC_FEATURE2_DARN;
break;
}
+
+ hwcap = cpu_features;
+ hwcap2 = cpu_features2;
}
void