From owner-freebsd-hackers@freebsd.org Fri Jun 16 13:23:36 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5F42BC08BD3 for ; Fri, 16 Jun 2017 13:23:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D0EDB7EF86 for ; Fri, 16 Jun 2017 13:23:35 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id v5GDNURm010143 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 16 Jun 2017 16:23:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua v5GDNURm010143 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id v5GDNUaL010142; Fri, 16 Jun 2017 16:23:30 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 16 Jun 2017 16:23:29 +0300 From: Konstantin Belousov To: karnajit wangkhem Cc: freebsd-hackers@freebsd.org Subject: Re: Undesirable FPU tag word value after PT_SETFPREGS on i386 Message-ID: <20170616132329.GY2088@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.2 (2017-04-18) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jun 2017 13:23:36 -0000 On Fri, Jun 16, 2017 at 03:19:35PM +0530, karnajit wangkhem wrote: > Hi All, > > Please help me understand why NaN is reported after PT_SETFPREGS. As a > result of this, if the inferior process contains an float operations, they > result in NaN. > This behavior is not seen in case of 32/64 bit binary on amd64. > > My env > kern.ostype: FreeBSD > kern.osrelease: 11.0-RELEASE-p1 > kern.version: FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 03:40:55 UTC > 2016 > root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC > hw.machine_arch: i386 > > Result of the below program on an i386 box > FPU TAG = ffff > FPU TAG = fe00 -> 11 11 11 10 00 00 00 00 FreeBSD 11 started translating between abridged and full FPU tags, but the translation appeared to be broken. Try this. diff --git a/sys/i386/isa/npx.c b/sys/i386/isa/npx.c index 5ca1ee507fe..de29adc4101 100644 --- a/sys/i386/isa/npx.c +++ b/sys/i386/isa/npx.c @@ -1108,7 +1108,7 @@ npx_fill_fpregs_xmm1(struct savexmm *sv_xmm, struct save87 *sv_87) sv_87->sv_ac[i] = sv_xmm->sv_fp[i].fp_acc; if ((penv_xmm->en_tw & (1 << i)) != 0) /* zero and special are set as valid */ - penv_87->en_tw &= ~(3 << i); + penv_87->en_tw &= ~(3 << i * 2); } } @@ -1143,7 +1143,7 @@ npx_set_fpregs_xmm(struct save87 *sv_87, struct savexmm *sv_xmm) penv_xmm->en_tw = 0; for (i = 0; i < 8; ++i) { sv_xmm->sv_fp[i].fp_acc = sv_87->sv_ac[i]; - if ((penv_87->en_tw && (3 << i)) != (3 << i)) + if ((penv_87->en_tw & (3 << i * 2)) != (3 << i * 2)) penv_xmm->en_tw |= 1 << i; } }