2015-10-23 00:26:58 +00:00
|
|
|
/* Check __ppc_get_hwcap() and __ppc_get_at_plaftorm() functionality.
|
2020-01-01 00:14:33 +00:00
|
|
|
Copyright (C) 2015-2020 Free Software Foundation, Inc.
|
2015-10-23 00:26:58 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2015-10-23 00:26:58 +00:00
|
|
|
|
|
|
|
/* Tests if the hwcap, hwcap2 and platform data are stored in the TCB. */
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2017-02-21 13:16:49 +00:00
|
|
|
#include <support/check.h>
|
|
|
|
#include <support/xthread.h>
|
|
|
|
|
2015-10-23 00:26:58 +00:00
|
|
|
#include <sys/auxv.h>
|
|
|
|
|
|
|
|
#include <dl-procinfo.h>
|
|
|
|
|
|
|
|
#ifndef STATIC_TST_HWCAP
|
|
|
|
#undef PROCINFO_DECL
|
|
|
|
#include <dl-procinfo.c>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Offsets copied from tcb-offsets.h. */
|
|
|
|
|
|
|
|
#ifdef __powerpc64__
|
|
|
|
# define __TPREG "r13"
|
|
|
|
# define __HWCAPOFF -28776
|
|
|
|
# define __ATPLATOFF -28764
|
|
|
|
#else
|
|
|
|
# define __TPREG "r2"
|
|
|
|
# define __HWCAPOFF -28736
|
|
|
|
# define __HWCAP2OFF -28732
|
|
|
|
# define __ATPLATOFF -28724
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint64_t check_tcbhwcap (long tid)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t tcb_at_platform, at_platform;
|
|
|
|
uint64_t hwcap, hwcap2, tcb_hwcap;
|
|
|
|
const char *at_platform_string;
|
|
|
|
|
|
|
|
/* Testing if the hwcap/hwcap2 data is correctly initialized by
|
|
|
|
TLS_TP_INIT. */
|
|
|
|
|
|
|
|
register unsigned long __tp __asm__ (__TPREG);
|
|
|
|
|
|
|
|
#ifdef __powerpc64__
|
|
|
|
__asm__ ("ld %0,%1(%2)\n"
|
|
|
|
: "=r" (tcb_hwcap)
|
|
|
|
: "i" (__HWCAPOFF), "b" (__tp));
|
|
|
|
#else
|
|
|
|
uint64_t h1, h2;
|
|
|
|
|
|
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
|
|
: "=r" (h1)
|
|
|
|
: "i" (__HWCAPOFF), "b" (__tp));
|
|
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
|
|
: "=r" (h2)
|
|
|
|
: "i" (__HWCAP2OFF), "b" (__tp));
|
|
|
|
tcb_hwcap = (h1 >> 32) << 32 | (h2 >> 32);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hwcap = getauxval (AT_HWCAP);
|
|
|
|
hwcap2 = getauxval (AT_HWCAP2);
|
|
|
|
|
|
|
|
/* hwcap contains only the latest supported ISA, the code checks which is
|
|
|
|
and fills the previous supported ones. This is necessary because the
|
|
|
|
same is done in hwcapinfo.c when setting the values that are copied to
|
|
|
|
the TCB. */
|
|
|
|
|
|
|
|
if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
|
|
|
|
hwcap |= PPC_FEATURE_ARCH_2_06
|
|
|
|
| PPC_FEATURE_ARCH_2_05
|
|
|
|
| PPC_FEATURE_POWER5_PLUS
|
|
|
|
| PPC_FEATURE_POWER5
|
|
|
|
| PPC_FEATURE_POWER4;
|
|
|
|
else if (hwcap & PPC_FEATURE_ARCH_2_06)
|
|
|
|
hwcap |= PPC_FEATURE_ARCH_2_05
|
|
|
|
| PPC_FEATURE_POWER5_PLUS
|
|
|
|
| PPC_FEATURE_POWER5
|
|
|
|
| PPC_FEATURE_POWER4;
|
|
|
|
else if (hwcap & PPC_FEATURE_ARCH_2_05)
|
|
|
|
hwcap |= PPC_FEATURE_POWER5_PLUS
|
|
|
|
| PPC_FEATURE_POWER5
|
|
|
|
| PPC_FEATURE_POWER4;
|
|
|
|
else if (hwcap & PPC_FEATURE_POWER5_PLUS)
|
|
|
|
hwcap |= PPC_FEATURE_POWER5
|
|
|
|
| PPC_FEATURE_POWER4;
|
|
|
|
else if (hwcap & PPC_FEATURE_POWER5)
|
|
|
|
hwcap |= PPC_FEATURE_POWER4;
|
|
|
|
|
|
|
|
hwcap = (hwcap << 32) + hwcap2;
|
|
|
|
|
|
|
|
if ( tcb_hwcap != hwcap )
|
|
|
|
{
|
|
|
|
printf ("FAIL: __ppc_get_hwcap() - HWCAP is %" PRIx64 ". Should be %"
|
|
|
|
PRIx64 " for thread %ld.\n", tcb_hwcap, hwcap, tid);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same test for the platform number. */
|
|
|
|
__asm__ ("lwz %0,%1(%2)\n"
|
|
|
|
: "=r" (tcb_at_platform)
|
|
|
|
: "i" (__ATPLATOFF), "b" (__tp));
|
|
|
|
|
|
|
|
at_platform_string = (const char *) getauxval (AT_PLATFORM);
|
|
|
|
at_platform = _dl_string_platform (at_platform_string);
|
|
|
|
|
|
|
|
if ( tcb_at_platform != at_platform )
|
|
|
|
{
|
|
|
|
printf ("FAIL: __ppc_get_at_platform() - AT_PLATFORM is %x. Should be %x"
|
|
|
|
" for thread %ld\n", tcb_at_platform, at_platform, tid);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *t1 (void *tid)
|
|
|
|
{
|
|
|
|
if (check_tcbhwcap ((long) tid))
|
|
|
|
{
|
|
|
|
pthread_exit (tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_exit (NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
|
|
|
|
|
|
|
pthread_t threads[2];
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init (&attr);
|
|
|
|
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
|
|
|
|
|
|
|
|
long i = 0;
|
|
|
|
|
|
|
|
/* Check for main. */
|
|
|
|
if (check_tcbhwcap (i))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for other thread. */
|
|
|
|
i++;
|
2017-02-21 13:16:49 +00:00
|
|
|
threads[i] = xpthread_create (&attr, t1, (void *)i);
|
2015-10-23 00:26:58 +00:00
|
|
|
|
|
|
|
pthread_attr_destroy (&attr);
|
2017-02-21 13:16:49 +00:00
|
|
|
TEST_VERIFY_EXIT (xpthread_join (threads[i]) == NULL);
|
2015-10-23 00:26:58 +00:00
|
|
|
|
|
|
|
printf("PASS: HWCAP, HWCAP2 and AT_PLATFORM are correctly set in the TCB for"
|
|
|
|
" all threads.\n");
|
|
|
|
|
|
|
|
pthread_exit (NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-21 13:16:49 +00:00
|
|
|
#include <support/test-driver.c>
|