xtensa.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. function InterLockedDecrement (var Target: longint) : longint;
  113. var
  114. temp_sreg : byte;
  115. begin
  116. Result:=Target-1;
  117. Target:=Result;
  118. end;
  119. function InterLockedIncrement (var Target: longint) : longint;
  120. var
  121. temp_sreg : byte;
  122. begin
  123. Result:=Target+1;
  124. Target:=Result;
  125. end;
  126. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  127. var
  128. temp_sreg : byte;
  129. begin
  130. Result:=Target;
  131. Target:=Source;
  132. end;
  133. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  134. var
  135. temp_sreg : byte;
  136. begin
  137. Result:=Target;
  138. if Result=Comperand then
  139. Target:=NewValue;
  140. end;
  141. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  142. var
  143. temp_sreg : byte;
  144. begin
  145. Result:=Target;
  146. Target:=Result+Source;
  147. end;
  148. function InterLockedDecrement (var Target: smallint) : smallint;
  149. var
  150. temp_sreg : byte;
  151. begin
  152. Result:=Target-1;
  153. Target:=Result;
  154. end;
  155. function InterLockedIncrement (var Target: smallint) : smallint;
  156. var
  157. temp_sreg : byte;
  158. begin
  159. Result:=Target+1;
  160. Target:=Result;
  161. end;
  162. function InterLockedExchange (var Target: smallint;Source : smallint) : smallint;
  163. var
  164. temp_sreg : byte;
  165. begin
  166. Result:=Target;
  167. Target:=Source;
  168. end;
  169. function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Comperand: smallint): smallint;
  170. var
  171. temp_sreg : byte;
  172. begin
  173. Result:=Target;
  174. if Result=Comperand then
  175. Target:=NewValue;
  176. end;
  177. function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : smallint;
  178. var
  179. temp_sreg : byte;
  180. begin
  181. Result:=Target;
  182. Target:=Result+Source;
  183. end;