xtensa.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. end;
  16. {$define FPC_SYSTEM_HAS_SYSINITFPU}
  17. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  18. begin
  19. end;
  20. procedure fpc_cpuinit;
  21. begin
  22. { don't let libraries influence the FPU cw set by the host program }
  23. if not IsLibrary then
  24. SysInitFPU;
  25. end;
  26. {$ifdef fpc_abi_windowed}
  27. procedure forceSpilledRegs; assembler; public name 'forcespilledregs';
  28. asm
  29. movi a2, 0
  30. syscall
  31. end;
  32. procedure fixCodeAddress(var addr: pointer);
  33. begin
  34. // Check if valid code address
  35. if ptruint(addr) and $C0000000 >= $40000000 then
  36. begin
  37. // Replace windowed call prefix
  38. addr:=codepointer((ptruint(addr)and$00FFFFFF) or $40000000);
  39. // Rewind to call instruction address
  40. dec(addr,3);
  41. end
  42. else
  43. addr:=nil;
  44. end;
  45. {$endif fpc_abi_windowed}
  46. {$IFNDEF INTERNAL_BACKTRACE}
  47. {$define FPC_SYSTEM_HAS_GET_FRAME}
  48. function get_frame:pointer;assembler;
  49. asm
  50. {$ifdef fpc_abi_windowed}
  51. // Force registers to spill onto stack
  52. call8 forcespilledregs
  53. // now get frame pointer of caller
  54. addi a2, a1, -12
  55. l32i a2, a2, 0
  56. {$else}
  57. mov a2, a1
  58. {$endif}
  59. end;
  60. {$ENDIF not INTERNAL_BACKTRACE}
  61. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  62. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;
  63. begin
  64. {$ifdef fpc_abi_windowed}
  65. forceSpilledRegs;
  66. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  67. begin
  68. get_caller_addr:=pointer((framebp-16)^);
  69. fixCodeAddress(get_caller_addr);
  70. end
  71. else
  72. get_caller_addr:=nil;
  73. {$else}
  74. get_caller_addr:=nil;
  75. {$endif}
  76. end;
  77. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  78. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;
  79. begin
  80. {$ifdef fpc_abi_windowed}
  81. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  82. begin
  83. forceSpilledRegs;
  84. get_caller_frame:=pointer((framebp-12)^);
  85. end
  86. else
  87. get_caller_frame:=nil;
  88. {$else}
  89. get_caller_frame:=nil;
  90. {$endif}
  91. end;
  92. {$ifdef fpc_abi_windowed}
  93. {$define FPC_SYSTEM_HAS_GET_CALLER_STACKINFO}
  94. procedure get_caller_stackinfo(var framebp : pointer; var addr : codepointer);
  95. begin
  96. if (ptruint(framebp)>$3ff00000)and(ptruint(framebp)<$40000000) then
  97. begin
  98. forceSpilledRegs;
  99. addr:=codepointer((framebp-16)^);
  100. framebp := pointer((framebp-12)^);
  101. fixCodeAddress(addr);
  102. end
  103. else
  104. begin
  105. addr:=nil;
  106. framebp:=nil;
  107. end;
  108. end;
  109. {$endif fpc_abi_windowed}
  110. {$define FPC_SYSTEM_HAS_SPTR}
  111. Function Sptr : pointer;assembler;
  112. asm
  113. mov a2,a1
  114. end;
  115. function InterLockedDecrement (var Target: longint) : longint;
  116. var
  117. temp_sreg : byte;
  118. begin
  119. Result:=Target-1;
  120. Target:=Result;
  121. end;
  122. function InterLockedIncrement (var Target: longint) : longint;
  123. var
  124. temp_sreg : byte;
  125. begin
  126. Result:=Target+1;
  127. Target:=Result;
  128. end;
  129. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  130. var
  131. temp_sreg : byte;
  132. begin
  133. Result:=Target;
  134. Target:=Source;
  135. end;
  136. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  137. var
  138. temp_sreg : byte;
  139. begin
  140. Result:=Target;
  141. if Result=Comperand then
  142. Target:=NewValue;
  143. end;
  144. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  145. var
  146. temp_sreg : byte;
  147. begin
  148. Result:=Target;
  149. Target:=Result+Source;
  150. end;
  151. function InterLockedDecrement (var Target: smallint) : smallint;
  152. var
  153. temp_sreg : byte;
  154. begin
  155. Result:=Target-1;
  156. Target:=Result;
  157. end;
  158. function InterLockedIncrement (var Target: smallint) : smallint;
  159. var
  160. temp_sreg : byte;
  161. begin
  162. Result:=Target+1;
  163. Target:=Result;
  164. end;
  165. function InterLockedExchange (var Target: smallint;Source : smallint) : smallint;
  166. var
  167. temp_sreg : byte;
  168. begin
  169. Result:=Target;
  170. Target:=Source;
  171. end;
  172. function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Comperand: smallint): smallint;
  173. var
  174. temp_sreg : byte;
  175. begin
  176. Result:=Target;
  177. if Result=Comperand then
  178. Target:=NewValue;
  179. end;
  180. function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : smallint;
  181. var
  182. temp_sreg : byte;
  183. begin
  184. Result:=Target;
  185. Target:=Result+Source;
  186. end;