m68kamiga.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2015-2016 by Karoly Balogh,
  4. member of the Free Pascal development team.
  5. Amiga specific m68k functions
  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. { The Amiga hardware doesn't support the m68k CPU's atomic operations
  13. like TAS, CAS, CAS2 and so on. Therefore we must "emulate" them from
  14. software. The easiest way is the Forbid()/Permit() OS call pair around
  15. the ops themselves. It of course won't be hardware-atomic, but should
  16. be safe for multithreading. (KB) }
  17. {$DEFINE FPC_SYSTEM_HAS_INTERLOCKEDFUNCS}
  18. function InterLockedDecrement (var Target: longint) : longint;
  19. begin
  20. Forbid;
  21. Dec(Target);
  22. Result := Target;
  23. Permit;
  24. end;
  25. function InterLockedIncrement (var Target: longint) : longint;
  26. begin
  27. Forbid;
  28. Inc(Target);
  29. Result := Target;
  30. Permit;
  31. end;
  32. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  33. begin
  34. Forbid;
  35. Result := Target;
  36. Target := Source;
  37. Permit;
  38. end;
  39. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  40. begin
  41. Forbid;
  42. Result := Target;
  43. Target := Target + Source;
  44. Permit;
  45. end;
  46. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  47. begin
  48. Forbid;
  49. Result := Target;
  50. if Target = Comperand then
  51. Target := NewValue;
  52. Permit;
  53. end;
  54. { AmigaOS tells us what CPU we run on, so just use that }
  55. {$DEFINE FPC_SYSTEM_HAS_TEST68K}
  56. procedure Test68k(var CPU: byte; var FPU: byte);
  57. var
  58. flags: DWord;
  59. begin
  60. flags:=PExecBase(AOS_ExecBase)^.AttnFlags;
  61. CPU:=0;
  62. if (flags and AFF_68010) > 0 then CPU:=1;
  63. if (flags and AFF_68020) > 0 then CPU:=2;
  64. if (flags and AFF_68030) > 0 then CPU:=3;
  65. if (flags and AFF_68040) > 0 then CPU:=4;
  66. if (flags and AFF_68060) > 0 then CPU:=6;
  67. FPU:=0;
  68. if (flags and AFF_68881) > 0 then FPU:=1;
  69. if (flags and AFF_68882) > 0 then FPU:=2;
  70. if (flags and AFF_FPU40) > 0 then FPU:=CPU; // 040 or 060 with FPU
  71. end;