avr.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. AVR
  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. {$asmmode gas}
  13. Procedure SysInitFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  14. begin
  15. end;
  16. procedure fpc_cpuinit;
  17. begin
  18. SysInitFPU;
  19. end;
  20. {$define FPC_SYSTEM_HAS_MOVE}
  21. procedure Move(const source;var dest;count:SizeInt);[public, alias: 'FPC_MOVE'];
  22. var
  23. aligncount : sizeint;
  24. pdest,psrc,pend : pbyte;
  25. begin
  26. if (@dest=@source) or (count<=0) then
  27. exit;
  28. if (@dest<@source) or (@source+count<@dest) then
  29. begin
  30. { Forward Move }
  31. psrc:=@source;
  32. pdest:=@dest;
  33. pend:=psrc+count;
  34. while psrc<pend do
  35. begin
  36. pdest^:=psrc^;
  37. inc(pdest);
  38. inc(psrc);
  39. end;
  40. end
  41. else
  42. begin
  43. { Backward Move }
  44. psrc:=@source+count;
  45. pdest:=@dest+count;
  46. while psrc>@source do
  47. begin
  48. dec(pdest);
  49. dec(psrc);
  50. pdest^:=psrc^;
  51. end;
  52. end;
  53. end;
  54. {$define FPC_SYSTEM_HAS_FILLCHAR}
  55. Procedure FillChar(var x;count:SizeInt;value:byte);
  56. var
  57. pdest,pend : pbyte;
  58. v : ptruint;
  59. begin
  60. if count <= 0 then
  61. exit;
  62. pdest:=@x;
  63. pend:=pdest+count;
  64. while pdest<pend do
  65. begin
  66. pdest^:=value;
  67. inc(pdest);
  68. end;
  69. end;
  70. {$IFNDEF INTERNAL_BACKTRACE}
  71. {$define FPC_SYSTEM_HAS_GET_FRAME}
  72. function get_frame:pointer;assembler;nostackframe;
  73. asm
  74. end;
  75. {$ENDIF not INTERNAL_BACKTRACE}
  76. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  77. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;assembler;
  78. asm
  79. end;
  80. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  81. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;assembler;
  82. asm
  83. end;
  84. {$define FPC_SYSTEM_HAS_SPTR}
  85. Function Sptr : pointer;assembler;
  86. asm
  87. end;
  88. function InterLockedDecrement (var Target: longint) : longint;
  89. var
  90. temp_sreg : byte;
  91. begin
  92. { block interrupts }
  93. asm
  94. in r0,0x3f
  95. std temp_sreg,r0
  96. cli
  97. end;
  98. dec(Target);
  99. Result:=Target;
  100. { release interrupts }
  101. asm
  102. ldd r0,temp_sreg
  103. out 0x3f,r0
  104. end;
  105. end;
  106. function InterLockedIncrement (var Target: longint) : longint;
  107. var
  108. temp_sreg : byte;
  109. begin
  110. { block interrupts }
  111. asm
  112. in r0,0x3f
  113. std temp_sreg,r0
  114. cli
  115. end;
  116. inc(Target);
  117. Result:=Target;
  118. { release interrupts }
  119. asm
  120. ldd r0,temp_sreg
  121. out 0x3f,r0
  122. end;
  123. end;
  124. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  125. var
  126. temp_sreg : byte;
  127. begin
  128. { block interrupts }
  129. asm
  130. in r0,0x3f
  131. std temp_sreg,r0
  132. cli
  133. end;
  134. Result:=Target;
  135. Target:=Source;
  136. { release interrupts }
  137. asm
  138. ldd r0,temp_sreg
  139. out 0x3f,r0
  140. end;
  141. end;
  142. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  143. var
  144. temp_sreg : byte;
  145. begin
  146. { block interrupts }
  147. asm
  148. in r0,0x3f
  149. std temp_sreg,r0
  150. cli
  151. end;
  152. Result:=Target;
  153. if Target=Comperand then
  154. Target:=NewValue;
  155. { release interrupts }
  156. asm
  157. ldd r0,temp_sreg
  158. out 0x3f,r0
  159. end;
  160. end;
  161. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  162. var
  163. temp_sreg : byte;
  164. begin
  165. { block interrupts }
  166. asm
  167. in r0,0x3f
  168. std temp_sreg,r0
  169. cli
  170. end;
  171. Result:=Target;
  172. inc(Target,Source);
  173. { release interrupts }
  174. asm
  175. ldd r0,temp_sreg
  176. out 0x3f,r0
  177. end;
  178. end;