Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/os-tests/tests/xsave/fpregs.c
+++ new/usr/src/test/os-tests/tests/xsave/fpregs.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2023 Oxide Computer Company
14 14 */
15 15
16 16 /*
17 17 * This test verifies the following:
18 18 *
19 19 * o xregs and fpregs report the same content for the xmm registers at least.
20 20 * o A write to xregs is reflected in reads of fpregs.
21 21 * o A write to the fpregs is reflected in reads of xregs and doesn't
22 22 * clobber additional state in xregs.
23 23 * o A thread in our victim process sees the final state here and can print
24 24 * that out.
25 25 * o As a side effect it makes sure that libproc isn't incorrectly caching
26 26 * register info on handles.
27 27 *
28 28 * We use the xsu_dump process of the same bitness as us.
29 29 */
30 30
31 31 #include <err.h>
32 32 #include <stdlib.h>
33 33 #include <errno.h>
34 34 #include <string.h>
35 35
36 36 #include "xsave_util.h"
37 37
38 38 static xsu_fpu_t fpu;
39 39
40 40 int
41 41 main(int argc, char *argv[])
42 42 {
43 43 uint32_t seed, hwsup;
44 44 unsigned long ul;
45 45 char *eptr;
46 46 prxregset_t *prx, *cmp_prx;
47 47 size_t prx_len, cmp_prx_len;
48 48 xsu_proc_t xp;
49 49 fpregset_t fpr;
50 50
51 51 if (argc != 5) {
52 52 errx(EXIT_FAILURE, "missing args: <prog> <output file> "
53 53 "<seed> <func>");
54 54 }
55 55
56 56 errno = 0;
57 57 ul = strtoul(argv[3], &eptr, 0);
58 58 if (errno != 0 || *eptr != '\0') {
59 59 errx(EXIT_FAILURE, "seed value is bad: %s", argv[3]);
60 60 }
61 61
62 62 #if defined(_LP64)
63 63 if (ul > UINT32_MAX) {
64 64 errx(EXIT_FAILURE, "seed %s, exceeds [0, UINT32_MAX]", argv[3]);
65 65 }
66 66 #endif
67 67
68 68 seed = (uint32_t)ul;
69 69 hwsup = xsu_hwsupport();
70 70 xsu_fill(&fpu, hwsup, seed);
71 71 xsu_fpu_to_xregs(&fpu, hwsup, &prx, &prx_len);
72 72
73 73 (void) memset(&xp, 0, sizeof (xsu_proc_t));
74 74 xp.xp_prog = argv[1];
75 75 xp.xp_arg = argv[2];
76 76 xp.xp_object = "a.out";
77 77 xp.xp_symname = argv[4];
78 78 xsu_proc_bkpt(&xp);
79 79
80 80 /*
81 81 * First get the xregs into a reasonable place.
82 82 */
83 83 if (Plwp_setxregs(xp.xp_proc, 1, prx, prx_len) != 0) {
84 84 err(EXIT_FAILURE, "failed to set target's xregs");
85 85 }
86 86
87 87 /*
88 88 * Now that we have that, let's go and get the fpregs. Because of
89 89 * differences between the 32-bit representation and the xsave state in
90 90 * the xregs, we stick to different checking in an ILP32 vs. LP64 pieces
91 91 * of this.
92 92 */
93 93 if (Plwp_getfpregs(xp.xp_proc, 1, &fpr) != 0) {
94 94 err(EXIT_FAILURE, "failed to get the fp registers");
95 95 }
96 96
97 97 if (!xsu_fpregs_cmp(&fpr, prx)) {
98 98 errx(EXIT_FAILURE, "fpregs do not reflect xsave changes!");
99 99 }
100 100 (void) printf("TEST PASSED: fpregs read respects xregs write\n");
101 101
102 102 /*
103 103 * Override the xmm registers with the known variant of the seed and set
104 104 * that. Update the xregs data so we can later compare them usefully.
105 105 */
106 106 xsu_fpregset_xmm_set(&fpr, seed + INT32_MAX);
107 107 xsu_xregs_xmm_set(prx, seed + INT32_MAX);
108 108 if (Plwp_setfpregs(xp.xp_proc, 1, &fpr) != 0) {
109 109 err(EXIT_FAILURE, "failed to set fpregs");
110 110 }
111 111
112 112 if (Plwp_getxregs(xp.xp_proc, 1, &cmp_prx, &cmp_prx_len) != 0) {
113 113 err(EXIT_FAILURE, "failed to get comparison xregs");
114 114 }
115 115
116 116 if (!xsu_fpregs_cmp(&fpr, cmp_prx)) {
117 117 errx(EXIT_FAILURE, "fpregs do not reflect xsave changes!");
118 118 }
119 119 (void) printf("TEST PASSED: xregs read respects fpregs write\n");
120 120
121 121 if (!xsu_xregs_comp_equal(prx, cmp_prx, PRX_INFO_YMM)) {
122 122 errx(EXIT_FAILURE, "%%ymm state changed across fpregs write");
123 123 }
124 124 (void) printf("TEST PASSED: fpregs did not change other xregs "
125 125 "components\n");
126 126
127 127 xsu_proc_finish(&xp);
128 128
129 129 return (EXIT_SUCCESS);
130 130 }
|
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX