systemh.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team
  5. This File contains the OS independent declarations of the system unit
  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. Supported conditionnals:
  14. ------------------------
  15. RTLLITE Create a somewhat smaller RTL
  16. }
  17. {****************************************************************************
  18. Support for multiple compiler versions
  19. ****************************************************************************}
  20. {$i version.inc}
  21. {****************************************************************************
  22. Global Types and Constants
  23. ****************************************************************************}
  24. Type
  25. {$Q-}
  26. { $8000000 creates a longint overfow !! }
  27. Longint = $80000000..$7fffffff;
  28. Integer = -32768..32767;
  29. shortint = -128..127;
  30. byte = 0..255;
  31. Word = 0..65535;
  32. { at least declare Turbo Pascal real types }
  33. {$ifdef i386}
  34. StrLenInt = LongInt;
  35. {$define DEFAULT_EXTENDED}
  36. {$define SUPPORT_EXTENDED}
  37. {$define SUPPORT_COMP}
  38. {$define SUPPORT_SINGLE}
  39. {$define SUPPORT_FIXED}
  40. Double = real;
  41. {$ifdef DEFAULT_EXTENDED}
  42. ValReal = Extended;
  43. {$else}
  44. ValReal = Double;
  45. {$endif}
  46. {$endif}
  47. {$ifdef m68k}
  48. StrLenInt = Integer;
  49. ValReal = Real;
  50. {$ifdef USEANSISTRINGS}
  51. {$error StrLenInt must be a longint if ansi strings are used}
  52. {$endif}
  53. {$endif}
  54. { some type aliases }
  55. dword = cardinal;
  56. longword = cardinal;
  57. ShortString = String[255];
  58. { Zero - terminated strings }
  59. PChar = ^Char;
  60. PPChar = ^PChar;
  61. { procedure type }
  62. TProcedure = Procedure;
  63. const
  64. { max. values for longint and int}
  65. maxLongint = $7fffffff;
  66. maxint = 32767;
  67. { Compatibility With TP }
  68. {$ifdef i386}
  69. Test8086 : byte = 2; { Always i386 or newer }
  70. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  71. {$endif i386}
  72. {$ifdef m68k}
  73. Test68000 : byte = 0; { Must be determined at startup for both }
  74. Test68881 : byte = 0;
  75. {$endif}
  76. { max level in dumping on error }
  77. Max_Frame_Dump : Word = 8;
  78. { Exit Procedure handling consts and types }
  79. ExitProc : pointer = nil;
  80. Erroraddr: pointer = nil;
  81. Errorcode: Word = 0;
  82. { file input modes }
  83. fmClosed = $D7B0;
  84. fmInput = $D7B1;
  85. fmOutput = $D7B2;
  86. fmInOut = $D7B3;
  87. fmAppend = $D7B4;
  88. Filemode : byte = 2;
  89. Type
  90. TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  91. var
  92. { Standard In- and Output }
  93. Output,
  94. Input,
  95. StdErr : Text;
  96. ExitCode,
  97. InOutRes : Word;
  98. StackBottom,
  99. LowestStack,
  100. RandSeed : Longint;
  101. { Error handlers }
  102. ErrorProc : Pointer;
  103. {****************************************************************************
  104. Processor specific routines
  105. ****************************************************************************}
  106. Procedure Move(Var source,dest;count:Longint);
  107. Procedure FillChar(Var x;count:Longint;Value:Char);
  108. Procedure FillChar(Var x;count:Longint;Value:byte);
  109. {$ifndef RTLLITE}
  110. Procedure FillWord(Var x;count:Longint;Value:Word);
  111. {$endif RTLLITE}
  112. {****************************************************************************
  113. Math Routines
  114. ****************************************************************************}
  115. {$ifndef RTLLITE}
  116. Function lo(w:Word):byte;
  117. Function lo(l:Longint):Word;
  118. Function lo(i:Integer):byte;
  119. Function lo(B: Byte):Byte;
  120. Function hi(w:Word):byte;
  121. Function hi(i:Integer):byte;
  122. Function hi(l:Longint):Word;
  123. Function Hi(B : Byte): byte;
  124. Function Swap (X:Word):Word;
  125. Function Swap (X:Integer):Integer;
  126. Function Swap (X:Cardinal):Cardinal;
  127. Function Swap (X:Longint):Longint;
  128. {$endif RTLLITE}
  129. Function Chr(b:byte):Char;
  130. Function Length(s:string):byte;
  131. Function Random(l:Longint):Longint;
  132. Function Random:real;
  133. Procedure Randomize;
  134. Function abs(l:Longint):Longint;
  135. Function sqr(l:Longint):Longint;
  136. Function odd(l:Longint):Boolean;
  137. { float math routines }
  138. {$I mathh.inc}
  139. {****************************************************************************
  140. Addr/Pointer Handling
  141. ****************************************************************************}
  142. {$ifndef RTLLITE}
  143. Function ptr(sel,off:Longint):pointer;
  144. Function Addr (Var X):pointer;
  145. Function Cseg:Word;
  146. Function Dseg:Word;
  147. Function Sseg:Word;
  148. {$endif RTLLITE}
  149. {****************************************************************************
  150. PChar and String Handling
  151. ****************************************************************************}
  152. function strpas(p:pchar):string;
  153. function strlen(p:pchar):longint;
  154. Function Copy(const s:string;index:StrLenInt;count:StrLenInt):string;
  155. Procedure Delete(Var s:string;index:StrLenInt;count:StrLenInt);
  156. Procedure Insert(const source:string;Var s:string;index:StrLenInt);
  157. Function Pos(const substr:string;const s:string):byte;
  158. Function Pos(C:Char;const s:string):byte;
  159. Function upCase(c:Char):Char;
  160. Function upCase(const s:string):string;
  161. {$ifndef RTLLITE}
  162. Function lowerCase(c:Char):Char;
  163. Function lowerCase(const s:string):string;
  164. Function hexStr(Val:Longint;cnt:byte):string;
  165. Function binStr(Val:Longint;cnt:byte):string;
  166. {$endif RTLLITE}
  167. Function Space(b:byte):string;
  168. Procedure Val(const s:string;Var l:Longint;Var code:Word);
  169. Procedure Val(const s:string;Var l:Longint;Var code:Integer);
  170. Procedure Val(const s:string;Var l:Longint;Var code:Longint);
  171. Procedure Val(const s:string;Var l:Longint);
  172. Procedure Val(const s:string;Var b:byte;Var code:Word);
  173. Procedure Val(const s:string;Var b:byte;Var code:Integer);
  174. Procedure Val(const s:string;Var b:byte;Var code:Longint);
  175. Procedure Val(const s:string;Var b:byte);
  176. Procedure Val(const s:string;Var b:shortint;Var code:Word);
  177. Procedure Val(const s:string;Var b:shortint;Var code:Integer);
  178. Procedure Val(const s:string;Var b:shortint;Var code:Longint);
  179. Procedure Val(const s:string;Var b:shortint);
  180. Procedure Val(const s:string;Var b:Word;Var code:Word);
  181. Procedure Val(const s:string;Var b:Word;Var code:Integer);
  182. Procedure Val(const s:string;Var b:Word;Var code:Longint);
  183. Procedure Val(const s:string;Var b:Word);
  184. Procedure Val(const s:string;Var b:Integer;Var code:Word);
  185. Procedure Val(const s:string;Var b:Integer;Var code:Integer);
  186. Procedure Val(const s:string;Var b:Integer;Var code:Longint);
  187. Procedure Val(const s:string;Var b:Integer);
  188. Procedure Val(const s:string;Var v:cardinal;Var code:Word);
  189. Procedure Val(const s:string;Var v:cardinal;Var code:Integer);
  190. Procedure Val(const s:string;Var v:cardinal;Var code:Longint);
  191. Procedure Val(const s:string;Var v:cardinal);
  192. Procedure Val(const s:string;Var d:ValReal;Var code:Word);
  193. Procedure Val(const s:string;Var d:ValReal;Var code:Integer);
  194. Procedure Val(const s:string;Var d:ValReal;Var code:Longint);
  195. Procedure Val(const s:string;Var d:ValReal);
  196. {$ifdef SUPPORT_SINGLE}
  197. Procedure Val(const s:string;Var d:single;Var code:Word);
  198. Procedure Val(const s:string;Var d:single;Var code:Integer);
  199. Procedure Val(const s:string;Var d:single;Var code:Longint);
  200. Procedure Val(const s:string;Var d:single);
  201. {$endif SUPPORT_SINGLE}
  202. {$ifdef SUPPORT_COMP}
  203. Procedure Val(const s:string;Var d:comp;Var code:Word);
  204. Procedure Val(const s:string;Var d:comp;Var code:Integer);
  205. Procedure Val(const s:string;Var d:comp;Var code:Longint);
  206. Procedure Val(const s:string;Var d:comp);
  207. {$endif SUPPORT_COMP}
  208. {$ifdef SUPPORT_FIXED}
  209. Procedure Val(const s:string;Var d:fixed;Var code:Word);
  210. Procedure Val(const s:string;Var d:fixed;Var code:Integer);
  211. Procedure Val(const s:string;Var d:fixed;Var code:Longint);
  212. Procedure Val(const s:string;Var d:fixed);
  213. {$endif SUPPORT_FIXED}
  214. {$ifdef DEFAULT_EXTENDED}
  215. Procedure Val(const s:string;Var d:Real;Var code:Word);
  216. Procedure Val(const s:string;Var d:Real;Var code:Integer);
  217. Procedure Val(const s:string;Var d:Real;Var code:Longint);
  218. Procedure Val(const s:string;Var d:Real);
  219. {$else DEFAULT_EXTENDED}
  220. {$ifdef SUPPORT_EXTENDED}
  221. Procedure Val(const s:string;Var d:Extended;Var code:Word);
  222. Procedure Val(const s:string;Var d:Extended;Var code:Integer);
  223. Procedure Val(const s:string;Var d:Extended;Var code:Longint);
  224. Procedure Val(const s:string;Var d:Extended);
  225. {$endif}
  226. {$endif DEFAULT_EXTENDED}
  227. {****************************************************************************
  228. AnsiString Handling
  229. ****************************************************************************}
  230. {$ifdef UseAnsiStrings }
  231. Procedure SetLength (Var S : AnsiString; l : Longint);
  232. Procedure UniqueAnsiString (Var S : AnsiString);
  233. Function Length (Const S : AnsiString) : Longint;
  234. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  235. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  236. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  237. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  238. Procedure Val (Const S : AnsiString; var R : real; Var Code : Integer);
  239. {
  240. Procedure Val (Const S : AnsiString; var D : Double; Var Code : Integer);
  241. }
  242. Procedure Val (Const S : AnsiString; var E : Extended; Code : Integer);
  243. Procedure Val (Const S : AnsiString; var C : Cardinal; Code : Integer);
  244. Procedure Val (Const S : AnsiString; var L : Longint; Var Code : Integer);
  245. Procedure Val (Const S : AnsiString; var W : Word; Var Code : Integer);
  246. Procedure Val (Const S : AnsiString; var I : Integer; Var Code : Integer);
  247. Procedure Val (Const S : AnsiString; var B : Byte; Var Code : Integer);
  248. Procedure Val (Const S : AnsiString; var SI : ShortInt; Var Code : Integer);
  249. {
  250. Procedure Str (Const R : Real;Len, fr : longint; Var S : AnsiString);
  251. Procedure Str (Const D : Double;Len,fr : longint; Var S : AnsiString);
  252. Procedure Str (Const E : Extended;Len,fr : longint; Var S : AnsiString);
  253. Procedure Str (Const C : Cardinal;len : Longint; Var S : AnsiString);
  254. Procedure Str (Const L : LongInt;len : longint; Var S : AnsiString);
  255. Procedure Str (Const W : Word;len : longint; Var S : AnsiString);
  256. Procedure Str (Const I : Integer;len : Longint; Var S : AnsiString);
  257. Procedure Str (Const B : Byte; Len : longint; Var S : AnsiString);
  258. Procedure Str (Const SI : ShortInt; Len : longint; Var S : AnsiString);
  259. }
  260. {$endif}
  261. {****************************************************************************
  262. Untyped File Management
  263. ****************************************************************************}
  264. Procedure Assign(Var f:File;const Name:string);
  265. Procedure Assign(Var f:File;p:pchar);
  266. Procedure Assign(Var f:File;c:char);
  267. Procedure Rewrite(Var f:File;l:Longint);
  268. Procedure Rewrite(Var f:File);
  269. Procedure Reset(Var f:File;l:Longint);
  270. Procedure Reset(Var f:File);
  271. Procedure Close(Var f:File);
  272. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  273. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  274. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  275. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  276. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  277. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  278. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  279. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  280. Function FilePos(Var f:File):Longint;
  281. Function FileSize(Var f:File):Longint;
  282. Procedure Seek(Var f:File;Pos:Longint);
  283. Function EOF(Var f:File):Boolean;
  284. Procedure Erase(Var f:File);
  285. Procedure Rename(Var f:File;const s:string);
  286. Procedure Rename(Var f:File;p:pchar);
  287. Procedure Rename(Var f:File;c:char);
  288. Procedure Truncate (Var F:File);
  289. {****************************************************************************
  290. Typed File Management
  291. ****************************************************************************}
  292. Procedure Assign(Var f:TypedFile;const Name:string);
  293. Procedure Assign(Var f:TypedFile;p:pchar);
  294. Procedure Assign(Var f:TypedFile;c:char);
  295. Procedure Rewrite(Var f:TypedFile);
  296. Procedure Reset(Var f:TypedFile);
  297. {****************************************************************************
  298. Text File Management
  299. ****************************************************************************}
  300. Procedure Assign(Var t:Text;const s:string);
  301. Procedure Assign(Var t:Text;p:pchar);
  302. Procedure Assign(Var t:Text;c:char);
  303. Procedure Close(Var t:Text);
  304. Procedure Rewrite(Var t:Text);
  305. Procedure Reset(Var t:Text);
  306. Procedure Append(Var t:Text);
  307. Procedure Flush(Var t:Text);
  308. Procedure Erase(Var t:Text);
  309. Procedure Rename(Var t:Text;const s:string);
  310. Procedure Rename(Var t:Text;p:pchar);
  311. Procedure Rename(Var t:Text;c:char);
  312. Function EOF(Var t:Text):Boolean;
  313. Function EOF:Boolean;
  314. Function EOLn(Var t:Text):Boolean;
  315. Function EOLn:Boolean;
  316. Function SeekEOLn (Var t:Text):Boolean;
  317. Function SeekEOF (Var t:Text):Boolean;
  318. Function SeekEOLn:Boolean;
  319. Function SeekEOF:Boolean;
  320. Procedure SetTextBuf(Var f:Text; Var Buf);
  321. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Word);
  322. {****************************************************************************
  323. Directory Management
  324. ****************************************************************************}
  325. Procedure chdir(const s:string);
  326. Procedure mkdir(const s:string);
  327. Procedure rmdir(const s:string);
  328. Procedure getdir(drivenr:byte;Var dir:string);
  329. {*****************************************************************************
  330. Miscelleaous
  331. *****************************************************************************}
  332. { os independent calls to allow backtraces }
  333. function get_frame:longint;
  334. function get_caller_addr(framebp:longint):longint;
  335. function get_caller_frame(framebp:longint):longint;
  336. Function IOResult:Word;
  337. Function Sptr:Longint;
  338. {*****************************************************************************
  339. Init / Exit / ExitProc
  340. *****************************************************************************}
  341. Function Paramcount:Longint;
  342. Function ParamStr(l:Longint):string;
  343. {$ifndef RTLLITE}
  344. Procedure Dump_Stack(bp:Longint);
  345. {$endif RTLLITE}
  346. Procedure RunError(w:Word);
  347. Procedure RunError;
  348. Procedure halt(errnum:byte);
  349. {$ifndef RTLLITE}
  350. Procedure AddExitProc(Proc:TProcedure);
  351. {$endif RTLLITE}
  352. Procedure halt;
  353. {*****************************************************************************
  354. Abstract/Assert
  355. *****************************************************************************}
  356. procedure AbstractError;
  357. Procedure SysAssert(Const Msg,FName:string;LineNo,ErrorAddr:Longint);
  358. const
  359. AssertErrorProc : Pointer=@SysAssert;
  360. AbstractErrorProc : Pointer=nil;
  361. {*****************************************************************************
  362. SetJmp/LongJmp
  363. *****************************************************************************}
  364. {$i setjumph.inc}
  365. {
  366. $Log$
  367. Revision 1.37 1998-10-10 15:28:47 peter
  368. + read single,fixed
  369. + val with code:longint
  370. + val for fixed
  371. Revision 1.36 1998/10/05 17:22:54 pierre
  372. * avoid overflow on $8000000 with $Q-
  373. Revision 1.35 1998/10/05 12:32:52 peter
  374. + assert() support
  375. Revision 1.34 1998/10/01 14:54:48 peter
  376. * export also stackframe functions
  377. Revision 1.33 1998/09/28 14:02:33 michael
  378. + AnsiString changes
  379. Revision 1.32 1998/09/22 15:30:55 peter
  380. * shortstring=string type added
  381. Revision 1.31 1998/09/20 17:49:09 florian
  382. * some ansistring fixes
  383. Revision 1.30 1998/09/17 16:34:17 peter
  384. * new eof,eoln,seekeoln,seekeof
  385. * speed upgrade for read_string
  386. * inoutres 104/105 updates for read_* and write_*
  387. Revision 1.29 1998/09/16 13:08:04 michael
  388. Added AbstractErrorHandler
  389. Revision 1.28 1998/09/14 10:48:22 peter
  390. * FPC_ names
  391. * Heap manager is now system independent
  392. Revision 1.27 1998/09/08 15:03:28 peter
  393. * moved getmem/freemem/memavail/maxavail to heaph.inc
  394. Revision 1.26 1998/09/04 18:16:14 peter
  395. * uniform filerec/textrec (with recsize:longint and name:0..255)
  396. Revision 1.25 1998/09/01 17:36:22 peter
  397. + internconst
  398. Revision 1.24 1998/08/11 21:39:08 peter
  399. * splitted default_extended from support_extended
  400. Revision 1.23 1998/08/11 00:05:27 peter
  401. * $ifdef ver0_99_5 updates
  402. Revision 1.22 1998/08/08 12:28:14 florian
  403. * a lot small fixes to the extended data type work
  404. Revision 1.21 1998/07/30 13:26:17 michael
  405. + Added support for ErrorProc variable. All internal functions are required
  406. to call HandleError instead of runerror from now on.
  407. This is necessary for exception support.
  408. Revision 1.20 1998/07/28 20:37:47 michael
  409. + added setjmp/longjmp and exception support
  410. Revision 1.19 1998/07/20 23:36:57 michael
  411. changes for ansistrings
  412. Revision 1.18 1998/07/18 17:14:24 florian
  413. * strlenint type implemented
  414. Revision 1.17 1998/07/10 11:02:39 peter
  415. * support_fixed, becuase fixed is not 100% yet for the m68k
  416. Revision 1.16 1998/07/02 12:13:18 carl
  417. * No SINGLE type for m68k or other non-intel processors!
  418. Revision 1.15 1998/07/01 14:43:46 carl
  419. - max_frame_dump reduced to 8, 20 is too much!
  420. Revision 1.14 1998/06/25 14:04:26 peter
  421. + internal inc/dec
  422. Revision 1.13 1998/06/25 09:44:21 daniel
  423. + RTLLITE directive to compile minimal RTL.
  424. Revision 1.12 1998/06/15 15:16:27 daniel
  425. * RTLLITE conditional added to produce smaller RTL
  426. Revision 1.11 1998/06/08 12:38:23 michael
  427. Implemented rtti, inserted ansistrings again
  428. Revision 1.10 1998/06/04 23:46:02 peter
  429. * comp,extended are only i386 added support_comp,support_extended
  430. Revision 1.9 1998/06/04 08:26:03 pierre
  431. * boolean internal definition again (needed to compile
  432. older RTL's)
  433. Revision 1.8 1998/06/03 23:39:53 peter
  434. + boolean=bytebool
  435. Revision 1.7 1998/05/22 12:34:11 peter
  436. * fixed the optimizes of daniel
  437. Revision 1.6 1998/05/21 19:31:00 peter
  438. * objects compiles for linux
  439. + assign(pchar), assign(char), rename(pchar), rename(char)
  440. * fixed read_text_as_array
  441. + read_text_as_pchar which was not yet in the rtl
  442. Revision 1.5 1998/05/12 10:42:45 peter
  443. * moved getopts to inc/, all supported OS's need argc,argv exported
  444. + strpas, strlen are now exported in the systemunit
  445. * removed logs
  446. * removed $ifdef ver_above
  447. Revision 1.4 1998/04/16 12:30:47 peter
  448. + inc(pchar), dec(pchar), incc(pchar,a),dec(pchar,a)
  449. }