avr.inc 3.8 KB

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