]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/tst-set_ppr.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / powerpc / tst-set_ppr.c
1 /* Test the implementation of __ppc_set_ppr_* functions.
2 Copyright (C) 2017-2019 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 <http://www.gnu.org/licenses/>. */
18
19 #include <inttypes.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <sys/auxv.h>
23
24 #include <sys/platform/ppc.h>
25
26 #include <support/test-driver.h>
27
28 #ifdef __powerpc64__
29 typedef uint64_t ppr_t;
30 # define MFPPR "mfppr"
31 /* The thread priority value is obtained from bits 11:13. */
32 # define EXTRACT_THREAD_PRIORITY(x) ((x >> 50) & 7)
33 #else
34 typedef uint32_t ppr_t;
35 # define MFPPR "mfppr32"
36 /* For 32-bit, the upper 32 bits of the Program Priority Register (PPR)
37 are used, so the thread priority value is obtained from bits 43:46. */
38 # define EXTRACT_THREAD_PRIORITY(x) ((x >> 18) & 7)
39 #endif /* !__powerpc64__ */
40
41 /* Read the thread priority value set in the PPR. */
42 static __inline__ ppr_t
43 get_thread_priority (void)
44 {
45 /* Read the PPR. */
46 ppr_t ppr;
47 asm volatile (MFPPR" %0" : "=r"(ppr));
48 /* Return the thread priority value. */
49 return EXTRACT_THREAD_PRIORITY (ppr);
50 }
51
52 /* Check the thread priority bits of PPR are set as expected. */
53 uint8_t
54 check_thread_priority (uint8_t expected)
55 {
56 ppr_t actual = get_thread_priority ();
57
58 if (actual != expected)
59 {
60 printf ("FAIL: Expected %"PRIu8" got %"PRIuMAX".\n", expected,
61 (uintmax_t) actual);
62 return 1;
63 }
64 printf ("PASS: Thread priority set to %"PRIu8" correctly.\n", expected);
65 return 0;
66 }
67
68 /* The Power ISA 2.06 allows the following thread priorities for any
69 problem state program: low (2), medium low (3), and medium (4).
70 Power ISA 2.07b added very low (1).
71 Check whether the values set by __ppc_set_ppr_* are correct. */
72 static int
73 do_test (void)
74 {
75 /* Check for the minimum required Power ISA to run these tests. */
76 if ((getauxval (AT_HWCAP) & PPC_FEATURE_ARCH_2_06) == 0)
77 {
78 printf ("Requires an environment that implements the Power ISA version"
79 " 2.06 or greater.\n");
80 return EXIT_UNSUPPORTED;
81 }
82
83 uint8_t rc = 0;
84
85 #ifdef _ARCH_PWR8
86 __ppc_set_ppr_very_low ();
87 rc |= check_thread_priority (1);
88 #endif /* _ARCH_PWR8 */
89
90 __ppc_set_ppr_low ();
91 rc |= check_thread_priority (2);
92
93 __ppc_set_ppr_med_low ();
94 rc |= check_thread_priority (3);
95
96 __ppc_set_ppr_med ();
97 rc |= check_thread_priority (4);
98
99 return rc;
100 }
101
102 #include <support/test-driver.c>