1/* Test if POWER vscr read by ucontext.
2 Copyright (C) 2018-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 <support/check.h>
20#include <sys/auxv.h>
21#include <ucontext.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <stdint.h>
25#include <altivec.h>
26
27#define SAT 0x1
28
29/* This test is supported only on POWER 5 or higher. */
30#define PPC_CPU_SUPPORTED (PPC_FEATURE_POWER5 | PPC_FEATURE_POWER5_PLUS \
31 | PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06 \
32 | PPC_FEATURE2_ARCH_2_07)
33static int
34do_test (void)
35{
36
37 if (!(getauxval(AT_HWCAP2) & PPC_CPU_SUPPORTED))
38 {
39 if (!(getauxval(AT_HWCAP) & PPC_CPU_SUPPORTED))
40 FAIL_UNSUPPORTED("This test is unsupported on POWER < 5\n");
41 }
42
43 uint32_t vscr[4] __attribute__ ((aligned (16)));
44 uint32_t* vscr_ptr = vscr;
45 uint32_t vscr_word;
46 ucontext_t ucp;
47 __vector unsigned int v0 = {0};
48 __vector unsigned int v1 = {0};
49
50 /* Set SAT bit in VSCR register. */
51 asm volatile (".machine push;\n"
52 ".machine \"power5\";\n"
53 ".machine altivec;\n"
54 "vspltisb %0,0;\n"
55 "vspltisb %1,-1;\n"
56 "vpkuwus %0,%0,%1;\n"
57 "mfvscr %0;\n"
58 "stvx %0,0,%2;\n"
59 ".machine pop;"
60 : "=v" (v0), "=v" (v1)
61 : "r" (vscr_ptr)
62 : "memory");
63#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
64 vscr_word = vscr[0];
65#else
66 vscr_word = vscr[3];
67#endif
68
69 if ((vscr_word & SAT) != SAT)
70 {
71 FAIL_EXIT1("FAIL: SAT bit is not set.\n");
72 }
73
74 if (getcontext (ucp: &ucp))
75 {
76 FAIL_EXIT1("FAIL: getcontext error\n");
77 }
78 if (ucp.uc_mcontext.v_regs->vscr.vscr_word != vscr_word)
79 {
80 FAIL_EXIT1("FAIL: ucontext vscr does not match with vscr\n");
81 }
82 return 0;
83}
84
85#include <support/test-driver.c>
86

source code of glibc/sysdeps/powerpc/powerpc64/tst-ucontext-ppc64-vscr.c