m68k.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 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. { This include file contains as little assembler as possible, to make }
  18. { porting to other systems easier. }
  19. { Port to the Motorola 680x0 compiler by: }
  20. { }
  21. { Carl-Eric Codere - port of non-system specific stuff. }
  22. { }
  23. { Some routines taken from the Atari freeware dlib source code, created by: }
  24. { Dale Schumacher 399 Beacon Ave. }
  25. { (alias: Dalnefre') St. Paul, MN 55104 }
  26. { [email protected] United States of America }
  27. { Some routines taken from the freeware Atari Sozobon C compiler, created by:}
  28. { 1988 by Sozobon, Limited. Author: Johann Ruegg (freeware) }
  29. { Thanks to all these people wherever they maybe today! }
  30. { BUGS in sqr and abs for return values. Only longint seems supported. }
  31. { }
  32. { Still left to do: }
  33. { mod_rr routine to convert to pascal format. }
  34. { }
  35. { ALL routines in set.inc, system.inc and real2str.inc are system independant.}
  36. {****************************************************************************}
  37. { Don't call the following routines directly. }
  38. Procedure Hlt;[public,alias: 'HALT_ERROR'];
  39. { called by code generator on run-time errors. }
  40. { on entry contains d0 = error code. }
  41. var
  42. b:byte; { only byte is used... }
  43. begin
  44. asm
  45. move.b d0,b
  46. end;
  47. HandleError(b);
  48. end;
  49. Procedure FillChar(var x; count: longint; value: byte);
  50. begin
  51. asm
  52. move.l 8(a6), a0 { destination }
  53. move.l 12(a6), d1 { number of bytes to fill }
  54. move.b 16(a6),d0 { fill data }
  55. cmpi.l #65535, d1 { check, if this is a word move }
  56. ble @LMEMSET3 { use fast dbra mode }
  57. bra @LMEMSET2
  58. @LMEMSET1:
  59. move.b d0,(a0)+
  60. @LMEMSET2:
  61. subq.l #1,d1
  62. cmp.b #-1,d1
  63. bne @LMEMSET1
  64. bra @LMEMSET5 { finished slow mode , exit }
  65. @LMEMSET4: { fast loop mode section 68010+ }
  66. move.b d0,(a0)+
  67. @LMEMSET3:
  68. dbra d1,@LMEMSET4
  69. @LMEMSET5:
  70. end ['d0','d1','a0'];
  71. end;
  72. Procedure FillObject(var x; count: longint; value: byte);
  73. begin
  74. asm
  75. move.l 8(a6), a0 { destination }
  76. move.l 12(a6), d1 { number of bytes to fill }
  77. move.w 16(a6),d0 { fill data }
  78. cmp.l #65535, d1 { check, if this is a word move }
  79. ble @LMEMSET3 { use fast dbra mode }
  80. bra @LMEMSET2
  81. @LMEMSET1:
  82. move.b d0,(a0)+
  83. @LMEMSET2:
  84. subq.l #1,d1
  85. cmp.b #-1,d1
  86. bne @LMEMSET1
  87. bra @LMEMSET5 { finished slow mode , exit }
  88. @LMEMSET4: { fast loop mode section 68010+ }
  89. move.b d0,(a0)+
  90. @LMEMSET3:
  91. dbra d1,@LMEMSET4
  92. @LMEMSET5:
  93. end ['d0','d1','a0'];
  94. end;
  95. procedure int_help_constructor;
  96. begin
  97. asm
  98. XDEF HELP_CONSTRUCTOR
  99. { Entry without preamble, since we need the ESP of the
  100. constructor }
  101. { Stack (relative to %ebp):
  102. 12 Self
  103. 8 VMT-Address
  104. 4 main programm-Addr
  105. 0 %ebp
  106. }
  107. { do we have to initialize self }
  108. { we just need to check for zero }
  109. move.l a5,d0
  110. tst.l d0 { set flags }
  111. bne @LHC_4
  112. { get memory, but save register first }
  113. { temporary variable }
  114. subq.l #4,sp
  115. move.l sp,a5
  116. { Save Registers }
  117. movem.l d0-a7,-(sp)
  118. { Memory size }
  119. move.l 8(a6),a0
  120. move.l (a0),-(sp)
  121. { push method pointer }
  122. move.l a5,-(sp)
  123. jsr GETMEM
  124. { Restore all registers in the correct order }
  125. movem.l (sp)+,d0-a7
  126. { Memory size to a5 }
  127. move.l (a5),a5
  128. add.l #4,sp
  129. { If no memory available : fail() }
  130. move.l a5,d0
  131. tst.l d0 { set flags for a5 }
  132. beq @LHC_5
  133. { init self for the constructor }
  134. move.l a5,12(a6)
  135. @LHC_4:
  136. { is there a VMT address ? }
  137. move.l 8(a6),d0
  138. or.l d0,d0
  139. bne @LHC_7
  140. { In case the constructor doesn't do anything, the Zero-Flag }
  141. { can't be put, because this calls Fail() }
  142. add.l #1,d0
  143. rts
  144. @LHC_7:
  145. { set zero inside the object }
  146. { Save Registers }
  147. movem.l d0-a7,-(sp)
  148. move.w #0,-(sp)
  149. move.l 8(a6),a0
  150. move.l (a0),-(sp)
  151. move.l a5,-(sp)
  152. { }
  153. jsr FILLOBJECT
  154. { Restore all registers in the correct order }
  155. movem.l (sp)+,d0-a7
  156. { set the VMT address for the new created object }
  157. move.l 8(a6),d0
  158. move.l d0,(a5)
  159. or.l d0,d0
  160. @LHC_5:
  161. rts
  162. end;
  163. end;
  164. procedure help_fail;
  165. begin
  166. asm
  167. end;
  168. end;
  169. procedure int_help_destructor;
  170. begin
  171. asm
  172. { Stack (relative to %ebp):
  173. 12 Self
  174. 8 VMT-Address
  175. 4 Main program-Addr
  176. 0 %ebp
  177. }
  178. { temporary Variable }
  179. XDEF HELP_DESTRUCTOR
  180. subq.l #4,sp
  181. move.l sp,d6
  182. { Save Registers }
  183. movem.l d0-a7,-(sp)
  184. move.l 8(a6),d0 { Get the address of the vmt }
  185. or.l d0,d0 { Check if there is a vmt }
  186. beq @LHD_3
  187. { Yes, get size from SELF! }
  188. move.l 12(a6),a0
  189. { get VMT-pointer (from Self) to %ebx }
  190. move.l (a0),a1
  191. { And put size on the Stack }
  192. move.l (a1),-(sp)
  193. { SELF }
  194. { I think for precaution }
  195. { that we should clear the VMT here }
  196. clr.l (a0)
  197. { get address of local variable into }
  198. { address register }
  199. move.l d6,a1
  200. move.l a0,(a1)
  201. move.l a1,-(sp)
  202. jsr FREEMEM
  203. @LHD_3:
  204. { Restore all registers in the correct order }
  205. movem.l (sp)+,d0-a7
  206. add.l #4,sp
  207. rts
  208. end;
  209. end;
  210. procedure new_class;assembler;
  211. asm
  212. XDEF NEW_CLASS
  213. { create class ? }
  214. move.l 8(a6), d0
  215. tst.l d0
  216. { check for nil... }
  217. beq @NEW_CLASS1
  218. { a5 contains vmt }
  219. move.l a5,-(sp)
  220. { call newinstance (class method!) }
  221. jsr 16(a5)
  222. { new instance returns a pointer to the new created }
  223. { instance in d0 }
  224. { load a5 and insert self }
  225. move.l d0,8(a6)
  226. move.l d0,a5
  227. bra @end
  228. @NEW_CLASS1:
  229. move.l a5,8(a6)
  230. @end:
  231. end;
  232. procedure dispose_class;assembler;
  233. asm
  234. XDEF DISPOSE_CLASS
  235. { destroy class ? }
  236. move.l 8(a6),d0
  237. { save self }
  238. move.l a5,8(a6)
  239. tst.l d0
  240. beq @DISPOSE_CLASS
  241. { no inherited call }
  242. move.l (a5),d0
  243. { push self }
  244. move.l a5,-(sp)
  245. { call freeinstance }
  246. move.l d0,a0
  247. jsr 20(a0)
  248. @DISPOSE_CLASS:
  249. { load self }
  250. move.l 8(a6),a5
  251. end;
  252. { checks for a correct vmt pointer }
  253. procedure co;assembler;
  254. { ON ENTRY: a0 -> Pointer to the VMT }
  255. { Nota: All registers must be preserved including }
  256. { A0 itself! }
  257. asm
  258. XDEF CHECK_OBJECT
  259. move.l d0,-(sp)
  260. tst.l a0
  261. { z flag set if zero }
  262. beq @co_re
  263. move.l (a0),d0
  264. add.l 4(a0),d0
  265. bne @co_re
  266. bra @end
  267. @co_re:
  268. move.l (sp)+,d0
  269. move.b #210,d0
  270. jsr HALT_ERROR
  271. @end:
  272. move.l (sp)+,d0
  273. end;
  274. function get_addr(BP : longint) : longint;
  275. begin
  276. asm
  277. move.l BP,a0
  278. cmp.l #0,a0
  279. beq @Lnul_address
  280. move.l 4(a0),a0
  281. @Lnul_address:
  282. move.l a0,@RESULT
  283. end ['a0'];
  284. end;
  285. function get_next_frame(bp : longint) : longint;
  286. begin
  287. asm
  288. move.l bp,a0
  289. cmp.l #0,a0
  290. beq @Lnul_frame
  291. move.l (a0),a0
  292. @Lnul_frame:
  293. move.l a0,@RESULT
  294. end ['a0'];
  295. end;
  296. Procedure HandleError (Errno : longint);[alias : 'handleerror'];
  297. {
  298. Procedure to handle internal errors, i.e. not user-invoked errors
  299. Internal function should ALWAYS call HandleError instead of RunError.
  300. }
  301. function get_addr : pointer;
  302. begin
  303. asm
  304. move.l (a6),a0
  305. move.l 4(a0),a0
  306. move.l a0,@RESULT
  307. end ['a0'];
  308. end;
  309. function get_error_bp : longint;
  310. begin
  311. asm
  312. { get base pointer of error }
  313. move.l (a6),d0
  314. move.l d0,@RESULT
  315. end ['d0'];
  316. end;
  317. begin
  318. If ErrorProc<>Nil then
  319. TErrorProc (ErrorProc)(Errno,get_addr);
  320. errorcode:=Errno;
  321. exitcode:=Errno;
  322. erroraddr:=Get_addr;
  323. DoError := TRUE;
  324. errorbase:=get_error_bp;
  325. halt(errorcode);
  326. end;
  327. procedure runerror(w : word);
  328. function get_addr : longint;
  329. begin
  330. asm
  331. move.l (a6),a0
  332. move.l 4(a0),a0
  333. move.l a0,@RESULT
  334. end ['a0'];
  335. end;
  336. function get_error_bp : longint;
  337. begin
  338. asm
  339. { get base pointer of error }
  340. move.l (a6),d0
  341. move.l d0,@RESULT
  342. end ['d0'];
  343. end;
  344. begin
  345. errorcode:=w;
  346. exitcode:=w;
  347. erroraddr:=pointer(get_addr);
  348. DoError:=True;
  349. ErrorBase:=get_error_bp;
  350. halt(byte(errorcode));
  351. end;
  352. procedure io1(addr : longint);[public,alias: 'IOCHECK'];
  353. var
  354. l : longint;
  355. begin
  356. { Since IOCHECK is called directly and only later the optimiser }
  357. { Maybe also save global registers }
  358. asm
  359. movem.l d0-a7,-(sp)
  360. end;
  361. l:=ioresult;
  362. if l<>0 then
  363. begin
  364. writeln('IO-Error ',l,' at 0x',HexStr(addr,8));
  365. halt(byte(l));
  366. end;
  367. asm
  368. { the register are put back in the correct order }
  369. movem.l (sp)+,d0-a7
  370. end;
  371. end;
  372. procedure re_overflow;[public,alias: 'RE_OVERFLOW'];
  373. var
  374. addr : longint;
  375. begin
  376. { Overflow was shortly before the return address }
  377. asm
  378. move.l 4(a6),d0
  379. move.l d0,addr
  380. end;
  381. writeln('Overflow at 0x',HexStr(addr,8));
  382. HandleError(215);
  383. end;
  384. { procedure strcopy(dstr,sstr : pointer;len : longint);[public,alias: 'STRCOPY'];}
  385. procedure strcopy; assembler;
  386. {---------------------------------------------------}
  387. { Low-level routine to copy a string to another }
  388. { string with maximum length. Never call directly! }
  389. { On Entry: }
  390. { a1.l = string to copy to }
  391. { a0.l = source string }
  392. { d0.l = maximum length of copy }
  393. { registers destroyed: a0,a1,d0,d1 }
  394. {---------------------------------------------------}
  395. asm
  396. XDEF STRCOPY
  397. { move.l 12(a6),a0
  398. move.l 16(a6),a1
  399. move.l 8(a6),d1 }
  400. move.l d0,d1
  401. move.b (a0)+,d0 { Get source length }
  402. and.w #$ff,d0
  403. cmp.w d1,d0 { This is a signed comparison! }
  404. ble @LM4
  405. move.b d1,d0 { If longer than maximum size of target, cut
  406. source length }
  407. @LM4:
  408. andi.l #$ff,d0 { zero extend d0-byte }
  409. move.l d0,d1 { save length to copy }
  410. move.b d0,(a1)+ { save new length }
  411. { Check if copying length is zero - if so then }
  412. { exit without copying anything. }
  413. tst.b d1
  414. beq @Lend
  415. bra @LMSTRCOPY55
  416. @LMSTRCOPY56: { 68010 Fast loop mode }
  417. move.b (a0)+,(a1)+
  418. @LMSTRCOPY55:
  419. dbra d1,@LMSTRCOPY56
  420. @Lend:
  421. end;
  422. { Concatenate Strings }
  423. { PARAMETERS ARE REVERSED COMPARED TO NORMAL! }
  424. { therefore online assembler may not parse the params as normal }
  425. procedure strconcat(s1,s2 : pointer);[public,alias: 'STRCONCAT'];
  426. begin
  427. asm
  428. move.b #255,d0
  429. move.l s1,a0 { a0 = destination }
  430. move.l s2,a1 { a1 = source }
  431. sub.b (a0),d0 { copyl:= 255 -length(s1) }
  432. move.b (a1),d6
  433. and.w #$ff,d0 { Sign flags are checked! }
  434. and.w #$ff,d6
  435. cmp.w d6,d0 { if copyl > length(s2) then }
  436. ble @Lcontinue
  437. move.b (a1),d0 { copyl:=length(s2) }
  438. @Lcontinue:
  439. move.b (a0),d6
  440. and.l #$ff,d6
  441. lea 1(a0,d6),a0 { s1[length(s1)+1] }
  442. add.l #1,a1 { s2[1] }
  443. move.b d0,d6
  444. { Check if copying length is zero - if so then }
  445. { exit without copying anything. }
  446. tst.b d6
  447. beq @Lend
  448. bra @ALoop
  449. @Loop:
  450. move.b (a1)+,(a0)+ { s1[i] := s2[i]; }
  451. @ALoop:
  452. dbra d6,@Loop
  453. move.l s1,a0
  454. add.b d0,(a0) { change to new string length }
  455. @Lend:
  456. end ['d0','d1','a0','a1','d6'];
  457. end;
  458. { Compares strings }
  459. { DO NOT CALL directly. }
  460. { a0 = pointer to first string to compare }
  461. { a1 = pointer to second string to compare }
  462. { ALL FLAGS are set appropriately. }
  463. { ZF = strings are equal }
  464. { REGISTERS DESTROYED: a0, a1, d0, d1, d6 }
  465. procedure strcmp; assembler;
  466. asm
  467. XDEF STRCMP
  468. move.b (a0)+,d0 { Get length of first string }
  469. move.b (a1)+,d6 { Get length of 2nd string }
  470. move.b d6,d1 { Save length of string for final compare }
  471. cmp.b d0,d6 { Get shortest string length }
  472. ble @LSTRCONCAT1
  473. move.b d0,d6 { Set length to shortest string }
  474. @LSTRCONCAT1:
  475. tst.b d6 { Both strings have a length of zero, exit }
  476. beq @LSTRCONCAT2
  477. andi.l #$ff,d6
  478. subq.l #1,d6 { subtract first attempt }
  479. { if value is -1 then don't loop and just compare lengths of }
  480. { both strings before exiting. }
  481. bmi @LSTRCONCAT2
  482. or.l d0,d0 { Make sure to set Zerfo flag to 0 }
  483. @LSTRCONCAT5:
  484. { Workaroung for GAS v.134 bug }
  485. { old: cmp.b (a1)+,(a0)+ }
  486. cmpm.b (a1)+,(a0)+
  487. @LSTRCONCAT4:
  488. dbne d6,@LSTRCONCAT5 { Repeat until not equal }
  489. bne @LSTRCONCAT3
  490. @LSTRCONCAT2:
  491. { If length of both string are equal }
  492. { Then set zero flag }
  493. cmp.b d1,d0 { Compare length - set flag if equal length strings }
  494. @LSTRCONCAT3:
  495. end;
  496. Function strpas(p: pchar): string;
  497. { only 255 first characters are actually copied. }
  498. var
  499. counter : byte;
  500. str: string;
  501. Begin
  502. counter := 0;
  503. str := '';
  504. while (ord(p[counter]) <> 0) and (counter < 255) do
  505. begin
  506. counter:=counter+1;
  507. str[counter] := char(p[counter-1]);
  508. end;
  509. str[0] := char(counter);
  510. strpas := str;
  511. end;
  512. function strlen(p : pchar) : longint;
  513. var
  514. counter : longint;
  515. Begin
  516. counter := 0;
  517. repeat
  518. counter:=counter+1;
  519. until ord(p[counter]) = 0;
  520. strlen := counter;
  521. end;
  522. procedure move(var source;var dest;count : longint);
  523. { base pointer+8 = source }
  524. { base pointer+12 = destination }
  525. { base pointer+16 = number of bytes to move}
  526. begin
  527. asm
  528. clr.l d0
  529. move.l 16(a6),d0 { number of bytes }
  530. @LMOVE0:
  531. move.l 12(a6),a1 { destination }
  532. move.l 8(a6),a0 { source }
  533. cmpi.l #65535, d0 { check, if this is a word move }
  534. ble @LMEMSET00 { use fast dbra mode 68010+ }
  535. cmp.l a0,a1 { check copy direction }
  536. bls @LMOVE4
  537. add.l d0,a0 { move pointers to end }
  538. add.l d0,a1
  539. bra @LMOVE2
  540. @LMOVE1:
  541. move.b -(a0),-(a1) { (s < d) copy loop }
  542. @LMOVE2:
  543. subq.l #1,d0
  544. cmpi.l #-1,d0
  545. bne @LMOVE1
  546. bra @LMOVE5
  547. @LMOVE3:
  548. move.b (a0)+,(a1)+ { (s >= d) copy loop }
  549. @LMOVE4:
  550. subq.l #1,d0
  551. cmpi.l #-1,d0
  552. bne @LMOVE3
  553. bra @LMOVE5
  554. @LMEMSET00: { use fast loop mode 68010+ }
  555. cmp.l a0,a1 { check copy direction }
  556. bls @LMOVE04
  557. add.l d0,a0 { move pointers to end }
  558. add.l d0,a1
  559. bra @LMOVE02
  560. @LMOVE01:
  561. move.b -(a0),-(a1) { (s < d) copy loop }
  562. @LMOVE02:
  563. dbra d0,@LMOVE01
  564. bra @LMOVE5
  565. @LMOVE03:
  566. move.b (a0)+,(a1)+ { (s >= d) copy loop }
  567. @LMOVE04:
  568. dbra d0,@LMOVE03
  569. { end fast loop mode }
  570. @LMOVE5:
  571. end ['d0','a0','a1'];
  572. end;
  573. procedure fillword(var x;count : longint;value : word);
  574. begin
  575. asm
  576. move.l 8(a6), a0 { destination }
  577. move.l 12(a6), d1 { number of bytes to fill }
  578. move.w 16(a6),d0 { fill data }
  579. bra @LMEMSET21
  580. @LMEMSET11:
  581. move.w d0,(a0)+
  582. @LMEMSET21:
  583. subq.l #1,d1
  584. cmp.b #-1,d1
  585. bne @LMEMSET11
  586. end ['d0','d1','a0'];
  587. end;
  588. function abs(l : longint) : longint;
  589. begin
  590. asm
  591. move.l 8(a6),d0
  592. tst.l d0
  593. bpl @LMABS1
  594. neg.l d0
  595. @LMABS1:
  596. move.l d0,@RESULT
  597. end ['d0'];
  598. end;
  599. function odd(l : longint) : boolean;
  600. begin
  601. if (l and $01) = $01 then
  602. odd := TRUE
  603. else
  604. odd := FALSE;
  605. end;
  606. function sqr(l : longint) : longint;
  607. begin
  608. sqr := l*l;
  609. end;
  610. procedure int_str(l : longint;var s : string);
  611. var
  612. value: longint;
  613. negative: boolean;
  614. begin
  615. negative := false;
  616. s:='';
  617. { Workaround: }
  618. if l=$80000000 then
  619. begin
  620. s:='-2147483648';
  621. exit;
  622. end;
  623. { handle case where l = 0 }
  624. if l = 0 then
  625. begin
  626. s:='0';
  627. exit;
  628. end;
  629. If l < 0 then
  630. begin
  631. negative := true;
  632. value:=abs(l);
  633. end
  634. else
  635. value:=l;
  636. { handle non-zero case }
  637. while value>0 do
  638. begin
  639. s:=char((value mod 10)+ord('0'))+s;
  640. value := value div 10;
  641. end;
  642. if negative then
  643. s := '-' + s;
  644. end;
  645. {$IFNDEF NEW_READWRITE}
  646. procedure f1;[public,alias: 'FLUSH_STDOUT'];
  647. begin
  648. asm
  649. { Save Registers }
  650. movem.l d0-a7,-(sp)
  651. end;
  652. FileFunc(textrec(output).flushfunc)(textrec(output));
  653. asm
  654. { Restore all registers in the correct order }
  655. movem.l (sp)+,d0-a7
  656. end;
  657. end;
  658. {$ENDIF NEW_READWRITE}
  659. Function Sptr : Longint;
  660. begin
  661. asm
  662. move.l sp,d0
  663. add.l #8,d0
  664. move.l d0,@RESULT
  665. end ['d0'];
  666. end;
  667. Procedure BoundsCheck;assembler;
  668. { called by code generator with R+ state to }
  669. { determine if a range check occured. }
  670. { Only in 68000 mode, in 68020 mode this is }
  671. { inline. }
  672. { On Entry: }
  673. { A1 = address contaning min and max indexes }
  674. { D0 = value of current index to check. }
  675. asm
  676. XDEF RE_BOUNDS_CHECK
  677. cmp.l (A1),D0 { lower bound ... }
  678. bmi @rebounderr { is index lower ... }
  679. add.l #4,A1
  680. cmp.l (A1),D0
  681. bmi @reboundend
  682. beq @reboundend
  683. @rebounderr:
  684. move.l #201,d0
  685. jsr HALT_ERROR
  686. @reboundend:
  687. end;
  688. {
  689. $Log$
  690. Revision 1.9 1998-07-30 13:26:14 michael
  691. + Added support for ErrorProc variable. All internal functions are required
  692. to call HandleError instead of runerror from now on.
  693. This is necessary for exception support.
  694. Revision 1.8 1998/07/10 11:02:41 peter
  695. * support_fixed, becuase fixed is not 100% yet for the m68k
  696. Revision 1.7 1998/07/02 12:20:58 carl
  697. + Io-Error and overflow print erroraddr in hex now
  698. Revision 1.6 1998/07/01 14:25:57 carl
  699. * strconcat was copying one byte too much
  700. * strcopy bugfix was using signed comparison
  701. + STRCOPY uses register calling conventions
  702. * FillChar bugfix was loading a word instead of a byte
  703. Revision 1.2 1998/03/27 23:48:06 carl
  704. * bugfix of STRCONCAT alignment problem
  705. Revision 1.18 1998/03/02 04:17:24 carl
  706. * problem with CHECK_OBJECT fixed, will probably only work with
  707. GNU tools, as the VMT pointer is an .lcomm and might not be
  708. zeroed automatically by other loaders.
  709. * CHECK_OBJECT was not jumping on right condition
  710. Revision 1.17 1998/02/23 02:26:06 carl
  711. * bugfix to make it link without problems
  712. Revision 1.13 1998/02/06 16:35:35 carl
  713. * oops commited wrong file
  714. Revision 1.11 1998/01/26 12:01:32 michael
  715. + Added log at the end
  716. Working file: rtl/m68k/m68k.inc
  717. description:
  718. ----------------------------
  719. revision 1.10
  720. date: 1998/01/19 10:21:36; author: michael; state: Exp; lines: +1 -12
  721. * moved Fillchar t(..,char) to system.inc
  722. ----------------------------
  723. revision 1.9
  724. date: 1998/01/13 03:47:39; author: carl; state: Exp; lines: +3 -3
  725. * bugfix of BoundsCheck invalid opcodes
  726. ----------------------------
  727. revision 1.8
  728. date: 1998/01/13 03:24:58; author: carl; state: Exp; lines: +2 -2
  729. * moveq.l #201 bugfix (This is of course an impossible opcode)
  730. ----------------------------
  731. revision 1.7
  732. date: 1998/01/12 15:24:47; author: carl; state: Exp; lines: +1 -20
  733. * bugfix, a function was being duplicated.
  734. ----------------------------
  735. revision 1.6
  736. date: 1998/01/12 03:40:11; author: carl; state: Exp; lines: +2 -2
  737. * bugfix of RE_OVERFLOW, now gives out a runerror(215)
  738. ----------------------------
  739. revision 1.5
  740. date: 1998/01/05 00:31:43; author: carl; state: Exp; lines: +206 -119
  741. * Bugfix of syntax errors
  742. ----------------------------
  743. revision 1.4
  744. date: 1998/01/01 16:50:16; author: michael; state: Exp; lines: +1 -21
  745. - Moved Do_exit to system.inc. Now processor independent.
  746. ----------------------------
  747. revision 1.3
  748. date: 1997/12/10 12:15:05; author: michael; state: Exp; lines: +2 -2
  749. * changed dateifunc to FileFunc.
  750. ----------------------------
  751. revision 1.2
  752. date: 1997/12/01 12:37:21; author: michael; state: Exp; lines: +14 -0
  753. + added copyright reference in header.
  754. ----------------------------
  755. revision 1.1
  756. date: 1997/11/27 08:33:48; author: michael; state: Exp;
  757. Initial revision
  758. ----------------------------
  759. revision 1.1.1.1
  760. date: 1997/11/27 08:33:48; author: michael; state: Exp; lines: +0 -0
  761. FPC RTL CVS start
  762. =============================================================================
  763. }