www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/09/01/07:59:22

Date: Wed, 1 Sep 1999 12:21:51 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Morten Welinder <terra AT diku DOT dk>
cc: sandmann AT clio DOT rice DOT edu, dj AT delorie DOT com, djgpp-workers AT delorie DOT com
Subject: Re: FWAIT emulation in emu387.cc
In-Reply-To: <199908311406.QAA07544@tyr.diku.dk>
Message-ID: <Pine.SUN.3.91.990901122128.25D-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 31 Aug 1999, Morten Welinder wrote:

> FWAIT before another F-instruction(*) has been treated as a NOP ever
> since the FPU got onto the same chip as the CPU.

The particular case I used most in my testing is the v2.02 version of
`floor'.  The source is attached below, for your convenience.

As you see, here FWAIT is after FSTCW.  Do I understand correctly that
this is *not* the case you are describing?

What I've seen is that when `floor' is called on DOS, FWAIT never ends
up in the emulator, but on Windows it does, at least in the case of a
simple one-liner that calls `floor'.  (I tried some math functions
that don't issue FWAIT, and they indeed run without problems on both
DOS and Windows.)

The only way I can understand this is that Windows sets the two bits
which Intel says will cause FWAIT to trigger the coprocessor not
present exception.  (Of course, there might be some bug somewhere,
too.)

> In particular the exception EIP won't point to the FWAIT.

If FWAIT is a NOP, and the exception is triggered by the FP
instruction that follows it, then EIP should point to that other
instruction and everything is oky-doky, right?

In other words, if FWAIT is a NOP, then it is not an FP instruction
that needs emulating, and the emulator doesn't need to bother about
that case.  Am I missing something?

I'm interested in the value of EIP when FWAIT *does* trigger an
exception.  Is there any possibility that when this happens, EIP
would point to something other than the instruction that triggered the
exception, i.e. FWAIT itself?


/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
	.globl	_floor
_floor:
	pushl	%ebp
	movl	%esp,%ebp
	subl	$8,%esp         /* -4 = old CW, -2 = new CW */

	fstcw	-4(%ebp)
	fwait
	movw	-4(%ebp),%ax
	andw	$0xf3ff,%ax
	orw	$0x0400,%ax
	movw	%ax,-2(%ebp)
	fldcww	-2(%ebp)

	fldl	8(%ebp)
	frndint

	fldcww	-4(%ebp)

	movl	%ebp,%esp
	popl	%ebp
	ret

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019