xtensa.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team.
  4. Processor dependent implementation for the system unit for
  5. Xtensa
  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. {$define FPC_SYSTEM_HAS_SYSRESETFPU}
  13. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  14. begin
  15. softfloat_exception_flags:=[];
  16. end;
  17. {$define FPC_SYSTEM_HAS_SYSINITFPU}
  18. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  19. begin
  20. softfloat_exception_mask:=[float_flag_underflow,float_flag_inexact,float_flag_denormal];
  21. softfloat_exception_flags:=[];
  22. end;
  23. {$ifdef fpc_abi_windowed}
  24. procedure forceSpilledRegs; assembler; public name 'forcespilledregs';
  25. asm
  26. movi a2, 0
  27. syscall
  28. end;
  29. procedure fixCodeAddress(var addr: pointer);
  30. begin
  31. // Check if valid code address
  32. if ptruint(addr) and $C0000000 >= $40000000 then
  33. begin
  34. // Replace windowed call prefix
  35. addr:=codepointer((ptruint(addr)and$00FFFFFF) or $40000000);
  36. // Rewind to call instruction address
  37. dec(addr,3);
  38. end
  39. else
  40. addr:=nil;
  41. end;
  42. {$endif fpc_abi_windowed}
  43. {$IFNDEF INTERNAL_BACKTRACE}
  44. {$define FPC_SYSTEM_HAS_GET_FRAME}
  45. function get_frame:pointer;assembler;
  46. asm
  47. {$ifdef fpc_abi_windowed}
  48. // Force registers to spill onto stack
  49. call8 forcespilledregs
  50. // now get frame pointer of caller
  51. addi a2, a1, -12
  52. l32i a2, a2, 0
  53. {$else}
  54. mov a2, a1
  55. {$endif}
  56. end;
  57. {$ENDIF not INTERNAL_BACKTRACE}
  58. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  59. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;
  60. begin
  61. {$ifdef fpc_abi_windowed}
  62. forceSpilledRegs;
  63. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  64. begin
  65. get_caller_addr:=pointer((framebp-16)^);
  66. fixCodeAddress(get_caller_addr);
  67. end
  68. else
  69. get_caller_addr:=nil;
  70. {$else}
  71. get_caller_addr:=nil;
  72. {$endif}
  73. end;
  74. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  75. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;
  76. begin
  77. {$ifdef fpc_abi_windowed}
  78. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  79. begin
  80. forceSpilledRegs;
  81. get_caller_frame:=pointer((framebp-12)^);
  82. end
  83. else
  84. get_caller_frame:=nil;
  85. {$else}
  86. get_caller_frame:=nil;
  87. {$endif}
  88. end;
  89. {$ifdef fpc_abi_windowed}
  90. {$define FPC_SYSTEM_HAS_GET_CALLER_STACKINFO}
  91. procedure get_caller_stackinfo(var framebp : pointer; var addr : codepointer);
  92. begin
  93. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  94. begin
  95. forceSpilledRegs;
  96. addr:=codepointer((framebp-16)^);
  97. framebp := pointer((framebp-12)^);
  98. fixCodeAddress(addr);
  99. end
  100. else
  101. begin
  102. addr:=nil;
  103. framebp:=nil;
  104. end;
  105. end;
  106. {$endif fpc_abi_windowed}
  107. {$define FPC_SYSTEM_HAS_SPTR}
  108. Function Sptr : pointer;assembler;
  109. asm
  110. mov a2,a1
  111. end;
  112. {$ifdef VER3_2}
  113. function InterLockedDecrement (var Target: longint) : longint;
  114. begin
  115. Result:=Target-1;
  116. Target:=Result;
  117. end;
  118. function InterLockedIncrement (var Target: longint) : longint;
  119. begin
  120. Result:=Target+1;
  121. Target:=Result;
  122. end;
  123. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  124. begin
  125. Result:=Target;
  126. Target:=Source;
  127. end;
  128. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  129. begin
  130. Result:=Target;
  131. Target:=Result+Source;
  132. end;
  133. function InterLockedDecrement (var Target: smallint) : smallint;
  134. begin
  135. Result:=Target-1;
  136. Target:=Result;
  137. end;
  138. function InterLockedIncrement (var Target: smallint) : smallint;
  139. begin
  140. Result:=Target+1;
  141. Target:=Result;
  142. end;
  143. function InterLockedExchange (var Target: smallint;Source : smallint) : smallint;
  144. begin
  145. Result:=Target;
  146. Target:=Source;
  147. end;
  148. function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : smallint;
  149. begin
  150. Result:=Target;
  151. Target:=Result+Source;
  152. end;
  153. {$endif VER3_2}
  154. {$ifdef VER3_2}
  155. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  156. {$else VER3_2}
  157. {$define FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_32}
  158. function fpc_atomic_cmp_xchg_32 (var Target: longint; NewValue : longint; Comparand: longint): longint; [public,alias:'FPC_ATOMIC_CMP_XCHG_32'];
  159. {$endif VER3_2}
  160. begin
  161. Result:=Target;
  162. if Result={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
  163. Target:=NewValue;
  164. end;
  165. {$ifdef VER3_2}
  166. function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Comperand: smallint): smallint;
  167. {$else VER3_2}
  168. {$define FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_16}
  169. function fpc_atomic_cmp_xchg_16 (var Target: smallint; NewValue : smallint; Comparand: smallint): smallint;
  170. {$endif VER3_2}
  171. begin
  172. Result:=Target;
  173. if Result={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
  174. Target:=NewValue;
  175. end;