/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Michał Górny for Moritz Systems Technology Company Sp. z o.o.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_convert_xmm_s87.c,v 1.1 2020/10/15 17:44:44 mgorny Exp $");
ATF_TC(fsave_fxsave_hw);
ATF_TC_HEAD(fsave_fxsave_hw, tc)
{
atf_tc_set_md_var(tc, "descr",
"converting between FSAVE/FXSAVE comparing to actual results");
}
ATF_TC_BODY(fsave_fxsave_hw, tc)
{
struct save87 fsave, fsave_conv;
struct fxsave fxsave, fxsave_conv;
int i, j;
int mib[] = { CTL_MACHDEP, CPU_OSFXSR };
int has_fxsave;
size_t has_fxsave_size = sizeof(has_fxsave);
if (sysctl(mib, __arraycount(mib), &has_fxsave, &has_fxsave_size,
NULL, 0) == -1 || !has_fxsave)
atf_tc_skip("FXSAVE not supported");
for (i = 1; i <= __arraycount(ST_INPUTS); i++) {
unsigned long unused1, unused2;
__asm__ __volatile__(
"finit\n"
".loadfp:\n\t"
"fldt (%2)\n\t"
"add $0x10, %2\n\t"
"loop .loadfp\n\t"
"fxsave %5\n\t"
"fsave %4\n\t"
: "=b"(unused1), "=c"(unused2)
: "b"(ST_INPUTS), "c"(i), "m"(fsave), "m"(fxsave)
: "st"
);
/* Self-assertion for working FSAVE/FXSAVE */
ATF_REQUIRE_EQ(fsave.s87_cw, fxsave.fx_cw);
ATF_REQUIRE_EQ(fsave.s87_sw, fxsave.fx_sw);