xref: /illumos-gate/usr/src/test/os-tests/tests/xsave/xregs_set.c (revision 1e56f352c1c208679012bca47d552e127f5b1072)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Oxide Computer Company
14  */
15 
16 /*
17  * This is a program that is meant to be used as a target for libproc and mdb.
18  * It uses a CLI-based seed and sets its FPU to a set of known values. After
19  * that, we call a function that can be used as a no-op target to dump the FPU
20  * state, attempting to minimize the number of instructions inbetween
21  * operations. We use the 'yield(2)' system call and library function in libc
22  * for that as it's something that'll not really do much and it is very unlikely
23  * the compiler will use the FPU between function calls.
24  */
25 
26 #include <err.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <errno.h>
30 
31 #include "xsave_util.h"
32 
33 static xsu_fpu_t fpu;
34 
35 int
36 main(int argc, char *argv[])
37 {
38 	uint32_t hwsup;
39 	char *eptr;
40 	unsigned long ul;
41 
42 	if (argc != 2) {
43 		errx(EXIT_FAILURE, "missing required seed");
44 	}
45 
46 	errno = 0;
47 	ul = strtoul(argv[1], &eptr, 0);
48 	if (errno != 0 || *eptr != '\0') {
49 		errx(EXIT_FAILURE, "seed value is bad: %s", argv[3]);
50 	}
51 
52 	hwsup = xsu_hwsupport();
53 	xsu_fill(&fpu, hwsup, (uint32_t)ul);
54 	xsu_setfpu(&fpu, hwsup);
55 
56 	yield();
57 	return (EXIT_SUCCESS);
58 }
59