generic.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Processor independent implementation for the system unit
  6. (adapted for intel i386.inc file)
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {****************************************************************************
  14. Primitives
  15. ****************************************************************************}
  16. {$ifndef FPC_SYSTEM_HAS_MOVE}
  17. procedure Move(var source;var dest;count:longint);
  18. type
  19. longintarray = array [0..maxlongint] of longint;
  20. bytearray = array [0..maxlongint] of byte;
  21. var
  22. i,size : longint;
  23. begin
  24. size:=count div sizeof(longint);
  25. if (@dest)<@source) or
  26. (@dest>@source+count) then
  27. begin
  28. for i:=0 to size-1 do
  29. longintarray(dest)[i]:=longintarray(source)[i];
  30. for i:=size*sizeof(longint) to count-1 do
  31. bytearray(dest)[i]:=bytearray(source)[i];
  32. end
  33. else
  34. begin
  35. for i:=count-1 downto size*sizeof(longint) do
  36. bytearray(dest)[i]:=bytearray(source)[i];
  37. for i:=size-1 downto 0 do
  38. longintarray(dest)[i]:=longintarray(source)[i];
  39. end;
  40. end;
  41. {$endif ndef FPC_SYSTEM_HAS_MOVE}
  42. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  43. Procedure FillChar(var x;count:longint;value:byte);
  44. type
  45. longintarray = array [0..maxlongint] of longint;
  46. bytearray = array [0..maxlongint] of byte;
  47. var
  48. i,v : longint;
  49. begin
  50. v:=value*256+value;
  51. v:=v*$10000+v;
  52. for i:=0 to (count div 4) -1 do
  53. longintarray(x)[i]:=v;
  54. for i:=(count div 4)*4 to count-1 do
  55. bytearray(x)[i]:=value;
  56. end;
  57. {$endif ndef FPC_SYSTEM_HAS_FILLCHAR}
  58. {$ifndef RTLLITE}
  59. {$ifndef FPC_SYSTEM_HAS_FILLBYTE}
  60. procedure FillByte (var x;count : longint;value : byte );
  61. begin
  62. FillChar (X,Count,CHR(VALUE));
  63. end;
  64. {$endif ndef FPC_SYSTEM_HAS_FILLBYTE}
  65. {$ifndef FPC_SYSTEM_HAS_FILLWORD}
  66. procedure fillword(var x;count : longint;value : word);
  67. type
  68. longintarray = array [0..maxlongint] of longint;
  69. wordarray = array [0..maxlongint] of word;
  70. var
  71. i,v : longint;
  72. begin
  73. v:=value*$10000+value;
  74. for i:=0 to (count div 2) -1 do
  75. longintarray(x)[i]:=v;
  76. for i:=(count div 2)*2 to count-1 do
  77. wordarray(x)[i]:=value;
  78. end;
  79. {$endif ndef FPC_SYSTEM_HAS_FILLWORD}
  80. {$ifndef FPC_SYSTEM_HAS_FILLDWORD}
  81. procedure FillDWord(var x;count : longint;value : DWord);
  82. var
  83. I : longint;
  84. begin
  85. if Count<>0 then
  86. begin
  87. I:=Count;
  88. while I<>0 do
  89. begin
  90. PDWord(@X)[I-1]:=Value;
  91. Dec(I);
  92. end;
  93. end;
  94. end;
  95. {$endif ndef FPC_SYSTEM_HAS_FILLDWORD}
  96. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR}
  97. function IndexChar(var buf;len:longint;b:char):longint;
  98. begin
  99. IndexChar:=IndexByte(Buf,Len,byte(B));
  100. end;
  101. {$endif ndef FPC_SYSTEM_HAS_INDEXCHAR}
  102. {$ifndef FPC_SYSTEM_HAS_INDEXBYTE}
  103. function IndexByte(var buf;len:longint;b:byte):longint;
  104. var
  105. I : longint;
  106. begin
  107. I:=0;
  108. while (pbyte(@buf)[I]<>b) and (I<Len) do
  109. inc(I);
  110. if (i=Len) then
  111. i:=-1; {Can't use 0, since it is a possible value}
  112. IndexByte:=I;
  113. end;
  114. {$endif ndef FPC_SYSTEM_HAS_INDEXBYTE}
  115. {$ifndef FPC_SYSTEM_HAS_INDEXWORD}
  116. function Indexword(var buf;len:longint;b:word):longint;
  117. var
  118. I : longint;
  119. begin
  120. I:=0;
  121. while (pword(@buf)[I]<>b) and (I<Len) do
  122. inc(I);
  123. if (i=Len) then
  124. i:=-1; {Can't use 0, since it is a possible value for index}
  125. Indexword:=I;
  126. end;
  127. {$endif ndef FPC_SYSTEM_HAS_INDEXWORD}
  128. {$ifndef FPC_SYSTEM_HAS_INDEXDWORD}
  129. function IndexDWord(var buf;len:longint;b:DWord):longint;
  130. var
  131. I : longint;
  132. begin
  133. I:=0;
  134. while (PDWord(@buf)[I]<>b) and (I<Len) do inc(I);
  135. if (i=Len) then
  136. i:=-1; {Can't use 0, since it is a possible value for index}
  137. IndexDWord:=I;
  138. end;
  139. {$endif ndef FPC_SYSTEM_HAS_INDEXDWORD}
  140. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR}
  141. function CompareChar(var buf1,buf2;len:longint):longint;
  142. begin
  143. CompareChar:=CompareByte(buf1,buf2,len);
  144. end;
  145. {$endif ndef FPC_SYSTEM_HAS_COMPARECHAR}
  146. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  147. function CompareByte(var buf1,buf2;len:longint):longint;
  148. var
  149. I,J : longint;
  150. begin
  151. I:=0;
  152. if (Len<>0) and (@Buf1<>@Buf2) then
  153. begin
  154. while (pbyte(@Buf1)[I]=pbyte(@Buf2)[I]) and (I<Len) do
  155. inc(I);
  156. if I=Len then {No difference}
  157. I:=0
  158. else
  159. begin
  160. I:=pbyte(@Buf1)[I]-pbyte(@Buf2)[I];
  161. if I>0 then
  162. I:=1
  163. else
  164. if I<0 then
  165. I:=-1;
  166. end;
  167. end;
  168. CompareByte:=I;
  169. end;
  170. {$endif ndef FPC_SYSTEM_HAS_COMPAREBYTE}
  171. {$ifndef FPC_SYSTEM_HAS_COMPAREWORD}
  172. function CompareWord(var buf1,buf2;len:longint):longint;
  173. var
  174. I,J : longint;
  175. begin
  176. I:=0;
  177. if (Len<>0) and (@Buf1<>@Buf2) then
  178. begin
  179. while (pword(@Buf1)[I]=pword(@Buf2)[I]) and (I<Len) do
  180. inc(I);
  181. if I=Len then {No difference}
  182. I:=0
  183. else
  184. begin
  185. I:=pword(@Buf1)[I]-pword(@Buf2)[I];
  186. if I>0 then
  187. I:=1
  188. else
  189. if I<0 then
  190. I:=-1;
  191. end;
  192. end;
  193. CompareWord:=I;
  194. end;
  195. {$endif ndef FPC_SYSTEM_HAS_COMPAREWORD}
  196. {$ifndef FPC_SYSTEM_HAS_COMPAREDWORD}
  197. function CompareDWord(var buf1,buf2;len:longint):longint;
  198. var
  199. I,J : longint;
  200. begin
  201. I:=0;
  202. if (Len<>0) and (@Buf1<>@Buf2) then
  203. begin
  204. while (PDWord(@Buf1)[I]=PDWord(@Buf2)[I]) and (I<Len) do
  205. inc(I);
  206. if I=Len then {No difference}
  207. I:=0
  208. else
  209. begin
  210. I:=PDWord(@Buf1)[I]-PDWord(@Buf2)[I];
  211. if I>0 then
  212. I:=1
  213. else
  214. if I<0 then
  215. I:=-1;
  216. end;
  217. end;
  218. CompareDWord:=I;
  219. end;
  220. {$endif ndef FPC_SYSTEM_HAS_COMPAREDWORD}
  221. {$ifndef FPC_SYSTEM_HAS_MOVECHAR0}
  222. procedure MoveChar0(var buf1,buf2;len:longint);
  223. var
  224. I : longint;
  225. begin
  226. if Len<> 0 then
  227. begin
  228. I:=IndexByte(Buf1,Len,0);
  229. if I<>0 then
  230. Move(Buf1,Buf2,I);
  231. end;
  232. end;
  233. {$endif ndef FPC_SYSTEM_HAS_MOVECHAR0}
  234. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR0}
  235. function IndexChar0(var buf;len:longint;b:Char):longint;
  236. var
  237. I : longint;
  238. begin
  239. if Len<>0 then
  240. begin
  241. I:=IndexByte(Buf,Len,0);
  242. IndexChar0:=IndexByte(Buf,I,0);
  243. end
  244. else
  245. IndexChar0:=0;
  246. end;
  247. {$endif ndef FPC_SYSTEM_HAS_INDEXCHAR0}
  248. {$ifndef FPC_SYSTEM_HAS_COMPARECHAR0}
  249. function CompareChar0(var buf1,buf2;len:longint):longint;
  250. var
  251. I,J,K,bytesTodo : longint;
  252. begin
  253. K:=0;
  254. if Len<>0 then
  255. begin
  256. I:=IndexByte(Buf1,Len,0);
  257. J:=IndexByte(Buf2,Len,0);
  258. if (I<>0) and (J<>0) then
  259. begin
  260. bytesTodo:=I;
  261. if J<bytesTodo then
  262. bytesTodo:=J;
  263. K:=CompareByte(Buf1,Buf2,bytesTodo); // Safe for bytesTodo=0
  264. end;
  265. end;
  266. CompareChar0:=K;
  267. end;
  268. {$endif ndef FPC_SYSTEM_HAS_COMPARECHAR0}
  269. {$endif ndef RTLLITE}
  270. {****************************************************************************
  271. Object Helpers
  272. ****************************************************************************}
  273. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  274. { Generic code does not set the register used for self !
  275. So this needs to be done by the compiler after calling
  276. FPC_HELP_CONSTRUCTOR : generic allways means aa little less efficient (PM) }
  277. procedure int_help_constructor(var _self : pointer; vmt : pointer; vmt_pos : cardinal); [public,alias:'FPC_HELP_CONSTRUCTOR'];
  278. type
  279. ppointer = ^pointer;
  280. pvmt = ^tvmt;
  281. tvmt = record
  282. size,msize : longint;
  283. parent : pointer;
  284. end;
  285. var
  286. objectsize : longint;
  287. begin
  288. objectsize:=pvmt(vmt)^.size;
  289. getmem(_self,objectsize);
  290. fillchar(_self,objectsize,#0);
  291. ppointer(_self+vmt_pos)^:=vmt;
  292. end;
  293. {$endif ndef FPC_SYSTEM_HAS_FPC_HELP_CONSTRUCTOR}
  294. {$ifndef FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  295. procedure int_help_destructor(var _self : pointer; vmt : pointer; vmt_pos : cardinal);[public,alias:'FPC_HELP_DESTRUCTOR'];
  296. type
  297. ppointer = ^pointer;
  298. pvmt = ^tvmt;
  299. tvmt = record
  300. size,msize : longint;
  301. parent : pointer;
  302. end;
  303. var
  304. objectsize : longint;
  305. begin
  306. if (_self=nil) then
  307. exit;
  308. if (pvmt(ppointer(_self+vmt_pos)^)^.size=0) or
  309. (pvmt(ppointer(_self+vmt_pos)^)^.size+pvmt(ppointer(_self+vmt_pos)^)^.msize<>0) then
  310. RunError(210);
  311. objectsize:=pvmt(vmt)^.size;
  312. { reset vmt to nil for protection }
  313. ppointer(_self+vmt_pos)^:=nil;
  314. freemem(_self,objectsize);
  315. _self:=nil;
  316. end;
  317. {$endif ndef FPC_SYSTEM_HAS_FPC_HELP_DESTRUCTOR}
  318. {$ifndef FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  319. {$error No pascal version of Int_new_class}
  320. (* procedure int_new_class;assembler;[public,alias:'FPC_NEW_CLASS'];
  321. asm
  322. { to be sure in the future, we save also edit }
  323. pushl %edi
  324. { create class ? }
  325. movl 8(%ebp),%edi
  326. orl %edi,%edi
  327. jz .LNEW_CLASS1
  328. { save registers !! }
  329. pushl %ebx
  330. pushl %ecx
  331. pushl %edx
  332. { esi contains the vmt }
  333. pushl %esi
  334. { call newinstance (class method!) }
  335. call *16(%esi)
  336. popl %edx
  337. popl %ecx
  338. popl %ebx
  339. { newinstance returns a pointer to the new created }
  340. { instance in eax }
  341. { load esi and insert self }
  342. movl %eax,%esi
  343. .LNEW_CLASS1:
  344. movl %esi,8(%ebp)
  345. orl %eax,%eax
  346. popl %edi
  347. end; *)
  348. {$endif ndef FPC_SYSTEM_HAS_FPC_NEW_CLASS}
  349. {$ifndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  350. {$error No pascal version of Int_dispose_class}
  351. (* procedure int_dispose_class;assembler;[public,alias:'FPC_DISPOSE_CLASS'];
  352. asm
  353. { to be sure in the future, we save also edit }
  354. pushl %edi
  355. { destroy class ? }
  356. movl 12(%ebp),%edi
  357. orl %edi,%edi
  358. jz .LDISPOSE_CLASS1
  359. { no inherited call }
  360. movl (%esi),%edi
  361. { save registers !! }
  362. pushl %eax
  363. pushl %ebx
  364. pushl %ecx
  365. pushl %edx
  366. { push self }
  367. pushl %esi
  368. { call freeinstance }
  369. call *20(%edi)
  370. popl %edx
  371. popl %ecx
  372. popl %ebx
  373. popl %eax
  374. .LDISPOSE_CLASS1:
  375. popl %edi
  376. end; *)
  377. {$endif ndef FPC_SYSTEM_HAS_FPC_DISPOSE_CLASS}
  378. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  379. procedure int_check_object(vmt : pointer);[public,alias:'FPC_CHECK_OBJECT'];
  380. type
  381. pvmt = ^tvmt;
  382. tvmt = record
  383. size,msize : longint;
  384. parent : pointer;
  385. end;
  386. begin
  387. if (vmt=nil) or
  388. (pvmt(vmt)^.size=0) or
  389. (pvmt(vmt)^.size+pvmt(vmt)^.msize<>0) then
  390. RunError(210);
  391. end;
  392. {$endif ndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT}
  393. { checks for a correct vmt pointer }
  394. { deeper check to see if the current object is }
  395. { really related to the true }
  396. {$ifndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  397. procedure int_check_object_ext(vmt, expvmt : pointer);[public,alias:'FPC_CHECK_OBJECT_EXT'];
  398. type
  399. pvmt = ^tvmt;
  400. tvmt = record
  401. size,msize : longint;
  402. parent : pointer;
  403. end;
  404. begin
  405. if (vmt=nil) or
  406. (pvmt(vmt)^.size=0) or
  407. (pvmt(vmt)^.size+pvmt(vmt)^.msize<>0) then
  408. RunError(210);
  409. while assigned(vmt) do
  410. if vmt=expvmt then
  411. exit
  412. else
  413. vmt:=pvmt(vmt)^.parent;
  414. RunError(220);
  415. end;
  416. {$endif ndef FPC_SYSTEM_HAS_FPC_CHECK_OBJECT_EXT}
  417. {****************************************************************************
  418. String
  419. ****************************************************************************}
  420. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
  421. procedure int_strcopy(len:longint;sstr,dstr:pointer);[public,alias:'FPC_SHORTSTR_COPY'];
  422. var
  423. slen : byte;
  424. begin
  425. if dstr=nil then
  426. exit;
  427. if sstr=nil then
  428. begin
  429. if dstr<>nil then
  430. pstring(dstr)^[0]:=#0;
  431. exit;
  432. end;
  433. slen:=length(pstring(sstr)^);
  434. if slen<len then
  435. len:=slen;
  436. move(sstr^,dstr^,len);
  437. pstring(dstr)^[0]:=chr(len);
  438. end;
  439. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COPY}
  440. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  441. procedure int_strconcat(s1,s2:pointer);[public,alias:'FPC_SHORTSTR_CONCAT'];
  442. var
  443. s1l, s2l : byte;
  444. begin
  445. if (s1=nil) or (s2=nil) then
  446. exit;
  447. s1l:=length(pstring(s1)^);
  448. s2l:=length(pstring(s2)^);
  449. if s1l+s2l>255 then
  450. s1l:=255-s2l;
  451. move(@(pstring(s1)^[1]),@(pstring(s2)^[s2l+1]),s1l);
  452. pstring(s2)^[0]:=chr(s1l+s2l);
  453. end;
  454. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  455. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  456. function int_strcmp(dstr,sstr:pointer) : longint;[public,alias:'FPC_SHORTSTR_COMPARE'];
  457. var
  458. s1,s2,max,i : byte;
  459. d : longint;
  460. begin
  461. s1:=length(pstring(dstr)^);
  462. s2:=length(pstring(sstr)^);
  463. if s1<s2 then
  464. max:=s1
  465. else
  466. max:=s2;
  467. for i:=1 to max do
  468. begin
  469. d:=byte(pstring(dstr)^[i])-byte(pstring(sstr)^[i]);
  470. if d>0 then
  471. exit(1)
  472. else if d<0 then
  473. exit(-1);
  474. end;
  475. if s1>s2 then
  476. exit(1)
  477. else if s1<s2 then
  478. exit(-1)
  479. else
  480. exit(0);
  481. end;
  482. {$endif ndef FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  483. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  484. function strpas(p:pchar):string;[public,alias:'FPC_PCHAR_TO_SHORTSTR'];
  485. var
  486. l : longint;
  487. begin
  488. if p=nil then
  489. l:=0
  490. else
  491. l:=strlen(p);
  492. if l>255 then
  493. l:=255;
  494. if l>0 then
  495. move(p^,@(strpas[1]),l);
  496. strpas[0]:=chr(l);
  497. end;
  498. {$endif ndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  499. {$ifndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  500. function strchararray(p:pchar; l : longint):shortstring;[public,alias:'FPC_CHARARRAY_TO_SHORTSTR'];
  501. begin
  502. if l>=256 then
  503. l:=255
  504. else if l<0 then
  505. l:=0;
  506. move(p^,@(strchararray[1]),l);
  507. strchararray[0]:=chr(l);
  508. end;
  509. {$endif ndef FPC_SYSTEM_HAS_FPC_CHARARRAY_TO_SHORTSTR}
  510. {$ifndef FPC_SYSTEM_HAS_STRLEN}
  511. function strlen(p:pchar):longint;
  512. var i : longint;
  513. begin
  514. i:=0;
  515. while p[i]<>#0 do inc(i);
  516. exit(i);
  517. end;
  518. {$endif ndef FPC_SYSTEM_HAS_STRLEN}
  519. {****************************************************************************
  520. Caller/StackFrame Helpers
  521. ****************************************************************************}
  522. {$ifndef FPC_SYSTEM_HAS_GET_FRAME}
  523. {$error Get_frame must be defined for each processor }
  524. {$endif ndef FPC_SYSTEM_HAS_GET_FRAME}
  525. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  526. {$error Get_caller_addr must be defined for each processor }
  527. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  528. {$ifndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  529. {$error Get_caller_frame must be defined for each processor }
  530. {$endif ndef FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  531. {****************************************************************************
  532. Math
  533. ****************************************************************************}
  534. {$ifndef FPC_SYSTEM_HAS_ABS_LONGINT}
  535. function abs(l:longint):longint;[internconst:in_const_abs];
  536. begin
  537. if l<0 then
  538. abs:=-l
  539. else
  540. abs:=l;
  541. end;
  542. {$endif ndef FPC_SYSTEM_HAS_ABS_LONGINT}
  543. {$ifndef FPC_SYSTEM_HAS_ODD_LONGINT}
  544. function odd(l:longint):boolean;[internconst:in_const_odd];
  545. begin
  546. odd:=((l and 1)<>0);
  547. end;
  548. {$endif ndef FPC_SYSTEM_HAS_ODD_LONGINT}
  549. {$ifndef FPC_SYSTEM_HAS_SQR_LONGINT}
  550. function sqr(l:longint):longint;[internconst:in_const_sqr];
  551. begin
  552. sqr:=l*l;
  553. end;
  554. {$endif ndef FPC_SYSTEM_HAS_SQR_LONGINT}
  555. {$ifndef FPC_SYSTEM_HAS_SPTR}
  556. {$error Sptr must be defined for each processor }
  557. {$endif ndef FPC_SYSTEM_HAS_SPTR}
  558. {****************************************************************************
  559. Str()
  560. ****************************************************************************}
  561. {$ifndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  562. procedure int_str(l : longint;var s : string);
  563. var
  564. sign : boolean;
  565. begin
  566. { Workaround: }
  567. if l=$80000000 then
  568. begin
  569. s:='-2147483648';
  570. exit;
  571. end;
  572. if l<0 then
  573. begin
  574. sign:=true;
  575. l:=-l;
  576. end
  577. else
  578. sign:=false;
  579. s:='';
  580. while l>0 do
  581. begin
  582. s:=char(ord('0')+(l mod 10))+s;
  583. l:=l div 10;
  584. end;
  585. if sign then
  586. s:='-'+s;
  587. end;
  588. {$endif ndef FPC_SYSTEM_HAS_INT_STR_LONGINT}
  589. {$ifndef FPC_SYSTEM_HAS_INT_STR_CARDINAL}
  590. procedure int_str(l : cardinal;var s : string);
  591. begin
  592. s:='';
  593. while l>0 do
  594. begin
  595. s:=char(ord('0')+(l mod 10))+s;
  596. l:=l div 10;
  597. end;
  598. if sign then
  599. s:='-'+s;
  600. end;
  601. {$endif ndef FPC_SYSTEM_HAS_INT_STR_CARDINAL}
  602. {****************************************************************************
  603. Bounds Check
  604. ****************************************************************************}
  605. {$ifndef FPC_SYSTEM_HAS_FPC_BOUNDCHECK}
  606. procedure int_boundcheck(l : longint; range : pointer);[public,alias: 'FPC_BOUNDCHECK'];
  607. type
  608. prange = ^trange;
  609. trange = record
  610. min,max : longint;
  611. end;
  612. begin
  613. if (l < prange(range)^.min) or
  614. (l > prange(range)^.max) then
  615. HandleError(201);
  616. end;
  617. {$endif ndef FPC_SYSTEM_HAS_FPC_BOUNDCHECK}
  618. {$ifndef HASSAVEREGISTERS}
  619. {****************************************************************************
  620. IoCheck
  621. ****************************************************************************}
  622. {$ifndef FPC_SYSTEM_HAS_FPC_IOCHECK}
  623. procedure int_iocheck(addr : longint);[public,alias:'FPC_IOCHECK'];
  624. var
  625. l : longint;
  626. begin
  627. if InOutRes<>0 then
  628. begin
  629. l:=InOutRes;
  630. InOutRes:=0;
  631. HandleErrorFrame(l,get_frame);
  632. end;
  633. end;
  634. {$endif ndef FPC_SYSTEM_HAS_FPC_IOCHECK}
  635. {$endif}
  636. {
  637. $Log$
  638. Revision 1.8 2000-03-10 13:45:31 pierre
  639. * small fixes
  640. Revision 1.7 2000/02/09 16:59:29 peter
  641. * truncated log
  642. Revision 1.6 2000/01/10 09:54:30 peter
  643. * primitives added
  644. Revision 1.5 2000/01/07 16:41:34 daniel
  645. * copyright 2000
  646. Revision 1.4 2000/01/07 16:32:24 daniel
  647. * copyright 2000 added
  648. Revision 1.3 1999/12/21 11:12:16 pierre
  649. * some assembler functions translated to pascal
  650. WARNING these are not yet TESTED !!!
  651. + FPC_CHARARRAY_TO_SHORTSTRING added
  652. }