riscv.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2008 by the Free Pascal development team.
  4. Processor dependent implementation for the system unit for
  5. RiscV which is common to all RiscV types
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {****************************************************************************
  13. fpu exception related stuff
  14. ****************************************************************************}
  15. {$ifdef FPUFD}
  16. const
  17. fpu_nx = 1 shl 0;
  18. fpu_uf = 1 shl 1;
  19. fpu_of = 1 shl 2;
  20. fpu_dz = 1 shl 3;
  21. fpu_nv = 1 shl 4;
  22. function getfflags: sizeuint; nostackframe; assembler;
  23. asm
  24. frflags a0
  25. end;
  26. procedure setfflags(flags : sizeuint); nostackframe; assembler;
  27. asm
  28. fsflags a0
  29. end;
  30. procedure RaisePendingExceptions;
  31. var
  32. fflags : sizeuint;
  33. f: TFPUException;
  34. begin
  35. fflags:=getfflags;
  36. if (fflags and fpu_dz) <> 0 then
  37. float_raise(exZeroDivide);
  38. if (fflags and fpu_of) <> 0 then
  39. float_raise(exOverflow);
  40. if (fflags and fpu_uf) <> 0 then
  41. float_raise(exUnderflow);
  42. if (fflags and fpu_nv) <> 0 then
  43. float_raise(exInvalidOp);
  44. if (fflags and fpu_nx) <> 0 then
  45. float_raise(exPrecision);
  46. { now the soft float exceptions }
  47. for f in softfloat_exception_flags do
  48. float_raise(f);
  49. end;
  50. procedure fpc_throwfpuexception;[public,alias:'FPC_THROWFPUEXCEPTION'];
  51. var
  52. fflags : sizeuint;
  53. begin
  54. fflags:=getfflags;
  55. { check, if the exception is masked }
  56. if ((fflags and fpu_dz) <> 0) and (exZeroDivide in softfloat_exception_mask) then
  57. fflags:=fflags and not(fpu_dz);
  58. if ((fflags and fpu_of) <> 0) and (exOverflow in softfloat_exception_mask) then
  59. fflags:=fflags and not(fpu_of);
  60. if ((fflags and fpu_uf) <> 0) and (exUnderflow in softfloat_exception_mask) then
  61. fflags:=fflags and not(fpu_uf);
  62. if ((fflags and fpu_nv) <> 0) and (exInvalidOp in softfloat_exception_mask) then
  63. fflags:=fflags and not(fpu_nv);
  64. if ((fflags and fpu_nx) <> 0) and (exPrecision in softfloat_exception_mask) then
  65. fflags:=fflags and not(fpu_nx);
  66. setfflags(fflags);
  67. if fflags<>0 then
  68. RaisePendingExceptions;
  69. end;
  70. {$endif FPUFD}
  71. procedure fpc_cpuinit;{$ifdef SYSTEMINLINE}inline;{$endif}
  72. begin
  73. softfloat_exception_mask:=[exPrecision,exUnderflow];
  74. end;