sighnd.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. asm
  42. fmove.l fpucw,fpcr
  43. fmove.l fpust,fpsr
  44. end;
  45. end;
  46. function GetFPUState(const SigContext : TSigContext) : longint;
  47. begin
  48. GetfpuState:=SigContext.psr;
  49. {$ifdef SYSTEM_DEBUG}
  50. Writeln(stderr,'FpuState = ',GetFpuState);
  51. {$endif SYSTEM_DEBUG}
  52. end;
  53. procedure SignalToRunerror(Sig: longint; Info : pointer; var SigContext: TSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  54. var
  55. res,fpustate : word;
  56. begin
  57. res:=0;
  58. case sig of
  59. SIGFPE :
  60. begin
  61. { this is not allways necessary but I don't know yet
  62. how to tell if it is or not PM }
  63. res:=200;
  64. fpustate:=GetFPUState(SigContext);
  65. if (FpuState and FPU_All) <> 0 then
  66. begin
  67. { first check the more precise options }
  68. if (FpuState and FPU_DivisionByZero)<>0 then
  69. res:=200
  70. else if (FpuState and FPU_Overflow)<>0 then
  71. res:=205
  72. else if (FpuState and FPU_Underflow)<>0 then
  73. res:=206
  74. else if (FpuState and FPU_Denormal)<>0 then
  75. res:=216
  76. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  77. res:=207
  78. else if (FpuState and FPU_Invalid)<>0 then
  79. res:=216
  80. else
  81. res:=207; {'Coprocessor Error'}
  82. end;
  83. ResetFPU;
  84. end;
  85. SIGILL,
  86. SIGBUS,
  87. SIGSEGV :
  88. res:=216;
  89. SIGINT:
  90. res:=217;
  91. SIGQUIT:
  92. res:=233;
  93. end;
  94. reenable_signal(sig);
  95. { give runtime error at the position where the signal was raised }
  96. if res<>0 then
  97. begin
  98. { HandleErrorAddrFrame(res,SigContext.sc_pc,SigContext.sc_fp);}
  99. { fp is not saved in context record :( }
  100. HandleError(res);
  101. HandleError(res);
  102. end;
  103. end;