sighnd.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. Signal handler is arch dependant due to processor to language
  6. exception conversion.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. const
  14. { Bits in control register }
  15. RoundingMode = $30;
  16. RoundingPrecision = $c0;
  17. InexactDecimal = $100;
  18. InexactOperation = $200;
  19. DivideByZero = $400;
  20. UnderFlow = $800;
  21. OverFlow = $1000;
  22. OperandError = $2000;
  23. SignalingNaN = $4000;
  24. BranchOnUnordered = $800;
  25. fpucw : longint = {InexactOperation or }DivideByZero or
  26. OverFlow or OperandError or
  27. SignalingNaN or BranchOnUnordered;
  28. fpust : longint = 0;
  29. { Bits in status register }
  30. FPU_Invalid = $80;
  31. FPU_Denormal = $8;
  32. FPU_DivisionByZero = $10;
  33. FPU_Overflow = $40;
  34. FPU_Underflow = $20;
  35. { m68k is not stack based }
  36. FPU_StackUnderflow = $0;
  37. FPU_StackOverflow = $0;
  38. FPU_All = $f8;
  39. Procedure ResetFPU;
  40. begin
  41. {$ifdef CPU68020}
  42. asm
  43. fmove.l fpucw,fpcr
  44. fmove.l fpust,fpsr
  45. end;
  46. {$endif}
  47. end;
  48. function GetFPUState(const SigContext : TSigContext) : longint;
  49. begin
  50. GetfpuState:=SigContext.psr;
  51. {$ifdef SYSTEM_DEBUG}
  52. Writeln(stderr,'FpuState = ',GetFpuState);
  53. {$endif SYSTEM_DEBUG}
  54. end;
  55. procedure SignalToRunerror(Sig: longint; Info : pointer; var SigContext: TSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  56. var
  57. res,fpustate : word;
  58. begin
  59. res:=0;
  60. case sig of
  61. SIGFPE :
  62. begin
  63. { this is not allways necessary but I don't know yet
  64. how to tell if it is or not PM }
  65. res:=200;
  66. fpustate:=GetFPUState(SigContext);
  67. if (FpuState and FPU_All) <> 0 then
  68. begin
  69. { first check the more precise options }
  70. if (FpuState and FPU_DivisionByZero)<>0 then
  71. res:=200
  72. else if (FpuState and FPU_Overflow)<>0 then
  73. res:=205
  74. else if (FpuState and FPU_Underflow)<>0 then
  75. res:=206
  76. else if (FpuState and FPU_Denormal)<>0 then
  77. res:=216
  78. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  79. res:=207
  80. else if (FpuState and FPU_Invalid)<>0 then
  81. res:=216
  82. else
  83. res:=207; {'Coprocessor Error'}
  84. end;
  85. ResetFPU;
  86. end;
  87. SIGILL,
  88. SIGBUS,
  89. SIGSEGV :
  90. res:=216;
  91. SIGINT:
  92. res:=217;
  93. SIGQUIT:
  94. res:=233;
  95. end;
  96. reenable_signal(sig);
  97. { give runtime error at the position where the signal was raised }
  98. if res<>0 then
  99. begin
  100. { HandleErrorAddrFrame(res,SigContext.sc_pc,SigContext.sc_fp);}
  101. { fp is not saved in context record :( }
  102. HandleError(res);
  103. HandleError(res);
  104. end;
  105. end;