m68k.inc 10.0 KB

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