From: Jeremie Courreges-Anglas Subject: Re: powerpc minimal AT_HWCAP support To: tech@openbsd.org Cc: kettenis@openbsd.org, gkoehler@openbsd.org, brad@comstyle.com, miod@openbsd.org Date: Mon, 15 Jul 2024 14:30:29 +0200 On Mon, Jul 15, 2024 at 02:16:53PM +0200, Jeremie Courreges-Anglas wrote: > > powerpc only is macppc these days, but not all macppc have altivec. > The following diff exports the bare minimum for altivec to be checked > by userland through elf_aux_info. This could be enough for pixman and > mesa on OpenBSD to use the same code path as FreeBSD. I propose this > as a first step so that someone with more knowledge of that > architecture can build upon. > > Compile-tested only using clang-16 -target powerpc-unknown-openbsd. > > Feedback welcome. ok? Now with 100% more definition for hwcap. diff --git a/sys/arch/macppc/macppc/cpu.c b/sys/arch/macppc/macppc/cpu.c index f3dbe078fde..8c2580938d4 100644 --- a/sys/arch/macppc/macppc/cpu.c +++ b/sys/arch/macppc/macppc/cpu.c @@ -48,6 +48,7 @@ #include #include #include +#include #include /* SCOM addresses (24-bit) */ @@ -201,6 +202,8 @@ cpuattach(struct device *parent, struct device *dev, void *aux) ci->ci_intrdepth = -1; ci->ci_dev = dev; + hwcap = PPC_FEATURE_32 | PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_MMU; + pvr = ppc_mfpvr(); cpu = pvr >> 16; switch (cpu) { @@ -278,6 +281,9 @@ cpuattach(struct device *parent, struct device *dev, void *aux) #ifndef ALTIVEC /* altivec support absent from kernel */ ppc_altivec = 0; #endif + if (ppc_altivec) + hwcap |= PPC_FEATURE_HAS_ALTIVEC; + snprintf(cpu_model + strlen(cpu_model), sizeof(cpu_model) - strlen(cpu_model), " (Revision 0x%x)", pvr & 0xffff); diff --git a/sys/arch/powerpc/include/elf.h b/sys/arch/powerpc/include/elf.h index 6624f42f237..d3779d250e7 100644 --- a/sys/arch/powerpc/include/elf.h +++ b/sys/arch/powerpc/include/elf.h @@ -1,14 +1,93 @@ /* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ -/* - * This file is in the public domain. +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * Copyright (C) 1995-1997 Wolfgang Solfrank. + * Copyright (C) 1995-1997 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: cpu.h,v 1.11 2000/05/26 21:19:53 thorpej Exp $ */ #ifndef _MACHINE_ELF_H_ #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. */ -#endif /* !_MACHINE_ELF_H_ */ +#define __HAVE_CPU_HWCAP +#define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap; +extern unsigned long hwcap2; + +#define PPC_FEATURE_32 0x80000000 /* Always true */ +#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */ +#define PPC_FEATURE_601_INSTR 0x20000000 /* Defined on a 64-bit CPU */ +#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_ */ -- jca