mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 11:48:34 +02:00
* manually merged parts of r42260 to enable further merges
git-svn-id: branches/fixes_3_2@47905 -
This commit is contained in:
parent
7f5361f301
commit
91382b5deb
@ -1299,6 +1299,14 @@ const
|
||||
FPU_StackOverflow = $40;
|
||||
FPU_ExceptionMask = $ff;
|
||||
|
||||
MM_Invalid = 1;
|
||||
MM_Denormal = 2;
|
||||
MM_DivisionByZero = 4;
|
||||
MM_Overflow = 8;
|
||||
MM_Underflow = $10;
|
||||
MM_Precicion = $20;
|
||||
MM_ExceptionMask = $3f;
|
||||
|
||||
MM_MaskInvalidOp = %0000000010000000;
|
||||
MM_MaskDenorm = %0000000100000000;
|
||||
MM_MaskDivZero = %0000001000000000;
|
||||
|
@ -16,9 +16,16 @@
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
{ use a trampoline which pushes the return address for proper unwinding }
|
||||
Procedure SignalToHandleErrorAddrFrame (Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
|
||||
asm
|
||||
pushl addr
|
||||
jmp HandleErrorAddrFrame
|
||||
end;
|
||||
|
||||
procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; UContext: Pucontext);public name '_FPC_DEFAULTSIGHANDLER';cdecl;
|
||||
var
|
||||
res,fpustate : word;
|
||||
res,fpustate,MMState : word;
|
||||
begin
|
||||
res:=0;
|
||||
case sig of
|
||||
@ -27,35 +34,59 @@ begin
|
||||
{ this is not allways necessary but I don't know yet
|
||||
how to tell if it is or not PM }
|
||||
res:=200;
|
||||
if assigned(ucontext^.uc_mcontext.fpstate) then
|
||||
if SigInfo^.si_code<>FPE_INTDIV then
|
||||
begin
|
||||
FpuState:=ucontext^.uc_mcontext.fpstate^.sw;
|
||||
if (FpuState and FPU_ExceptionMask) <> 0 then
|
||||
if assigned(ucontext^.uc_mcontext.fpstate) then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=200
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
|
||||
res:=207
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
with ucontext^.uc_mcontext.fpstate^ do
|
||||
begin
|
||||
{ Reset Status word }
|
||||
sw:=sw and not FPU_ExceptionMask;
|
||||
{ Restoree default control word }
|
||||
cw:=Default8087CW;
|
||||
{ Reset Tag word to $ffff for all empty }
|
||||
tag:=$ffff;
|
||||
end;
|
||||
end;
|
||||
FpuState:=ucontext^.uc_mcontext.fpstate^.sw;
|
||||
if (FpuState and FPU_ExceptionMask) <> 0 then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=208
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
|
||||
res:=207
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
{ SSE data? }
|
||||
if ucontext^.uc_mcontext.fpstate^.magic<>$ffff then
|
||||
begin
|
||||
MMState:=ucontext^.uc_mcontext.fpstate^.mxcsr;
|
||||
if (MMState and MM_ExceptionMask)<>0 then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (MMState and MM_DivisionByZero)<>0 then
|
||||
res:=208
|
||||
else if (MMState and MM_Invalid)<>0 Then
|
||||
res:=207
|
||||
else if (MMState and MM_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (MMState and MM_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (MMState and MM_Denormal)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
end;
|
||||
with ucontext^.uc_mcontext.fpstate^ do
|
||||
begin
|
||||
{ Reset Status word }
|
||||
sw:=sw and not FPU_ExceptionMask;
|
||||
{ Restoree default control word }
|
||||
cw:=Default8087CW;
|
||||
{ Reset Tag word to $ffff for all empty }
|
||||
tag:=$ffff;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
SIGBUS:
|
||||
res:=214;
|
||||
@ -82,7 +113,7 @@ begin
|
||||
ucontext^.uc_mcontext.eax := res;
|
||||
ucontext^.uc_mcontext.edx := ucontext^.uc_mcontext.eip;
|
||||
ucontext^.uc_mcontext.ecx := ucontext^.uc_mcontext.ebp;
|
||||
ucontext^.uc_mcontext.eip := ptruint(@HandleErrorAddrFrame);
|
||||
ucontext^.uc_mcontext.eip := ptruint(@SignalToHandleErrorAddrFrame);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -18,15 +18,32 @@
|
||||
|
||||
type
|
||||
tfpreg = record
|
||||
significand: array[0..3] of word;
|
||||
exponent: word;
|
||||
significand: array[0..3] of word;
|
||||
exponent: word;
|
||||
end;
|
||||
|
||||
tfpxreg = record
|
||||
significand: array[0..3] of word;
|
||||
exponent: word;
|
||||
padding : array[0..2] of word;
|
||||
end;
|
||||
|
||||
txmmreg = record
|
||||
element : array[0..3] of dword;
|
||||
end;
|
||||
|
||||
|
||||
pfpstate = ^tfpstate;
|
||||
tfpstate = record
|
||||
cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
|
||||
st: array[0..7] of tfpreg;
|
||||
status: cardinal;
|
||||
cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
|
||||
st: array[0..7] of tfpreg;
|
||||
status, magic: word;
|
||||
fxsr_env : array[0..5] of dword;
|
||||
mxcsr : dword;
|
||||
reserved : dword;
|
||||
fxsr_st : array[0..7] of tfpxreg;
|
||||
xmmreg : array[0..7] of txmmreg;
|
||||
padding : array[0..55] of dword;
|
||||
end;
|
||||
|
||||
PSigContext = ^TSigContext;
|
||||
|
@ -16,6 +16,13 @@
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
{ use a trampoline which pushes the return address for proper unwinding }
|
||||
Procedure SignalToHandleErrorAddrFrame (Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
|
||||
asm
|
||||
pushq addr
|
||||
jmp HandleErrorAddrFrame
|
||||
end;
|
||||
|
||||
const
|
||||
FPU_All = $7f;
|
||||
|
||||
@ -33,10 +40,21 @@ function GetFPUState(const SigContext : TSigContext) : word;
|
||||
{$endif SYSTEM_DEBUG}
|
||||
end;
|
||||
|
||||
function GetMMState(const SigContext : TSigContext) : dword;
|
||||
begin
|
||||
if assigned(SigContext.fpstate) then
|
||||
Result:=SigContext.fpstate^.mxcsr
|
||||
else
|
||||
Result:=0;
|
||||
{$ifdef SYSTEM_DEBUG}
|
||||
Writeln(stderr,'MMState = ',result);
|
||||
{$endif SYSTEM_DEBUG}
|
||||
end;
|
||||
|
||||
|
||||
procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
|
||||
var
|
||||
res,fpustate : word;
|
||||
res,fpustate,MMState : word;
|
||||
begin
|
||||
res:=0;
|
||||
case sig of
|
||||
@ -45,24 +63,44 @@ procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigCon
|
||||
{ this is not allways necessary but I don't know yet
|
||||
how to tell if it is or not PM }
|
||||
res:=200;
|
||||
fpustate:=GetFPUState(SigContext^);
|
||||
if (FpuState and FPU_All) <> 0 then
|
||||
if SigInfo^.si_code<>FPE_INTDIV then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=200
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
|
||||
res:=207
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
fpustate:=GetFPUState(SigContext^);
|
||||
if (FpuState and FPU_All) <> 0 then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (FpuState and FPU_DivisionByZero)<>0 then
|
||||
res:=200
|
||||
else if (FpuState and FPU_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (FpuState and FPU_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (FpuState and FPU_Denormal)<>0 then
|
||||
res:=216
|
||||
else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
|
||||
res:=207
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
MMState:=getMMState(SigContext^);
|
||||
if (MMState and MM_ExceptionMask)<>0 then
|
||||
begin
|
||||
{ first check the more precise options }
|
||||
if (MMState and MM_DivisionByZero)<>0 then
|
||||
res:=208
|
||||
else if (MMState and MM_Invalid)<>0 Then
|
||||
res:=207
|
||||
else if (MMState and MM_Overflow)<>0 then
|
||||
res:=205
|
||||
else if (MMState and MM_Underflow)<>0 then
|
||||
res:=206
|
||||
else if (MMState and MM_Denormal)<>0 then
|
||||
res:=216
|
||||
else
|
||||
res:=207; {'Coprocessor Error'}
|
||||
end;
|
||||
end;
|
||||
SysResetFPU;
|
||||
SysResetFPU;
|
||||
end;
|
||||
SIGILL,
|
||||
SIGBUS,
|
||||
@ -75,7 +113,12 @@ procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigCon
|
||||
end;
|
||||
reenable_signal(sig);
|
||||
if res<>0 then
|
||||
HandleErrorAddrFrame(res,pointer(SigContext^.rip),pointer(SigContext^.rbp));
|
||||
begin
|
||||
SigContext^.rdi := res;
|
||||
SigContext^.rsi := SigContext^.rip;
|
||||
SigContext^.rdx := SigContext^.rbp;
|
||||
SigContext^.rip := ptruint(@SignalToHandleErrorAddrFrame);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -933,6 +933,14 @@ const
|
||||
FPU_StackOverflow = $40;
|
||||
FPU_ExceptionMask = $ff;
|
||||
|
||||
MM_Invalid = 1;
|
||||
MM_Denormal = 2;
|
||||
MM_DivisionByZero = 4;
|
||||
MM_Overflow = 8;
|
||||
MM_Underflow = $10;
|
||||
MM_Precicion = $20;
|
||||
MM_ExceptionMask = $3f;
|
||||
|
||||
MM_MaskInvalidOp = %0000000010000000;
|
||||
MM_MaskDenorm = %0000000100000000;
|
||||
MM_MaskDivZero = %0000001000000000;
|
||||
@ -940,7 +948,6 @@ const
|
||||
MM_MaskUnderflow = %0000100000000000;
|
||||
MM_MaskPrecision = %0001000000000000;
|
||||
|
||||
|
||||
procedure fpc_cpuinit;
|
||||
begin
|
||||
{ don't let libraries influence the FPU cw set by the host program }
|
||||
|
Loading…
Reference in New Issue
Block a user