* refactored SysResetFPU into SysInitFPU and SysResetFPU

git-svn-id: trunk@8966 -
This commit is contained in:
florian 2007-10-28 12:06:49 +00:00
parent ba224d6b0d
commit 7da7364ee7
18 changed files with 102 additions and 32 deletions

View File

@ -361,9 +361,11 @@ end;
begin begin
SysResetFPU;
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
StackLength := CheckInitialStkLen(InitialStkLen); StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ OS specific startup } { OS specific startup }

View File

@ -21,9 +21,10 @@ const
cpu_has_edsp : boolean = false; cpu_has_edsp : boolean = false;
in_edsp_test : boolean = false; in_edsp_test : boolean = false;
procedure fpc_cpuinit;
begin
{$if not(defined(wince)) and not(defined(gba)) and not(defined(nds)) and not(defined(FPUSOFT)) and not(defined(FPULIBGCC))} {$if not(defined(wince)) and not(defined(gba)) and not(defined(nds)) and not(defined(FPUSOFT)) and not(defined(FPULIBGCC))}
{$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{ Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL } { Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL }
asm asm
rfs r0 rfs r0
@ -31,7 +32,12 @@ begin
orr r0,r0,#0x00070000 orr r0,r0,#0x00070000
wfs r0 wfs r0
end; end;
end;
{$endif} {$endif}
procedure fpc_cpuinit;
begin
SysInitFPU;
end; end;
{$ifdef wince} {$ifdef wince}
@ -41,6 +47,11 @@ function _controlfp(new: DWORD; mask: DWORD): DWORD; cdecl; external 'coredll';
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif} Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin begin
softfloat_exception_flags:=0; softfloat_exception_flags:=0;
end;
{$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal; softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
{ Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL } { Enable FPU exceptions, but disable INEXACT, UNDERFLOW, DENORMAL }
{ FPU precision 64 bit, rounding to nearest, affine infinity } { FPU precision 64 bit, rounding to nearest, affine infinity }

View File

@ -259,6 +259,8 @@ var
begin begin
{$ifdef FPC_HAS_FEATURE_FPU} {$ifdef FPC_HAS_FEATURE_FPU}
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
{$endif FPC_HAS_FEATURE_FPU} {$endif FPC_HAS_FEATURE_FPU}
{$ifdef FPC_HAS_FEATURE_CONSOLEIO} {$ifdef FPC_HAS_FEATURE_CONSOLEIO}

View File

@ -1596,10 +1596,7 @@ begin
ErrorOfSig:=207; {'Coprocessor Error'} ErrorOfSig:=207; {'Coprocessor Error'}
{ if exceptions then Reset FPU and reload control word } { if exceptions then Reset FPU and reload control word }
if (FPUStatus and FPU_ExceptionMask)<>0 then if (FPUStatus and FPU_ExceptionMask)<>0 then
asm SysResetFPU;
fninit
fldcw FPU_ControlWord
end;
end; end;
4 : ErrorOfSig:=215; {'Overflow'} 4 : ErrorOfSig:=215; {'Overflow'}
1, {'Debug'} 1, {'Debug'}

View File

@ -1262,8 +1262,9 @@ const
mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm; mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif} {$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
var var
{ these locals are so we don't have to hack pic code in the assembler } { these locals are so we don't have to hack pic code in the assembler }
localmxcsr: dword; localmxcsr: dword;
@ -1271,7 +1272,6 @@ Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin begin
localfpucw:=Default8087CW; localfpucw:=Default8087CW;
asm asm
fninit
fldcw localfpucw fldcw localfpucw
fwait fwait
end; end;
@ -1283,11 +1283,21 @@ Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
ldmxcsr localmxcsr ldmxcsr localmxcsr
end; end;
end; end;
softfloat_exception_flags:=0;
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal; softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
end; end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
asm
fnclex
fwait
end;
softfloat_exception_flags:=0;
end;
{ because of the brain dead sse detection on x86, this test is post poned } { because of the brain dead sse detection on x86, this test is post poned }
procedure fpc_cpucodeinit; procedure fpc_cpucodeinit;
begin begin
@ -1307,6 +1317,8 @@ procedure fpc_cpucodeinit;
has_sse_support:=os_supports_sse; has_sse_support:=os_supports_sse;
has_mmx_support:=mmx_support; has_mmx_support:=mmx_support;
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
{$ifdef USE_FASTMOVE} {$ifdef USE_FASTMOVE}
setup_fastmove; setup_fastmove;
{$endif} {$endif}

View File

@ -1665,11 +1665,19 @@ end;
procedure SysResetFpu;{$ifdef SYSTEMINLINE}inline;{$endif} procedure SysResetFpu;{$ifdef SYSTEMINLINE}inline;{$endif}
begin begin
softfloat_exception_flags:=0; softfloat_exception_flags:=0;
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
end; end;
{$endif FPC_SYSTEM_HAS_SYSRESETFPU} {$endif FPC_SYSTEM_HAS_SYSRESETFPU}
{$ifndef FPC_SYSTEM_HAS_SYSINITFPU}
procedure SysInitFpu;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
end;
{$endif FPC_SYSTEM_HAS_SYSINITFPU}
{$ifndef FPC_SYSTEM_HAS_SWAPENDIAN} {$ifndef FPC_SYSTEM_HAS_SWAPENDIAN}
function SwapEndian(const AValue: SmallInt): SmallInt; function SwapEndian(const AValue: SmallInt): SmallInt;
begin begin

View File

@ -795,6 +795,7 @@ Procedure SysInitExceptions;
procedure SysInitStdIO; procedure SysInitStdIO;
{$endif FPC_HAS_FEATURE_CONSOLEIO} {$endif FPC_HAS_FEATURE_CONSOLEIO}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif} Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
{***************************************************************************** {*****************************************************************************
Abstract/Assert/Error Handling Abstract/Assert/Error Handling

View File

@ -24,6 +24,7 @@ Var
procedure InitThread(stklen:SizeUInt); procedure InitThread(stklen:SizeUInt);
begin begin
SysResetFPU; SysResetFPU;
SysInitFPU;
{$ifndef HAS_MEMORYMANAGER} {$ifndef HAS_MEMORYMANAGER}
{ initialize this thread's heap } { initialize this thread's heap }
InitHeapThread; InitHeapThread;

View File

@ -307,6 +307,8 @@ begin
{$endif} {$endif}
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
{$if defined(cpupowerpc)} {$if defined(cpupowerpc)}
// some PPC kernels set the exception bits FE0/FE1 in the MSR to zero, // some PPC kernels set the exception bits FE0/FE1 in the MSR to zero,
// disabling all FPU exceptions. Enable them again. // disabling all FPU exceptions. Enable them again.

View File

@ -393,11 +393,13 @@ end;
begin begin
SysResetFPU;
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := CheckInitialStkLen(InitialStkLen); StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
{ OS specific startup } { OS specific startup }
MOS_ambMsg:=nil; MOS_ambMsg:=nil;
MOS_origDir:=0; MOS_origDir:=0;

View File

@ -140,6 +140,7 @@ end;
(* procedure InitThread(stklen:cardinal); (* procedure InitThread(stklen:cardinal);
begin begin
SysResetFPU; SysResetFPU;
SysInitFPU;
{ ExceptAddrStack and ExceptObjectStack are threadvars } { ExceptAddrStack and ExceptObjectStack are threadvars }
{ so every thread has its on exception handling capabilities } { so every thread has its on exception handling capabilities }
SysInitExceptions; SysInitExceptions;

View File

@ -1192,8 +1192,8 @@ end;
{$IFDEF MORPHOS} {$IFDEF MORPHOS}
{ this is only required for MorphOS } { this is only required for MorphOS }
{$define FPC_SYSTEM_HAS_SYSRESETFPU} {$define FPC_SYSTEM_HAS_SYSINITFPU}
procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif} procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
var tmp: array[0..1] of dword; var tmp: array[0..1] of dword;
begin begin
asm asm
@ -1208,6 +1208,12 @@ begin
softfloat_exception_flags:=0; softfloat_exception_flags:=0;
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal; softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
end; end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_flags:=0;
end;
{$ENDIF} {$ENDIF}
{$ifndef FPC_SYSTEM_HAS_MEM_BARRIER} {$ifndef FPC_SYSTEM_HAS_MEM_BARRIER}

View File

@ -45,20 +45,27 @@ function get_got : pointer;assembler;nostackframe;[public, alias: 'FPC_GETGOT'];
end; end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU} {$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif} Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin begin
softfloat_exception_flags:=0;
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal; softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
{ enable div by 0 and invalid operation fpu exceptions { enable div by 0 and invalid operation fpu exceptions
round towards zero; ieee compliant arithmetics } round towards zero; ieee compliant arithmetics }
set_fsr((get_fsr and $3fbfffff) or $09000000); set_fsr((get_fsr and $3fbfffff) or $09000000);
end; end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
softfloat_exception_flags:=0;
end;
procedure fpc_cpuinit; procedure fpc_cpuinit;
begin begin
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
end; end;

View File

@ -192,6 +192,9 @@ threadvar
function GetCommandLine : pchar; function GetCommandLine : pchar;
stdcall;external KernelDLL name 'GetCommandLineA'; stdcall;external KernelDLL name 'GetCommandLineA';
function GetCommandLineW : pwidechar;
stdcall;external KernelDLL name 'GetCommandLineW';
function GetCurrentProcessId:DWORD; function GetCurrentProcessId:DWORD;
stdcall; external KernelDLL name 'GetCurrentProcessId'; stdcall; external KernelDLL name 'GetCurrentProcessId';

View File

@ -379,7 +379,6 @@ procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
xorl %eax,%eax xorl %eax,%eax
movw %ss,%ax movw %ss,%ax
movl %eax,_SS movl %eax,_SS
call SysResetFPU
xorl %ebp,%ebp xorl %ebp,%ebp
call PASCALMAIN call PASCALMAIN
popl %ebp popl %ebp
@ -1110,6 +1109,11 @@ begin
StackBottom := StackTop - StackLength; StackBottom := StackTop - StackLength;
{ get some helpful informations } { get some helpful informations }
GetStartupInfo(@startupinfo); GetStartupInfo(@startupinfo);
SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
{ some misc Win32 stuff } { some misc Win32 stuff }
hprevinst:=0; hprevinst:=0;
if not IsLibrary then if not IsLibrary then

View File

@ -416,7 +416,6 @@ procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
xorl %rax,%rax xorl %rax,%rax
movw %ss,%ax movw %ss,%ax
movl %eax,_SS movl %eax,_SS
call SysResetFPU
xorl %rbp,%rbp xorl %rbp,%rbp
call PASCALMAIN call PASCALMAIN
popq %rbp popq %rbp
@ -1145,6 +1144,8 @@ end;
begin begin
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
StackLength := CheckInitialStkLen(InitialStkLen); StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := StackTop - StackLength; StackBottom := StackTop - StackLength;
{ get some helpful informations } { get some helpful informations }

View File

@ -1790,6 +1790,8 @@ end;
initialization initialization
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
StackLength := CheckInitialStkLen(InitialStkLen); StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := StackTop - StackLength; StackBottom := StackTop - StackLength;
{ some misc stuff } { some misc stuff }

View File

@ -27,6 +27,8 @@
procedure fpc_cpuinit; procedure fpc_cpuinit;
begin begin
SysResetFPU; SysResetFPU;
if not(IsLibrary) then
SysInitFPU;
end; end;
{$define FPC_SYSTEM_HAS_SPTR} {$define FPC_SYSTEM_HAS_SPTR}
@ -591,16 +593,10 @@ const
mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm; mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm;
{$define FPC_SYSTEM_HAS_SYSRESETFPU} {$define FPC_SYSTEM_HAS_SYSINITFPU}
Procedure SysResetFPU; Procedure SysInitFPU;
begin begin
asm asm
{ Win64 uses the fpu for ln etc. so we've to reset it as well
$ifndef WIN64}
{ initialize fpu }
fninit
fwait
{ $endif WIN64}
{$ifdef FPC_PIC} {$ifdef FPC_PIC}
movq fpucw@GOTPCREL(%rip),%rax movq fpucw@GOTPCREL(%rip),%rax
fldcw (%rax) fldcw (%rax)
@ -614,10 +610,22 @@ begin
{$endif FPC_PIC} {$endif FPC_PIC}
end ['RAX']; end ['RAX'];
{ x86-64 might use softfloat code } { x86-64 might use softfloat code }
softfloat_exception_flags:=0;
softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal; softfloat_exception_mask:=float_flag_underflow or float_flag_inexact or float_flag_denormal;
end; end;
{$define FPC_SYSTEM_HAS_SYSRESETFPU}
Procedure SysResetFPU;
begin
asm
{ initialize fpu }
fnclex
fwait
end;
{ x86-64 might use softfloat code }
softfloat_exception_flags:=0;
end;
{$ifndef FPC_SYSTEM_HAS_MEM_BARRIER} {$ifndef FPC_SYSTEM_HAS_MEM_BARRIER}
{$define FPC_SYSTEM_HAS_MEM_BARRIER} {$define FPC_SYSTEM_HAS_MEM_BARRIER}