Mail Archives: djgpp-workers/1999/09/01/07:59:22
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 -