m68k.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Carl-Eric Codere,
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************
  12. m68k.inc : Processor dependent implementation of system unit
  13. For Motorola 680x0 Processor.
  14. *****************************************************************************}
  15. {****************************************************************************}
  16. { Credit where credit is due: }
  17. { -Some of the copy routines taken from the Atari dlib source code: }
  18. { Dale Schumacher (alias: Dalnefre') [email protected] }
  19. { 399 Beacon Ave. St. Paul, MN 55104,USA }
  20. { -Some of the routines taken from the freeware ATARI Sozobon C compiler }
  21. { 1988 by Sozobon, Limited. Author: Johann Ruegg (freeware) }
  22. { Thanks to all these people wherever they maybe today! }
  23. {****************************************************************************}
  24. procedure fpc_cpuinit;
  25. begin
  26. end;
  27. {$define FPC_SYSTEM_HAS_GET_FRAME}
  28. function get_frame : pointer; assembler;
  29. asm
  30. move.l a6,d0
  31. end;
  32. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  33. function get_caller_addr(framebp : pointer;addr:pointer=nil) : pointer;
  34. begin
  35. asm
  36. move.l framebp,a0
  37. cmp.l #0,a0
  38. beq @Lnul_address
  39. move.l 4(a0),a0
  40. @Lnul_address:
  41. move.l a0,@RESULT
  42. end ['a0'];
  43. end;
  44. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  45. function get_caller_frame(framebp : pointer;addr:pointer=nil) : pointer;
  46. begin
  47. asm
  48. move.l FRAMEBP,a0
  49. cmp.l #0,a0
  50. beq @Lnul_frame
  51. move.l (a0),a0
  52. @Lnul_frame:
  53. move.l a0,@RESULT
  54. end ['a0'];
  55. end;
  56. {$define FPC_SYSTEM_HAS_SPTR}
  57. function Sptr : pointer; assembler;
  58. asm
  59. move.l sp,d0
  60. end ['d0'];
  61. {$define FPC_SYSTEM_HAS_FILLCHAR}
  62. procedure FillChar(var x;count:longint;value:byte); assembler;
  63. asm
  64. move.l 8(a6), a0 { destination }
  65. move.l 12(a6), d1 { number of bytes to fill }
  66. move.b 16(a6),d0 { fill data }
  67. cmpi.l #65535, d1 { check, if this is a word move }
  68. ble @LMEMSET3 { use fast dbra mode }
  69. bra @LMEMSET2
  70. @LMEMSET1:
  71. move.b d0,(a0)+
  72. @LMEMSET2:
  73. subq.l #1,d1
  74. cmp.l #-1,d1
  75. bne @LMEMSET1
  76. bra @LMEMSET5 { finished slow mode , exit }
  77. @LMEMSET4: { fast loop mode section 68010+ }
  78. move.b d0,(a0)+
  79. @LMEMSET3:
  80. {$ifdef CPUCOLDFIRE}
  81. sub.l #1,d1
  82. bmi @LMEMSET4
  83. {$else}
  84. dbra d1,@LMEMSET4
  85. {$endif}
  86. @LMEMSET5:
  87. end ['d0','d1','a0'];
  88. {$ifdef dummy}
  89. { procedure strcopy(dstr,sstr : pointer;len : longint);[public,alias: 'STRCOPY'];}
  90. procedure strcopy; assembler;[public,alias: 'FPC_STRCOPY'];
  91. {---------------------------------------------------}
  92. { Low-level routine to copy a string to another }
  93. { string with maximum length. Never call directly! }
  94. { On Entry: }
  95. { a1.l = string to copy to }
  96. { a0.l = source string }
  97. { d0.l = maximum length of copy }
  98. { registers destroyed: a0,a1,d0,d1 }
  99. {---------------------------------------------------}
  100. asm
  101. { move.l 12(a6),a0
  102. move.l 16(a6),a1
  103. move.l 8(a6),d1 }
  104. move.l d0,d1
  105. move.b (a0)+,d0 { Get source length }
  106. and.w #$ff,d0
  107. cmp.w d1,d0 { This is a signed comparison! }
  108. ble @LM4
  109. move.b d1,d0 { If longer than maximum size of target, cut
  110. source length }
  111. @LM4:
  112. andi.l #$ff,d0 { zero extend d0-byte }
  113. move.l d0,d1 { save length to copy }
  114. move.b d0,(a1)+ { save new length }
  115. { Check if copying length is zero - if so then }
  116. { exit without copying anything. }
  117. tst.b d1
  118. beq @Lend
  119. bra @LMSTRCOPY55
  120. @LMSTRCOPY56: { 68010 Fast loop mode }
  121. move.b (a0)+,(a1)+
  122. @LMSTRCOPY55:
  123. {$ifdef CPUCOLDFIRE}
  124. sub.l #1,d1
  125. bmi @LMSTRCOPY56
  126. {$else}
  127. dbra d1,@LMSTRCOPY56
  128. {$endif}
  129. @Lend:
  130. end;
  131. { Concatenate Strings }
  132. { PARAMETERS ARE REVERSED COMPARED TO NORMAL! }
  133. { therefore online assembler may not parse the params as normal }
  134. procedure strconcat(s1,s2 : pointer);[public,alias: 'STRCONCAT'];
  135. begin
  136. asm
  137. move.b #255,d0
  138. move.l s1,a0 { a0 = destination }
  139. move.l s2,a1 { a1 = source }
  140. sub.b (a0),d0 { copyl:= 255 -length(s1) }
  141. move.b (a1),d6
  142. and.w #$ff,d0 { Sign flags are checked! }
  143. and.w #$ff,d6
  144. cmp.w d6,d0 { if copyl > length(s2) then }
  145. ble @Lcontinue
  146. move.b (a1),d0 { copyl:=length(s2) }
  147. @Lcontinue:
  148. move.b (a0),d6
  149. and.l #$ff,d6
  150. lea 1(a0,d6),a0 { s1[length(s1)+1] }
  151. add.l #1,a1 { s2[1] }
  152. move.b d0,d6
  153. { Check if copying length is zero - if so then }
  154. { exit without copying anything. }
  155. tst.b d6
  156. beq @Lend
  157. bra @ALoop
  158. @Loop:
  159. move.b (a1)+,(a0)+ { s1[i] := s2[i]; }
  160. @ALoop:
  161. {$ifdef CPUCOLDFIRE}
  162. sub.l #1,d6
  163. bmi @Loop
  164. {$else}
  165. dbra d6,@Loop
  166. {$endif}
  167. move.l s1,a0
  168. add.b d0,(a0) { change to new string length }
  169. @Lend:
  170. end ['d0','d1','a0','a1','d6'];
  171. end;
  172. { Compares strings }
  173. { DO NOT CALL directly. }
  174. { a0 = pointer to first string to compare }
  175. { a1 = pointer to second string to compare }
  176. { ALL FLAGS are set appropriately. }
  177. { ZF = strings are equal }
  178. { REGISTERS DESTROYED: a0, a1, d0, d1, d6 }
  179. procedure strcmp; assembler;[public,alias:'FPC_STRCMP'];
  180. asm
  181. move.b (a0)+,d0 { Get length of first string }
  182. move.b (a1)+,d6 { Get length of 2nd string }
  183. move.b d6,d1 { Save length of string for final compare }
  184. cmp.b d0,d6 { Get shortest string length }
  185. ble @LSTRCONCAT1
  186. move.b d0,d6 { Set length to shortest string }
  187. @LSTRCONCAT1:
  188. tst.b d6 { Both strings have a length of zero, exit }
  189. beq @LSTRCONCAT2
  190. andi.l #$ff,d6
  191. subq.l #1,d6 { subtract first attempt }
  192. { if value is -1 then don't loop and just compare lengths of }
  193. { both strings before exiting. }
  194. bmi @LSTRCONCAT2
  195. or.l d0,d0 { Make sure to set Zerfo flag to 0 }
  196. @LSTRCONCAT5:
  197. { Workaroung for GAS v.134 bug }
  198. { old: cmp.b (a1)+,(a0)+ }
  199. cmpm.b (a1)+,(a0)+
  200. @LSTRCONCAT4:
  201. dbne d6,@LSTRCONCAT5 { Repeat until not equal }
  202. bne @LSTRCONCAT3
  203. @LSTRCONCAT2:
  204. { If length of both string are equal }
  205. { Then set zero flag }
  206. cmp.b d1,d0 { Compare length - set flag if equal length strings }
  207. @LSTRCONCAT3:
  208. end;
  209. {$endif dummy}
  210. {$define FPC_SYSTEM_HAS_MOVE}
  211. procedure move(const source;var dest;count : longint);
  212. { base pointer+8 = source }
  213. { base pointer+12 = destination }
  214. { base pointer+16 = number of bytes to move}
  215. begin
  216. asm
  217. clr.l d0
  218. move.l 16(a6),d0 { number of bytes }
  219. tst.l d0 { anything to copy at all? }
  220. beq @LMOVE5
  221. @LMOVE0:
  222. move.l 12(a6),a1 { destination }
  223. move.l 8(a6),a0 { source }
  224. cmpi.l #65535, d0 { check, if this is a word move }
  225. ble @LMEMSET00 { use fast dbra mode 68010+ }
  226. cmp.l a0,a1 { check copy direction }
  227. bls @LMOVE4
  228. add.l d0,a0 { move pointers to end }
  229. add.l d0,a1
  230. bra @LMOVE2
  231. @LMOVE1:
  232. move.b -(a0),-(a1) { (s < d) copy loop }
  233. @LMOVE2:
  234. subq.l #1,d0
  235. cmpi.l #-1,d0
  236. bne @LMOVE1
  237. bra @LMOVE5
  238. @LMOVE3:
  239. move.b (a0)+,(a1)+ { (s >= d) copy loop }
  240. @LMOVE4:
  241. subq.l #1,d0
  242. cmpi.l #-1,d0
  243. bne @LMOVE3
  244. bra @LMOVE5
  245. @LMEMSET00: { use fast loop mode 68010+ }
  246. cmp.l a0,a1 { check copy direction }
  247. bls @LMOVE04
  248. add.l d0,a0 { move pointers to end }
  249. add.l d0,a1
  250. bra @LMOVE02
  251. @LMOVE01:
  252. move.b -(a0),-(a1) { (s < d) copy loop }
  253. @LMOVE02:
  254. {$ifdef CPUCOLDFIRE}
  255. sub.l #1,d0
  256. bmi @LMOVE01
  257. {$else}
  258. dbra d0,@LMOVE01
  259. {$endif}
  260. bra @LMOVE5
  261. @LMOVE03:
  262. move.b (a0)+,(a1)+ { (s >= d) copy loop }
  263. @LMOVE04:
  264. {$ifdef CPUCOLDFIRE}
  265. sub.l #1,d0
  266. bmi @LMOVE03
  267. {$else}
  268. dbra d0,@LMOVE03
  269. {$endif}
  270. { end fast loop mode }
  271. @LMOVE5:
  272. end ['d0','a0','a1'];
  273. end;
  274. {$define FPC_SYSTEM_HAS_FILLWORD}
  275. procedure fillword(var x;count : longint;value : word);
  276. begin
  277. asm
  278. move.l 8(a6), a0 { destination }
  279. move.l 12(a6), d1 { number of bytes to fill }
  280. move.w 16(a6),d0 { fill data }
  281. bra @LMEMSET21
  282. @LMEMSET11:
  283. move.w d0,(a0)+
  284. @LMEMSET21:
  285. subq.l #1,d1
  286. cmp.b #-1,d1
  287. bne @LMEMSET11
  288. end ['d0','d1','a0'];
  289. end;
  290. {$define FPC_SYSTEM_HAS_ABS_LONGINT}
  291. function abs(l : longint) : longint;
  292. begin
  293. asm
  294. move.l 8(a6),d0
  295. tst.l d0
  296. bpl @LMABS1
  297. neg.l d0
  298. @LMABS1:
  299. move.l d0,@RESULT
  300. end ['d0'];
  301. end;
  302. function InterLockedDecrement (var Target: longint) : longint;
  303. begin
  304. {$warning FIX ME}
  305. end;
  306. function InterLockedIncrement (var Target: longint) : longint;
  307. begin
  308. {$warning FIX ME}
  309. end;
  310. function InterLockedExchange (var Target: longint;Source : longint) : longint;
  311. begin
  312. {$warning FIX ME}
  313. end;
  314. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
  315. begin
  316. {$warning FIX ME}
  317. end;
  318. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
  319. begin
  320. {$warning FIX ME}
  321. end;