3 This file is part of the Free Pascal run time library
.
4 Copyright (c
) 1999-2000 by Pierre Muller
8 See the file COPYING
.FPC
, included
in this distribution
,
9 for details about the copyright
.
11 This program is distributed
in the hope that it will be useful
,
12 but WITHOUT ANY WARRANTY
; without even the implied warranty of
13 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
.
15 **********************************************************************}
19 procedure
npxsetup(prog_name
: string
);
27 dxeload
,dpmiexcp
,strings
;
30 emu_entry_type
= function(exc
: pexception_state
) : longint
;
33 _emu_entry
: emu_entry_type
;
36 procedure
_control87(mask1
,mask2
: longint
);
38 { Copyright (C
) 1995 DJ Delorie
, see COPYING
.DJ
for details
}
39 { from file cntrl87
.s
in src
/libc/pc_hw
/fpu
}
41 { make room on stack
}
47 { OK
; we have the old value ready
}
51 andl
%eax
, %ecx
{ the bits we want to keep
}
54 andl mask1
, %edx
{ the bits we want to change
}
56 orl
%ecx
, %edx
{ the new value
}
64 { the problem with the stack that is
not cleared
}
65 function
emu_entry(exc
: pexception_state
) : longint
;
67 emu_entry
:=_emu_entry(exc
);
71 function
nofpsig( sig
: longint
) : longint
;
73 last_eip
: longint
= 0;
77 {if last_eip
=djgpp_exception_state^
.__eip
then
79 writeln('emu call two times at same address');
80 dpmi_set_coprocessor_emulation(1);
84 last_eip
:=djgpp_exception_state^
.__eip
;
85 res
:=emu_entry(djgpp_exception_state
);
88 writeln('emu call failed. res = ',res
);
89 dpmi_set_coprocessor_emulation(1);
93 dpmi_longjmp(pdpmi_jmp_buf(djgpp_exception_state
)^
, djgpp_exception_state^
.__eax
);
101 procedure restore_DPMI_fpu_state
;
104 { Enable Coprocessor
, no exceptions
}
105 dpmi_set_coprocessor_emulation(1);
107 writeln(stderr,'Coprocessor restored ');
111 { function _detect_80387
: boolean
;
112 not used because of the underscore problem
}
117 function
getenv(const envvar
:string):string;
118 { Copied here
, preserves uses
Dos (PFV
) }
125 _envvar
:=upcase(envvar
);
128 while assigned(hp^
) do
132 if copy(hs
,1,eqpos-1
)=_envvar
then
134 getenv
:=copy(hs
,eqpos
+1,255);
142 function __detect_80387
:byte;external name
'__detect_80387';
144 procedure
npxsetup(prog_name
: string
);
148 have_80387
: boolean
;
151 veryfirst
: boolean
= True
;
154 if (length(cp
)>0) and (upcase(cp
[1])='N') then
158 dpmi_set_coprocessor_emulation(1);
164 if (length(cp
)>0) and (upcase(cp
[1])='Q') then
166 if not have_80387
then
168 writeln(stderr,'80387 detected.');
173 { mask all exceptions
, except invalid operation
}
174 { change to same value as
in v2prt0
.as (PM
) }
175 _control87($0332, $ffff)
179 { Flags value
3 means coprocessor emulation
, exceptions to us
}
180 if (dpmi_set_coprocessor_emulation(3)<>0) then
182 writeln(stderr,'Warning: Coprocessor not present and DPMI setup failed!');
183 writeln(stderr,' If application attempts floating operations system may hang!');
187 cp
:=getenv('EMU387');
190 for i
:=length(prog_name
) downto
1 do
191 if (prog_name
[i
]='\') or (prog_name[i]='/') then
194 cp:=copy(prog_name,1,i);
195 cp:=cp+'wmemu387
.dxe
';
198 _emu_entry:=emu_entry_type(emu_p);
201 writeln(cp+' load failed
!');
208 exitproc:=@restore_DPMI_fpu_state;
210 signal(SIGNOFP,@nofpsig);
216 npxsetup(paramstr(0));
220 Revision 1.1 2002/02/19 08:25:08 sasu
223 Revision 1.1 2000/07/13 06:30:37 michael
226 Revision 1.8 2000/02/09 16:59:28 peter
229 Revision 1.7 2000/01/07 16:41:31 daniel
232 Revision 1.6 2000/01/07 16:32:23 daniel
233 * copyright 2000 added
235 Revision 1.5 1999/09/08 18:55:50 peter