systemh.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. 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. Needed switches
  19. ****************************************************************************}
  20. {$I-,Q-,H-,R-,V-}
  21. {$mode objfpc}
  22. { needed for insert,delete,readln }
  23. {$P+}
  24. { Stack check gives a note under linux }
  25. {$ifndef linux}
  26. {$S-}
  27. {$endif}
  28. {****************************************************************************
  29. Global Types and Constants
  30. ****************************************************************************}
  31. Type
  32. shortint = -128..127;
  33. SmallInt = -32768..32767;
  34. Longint = $80000000..$7fffffff; { $8000000 creates a longint overfow !! }
  35. byte = 0..255;
  36. Word = 0..65535;
  37. dword = cardinal;
  38. longword = cardinal;
  39. { at least declare Turbo Pascal real types }
  40. {$ifdef i386}
  41. StrLenInt = LongInt;
  42. {$define DEFAULT_EXTENDED}
  43. {$define SUPPORT_SINGLE}
  44. {$define SUPPORT_DOUBLE}
  45. {$define SUPPORT_EXTENDED}
  46. {$define SUPPORT_COMP}
  47. { define SUPPORT_FIXED}
  48. ValSInt = Longint;
  49. ValUInt = Cardinal;
  50. ValReal = Extended;
  51. {$endif}
  52. {$ifdef m68k}
  53. StrLenInt = Longint;
  54. ValSInt = Longint;
  55. ValUInt = Cardinal;
  56. ValReal = Real;
  57. {$define SUPPORT_SINGLE}
  58. {$endif}
  59. { Zero - terminated strings }
  60. PChar = ^Char;
  61. PPChar = ^PChar;
  62. { Delphi types }
  63. TAnsiChar = Char;
  64. AnsiChar = TAnsiChar;
  65. PAnsiChar = PChar;
  66. {$ifdef HASWIDECHAR}
  67. PWideChar = ^WideChar;
  68. {$endif HASWIDECHAR}
  69. { procedure type }
  70. TProcedure = Procedure;
  71. const
  72. { Maximum value of the biggest signed and unsigned integer type available}
  73. MaxSIntValue = High(ValSInt);
  74. MaxUIntValue = High(ValUInt);
  75. { max. values for longint and int}
  76. maxLongint = $7fffffff;
  77. maxSmallint = 32767;
  78. { Integer type definition }
  79. type
  80. Integer = smallint;
  81. const
  82. maxint = maxsmallint;
  83. { Compatibility With TP }
  84. const
  85. {$ifdef i386}
  86. Test8086 : byte = 2; { Always i386 or newer }
  87. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  88. { code to use comps in int64mul and div code is commented out! (JM) }
  89. FPUInt64 : boolean = false; { set this to false if you don't want that }
  90. { the fpu does int64*int64 and }
  91. { int64 div int64, if the * is overflow }
  92. { checked, it is done in software }
  93. {$endif i386}
  94. {$ifdef m68k}
  95. Test68000 : byte = 0; { Must be determined at startup for both }
  96. Test68881 : byte = 0;
  97. {$endif}
  98. { max level in dumping on error }
  99. Max_Frame_Dump : Word = 8;
  100. { Exit Procedure handling consts and types }
  101. ExitProc : pointer = nil;
  102. Erroraddr: pointer = nil;
  103. Errorcode: Word = 0;
  104. { file input modes }
  105. fmClosed = $D7B0;
  106. fmInput = $D7B1;
  107. fmOutput = $D7B2;
  108. fmInOut = $D7B3;
  109. fmAppend = $D7B4;
  110. Filemode : byte = 2;
  111. CmdLine : PChar = nil;
  112. var
  113. { Standard In- and Output }
  114. Output,
  115. Input,
  116. StdOut,
  117. StdErr : Text;
  118. ExitCode,
  119. InOutRes : Word;
  120. StackBottom,
  121. LowestStack,
  122. RandSeed : Cardinal;
  123. {****************************************************************************
  124. Processor specific routines
  125. ****************************************************************************}
  126. Procedure Move(Var source,dest;count:Longint);
  127. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  128. Procedure FillChar(Var x;count:Longint;Value:Char);
  129. Procedure FillChar(Var x;count:Longint;Value:Byte);
  130. {$ifndef RTLLITE}
  131. procedure FillByte(var x;count:longint;value:byte);
  132. Procedure FillWord(Var x;count:Longint;Value:Word);
  133. procedure FillDWord(var x;count:longint;value:DWord);
  134. function IndexChar(var buf;len:longint;b:char):longint;
  135. function IndexByte(var buf;len:longint;b:byte):longint;
  136. function Indexword(var buf;len:longint;b:word):longint;
  137. function IndexDWord(var buf;len:longint;b:DWord):longint;
  138. function CompareChar(var buf1,buf2;len:longint):longint;
  139. function CompareByte(var buf1,buf2;len:longint):longint;
  140. function CompareWord(var buf1,buf2;len:longint):longint;
  141. function CompareDWord(var buf1,buf2;len:longint):longint;
  142. procedure MoveChar0(var buf1,buf2;len:longint);
  143. function IndexChar0(var buf;len:longint;b:char):longint;
  144. function CompareChar0(var buf1,buf2;len:longint):longint;
  145. {$endif}
  146. {****************************************************************************
  147. Math Routines
  148. ****************************************************************************}
  149. {$ifndef RTLLITE}
  150. Function lo(w:Word):byte;
  151. Function lo(l:Longint):Word;
  152. Function lo(l:DWord):Word;
  153. Function lo(i:Integer):byte;
  154. Function lo(B: Byte):Byte;
  155. Function hi(w:Word):byte;
  156. Function hi(i:Integer):byte;
  157. Function hi(l:Longint):Word;
  158. Function hi(b : Byte) : Byte;
  159. Function hi(l: DWord): Word;
  160. Function Swap (X:Word):Word;
  161. Function Swap (X:Integer):Integer;
  162. Function Swap (X:Cardinal):Cardinal;
  163. Function Swap (X:LongInt):LongInt;
  164. {$ifdef INT64}
  165. Function lo(q : QWord) : DWord;
  166. Function lo(i : Int64) : DWord;
  167. Function hi(q : QWord) : DWord;
  168. Function hi(i : Int64) : DWord;
  169. Function Swap (X:QWord):QWord;
  170. Function Swap (X:Int64):Int64;
  171. {$endif}
  172. {$endif RTLLITE}
  173. Function Random(l:cardinal):cardinal;
  174. {$ifndef cardinalmulfixed}
  175. Function Random(l:longint):longint;
  176. {$endif cardinalmulfixed}
  177. Function Random: extended;
  178. Procedure Randomize;
  179. Function abs(l:Longint):Longint;
  180. Function sqr(l:Longint):Longint;
  181. Function odd(l:Longint):Boolean;
  182. { float math routines }
  183. {$I mathh.inc}
  184. {****************************************************************************
  185. Addr/Pointer Handling
  186. ****************************************************************************}
  187. {$ifndef RTLLITE}
  188. Function ptr(sel,off:Longint):pointer;
  189. Function Cseg:Word;
  190. Function Dseg:Word;
  191. Function Sseg:Word;
  192. {$endif RTLLITE}
  193. {****************************************************************************
  194. PChar and String Handling
  195. ****************************************************************************}
  196. function strpas(p:pchar):shortstring;
  197. function strlen(p:pchar):longint;
  198. { Shortstring functions }
  199. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  200. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  201. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  202. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  203. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  204. Function Pos(C:Char;const s:shortstring):StrLenInt;
  205. Procedure SetLength(var s:shortstring;len:StrLenInt);
  206. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  207. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  208. Function Length(s:string):byte;
  209. Function upCase(const s:shortstring):shortstring;
  210. {$ifndef RTLLITE}
  211. Function lowerCase(const s:shortstring):shortstring;
  212. {$endif}
  213. Function Space(b:byte):shortstring;
  214. {$ifndef RTLLITE}
  215. Function hexStr(Val:Longint;cnt:byte):shortstring;
  216. Function binStr(Val:Longint;cnt:byte):shortstring;
  217. {$endif RTLLITE}
  218. { Char functions }
  219. Function Chr(b:byte):Char;
  220. Function upCase(c:Char):Char;
  221. {$ifndef RTLLITE}
  222. Function lowerCase(c:Char):Char;
  223. {$endif RTLLITE}
  224. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  225. function pos(const substr : shortstring;c:char): StrLenInt;
  226. function length(c:char):byte;
  227. {****************************************************************************
  228. AnsiString Handling
  229. ****************************************************************************}
  230. Procedure SetLength (Var S : AnsiString; l : Longint);
  231. Procedure UniqueAnsiString (Var S : AnsiString);
  232. Function Length (Const S : AnsiString) : Longint;
  233. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  234. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  235. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  236. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  237. Function StringOfChar(c : char;l : longint) : AnsiString;
  238. {****************************************************************************
  239. Untyped File Management
  240. ****************************************************************************}
  241. Procedure Assign(Var f:File;const Name:string);
  242. Procedure Assign(Var f:File;p:pchar);
  243. Procedure Assign(Var f:File;c:char);
  244. Procedure Rewrite(Var f:File;l:Longint);
  245. Procedure Rewrite(Var f:File);
  246. Procedure Reset(Var f:File;l:Longint);
  247. Procedure Reset(Var f:File);
  248. Procedure Close(Var f:File);
  249. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  250. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  251. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  252. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  253. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  254. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  255. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  256. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  257. Function FilePos(Var f:File):Longint;
  258. Function FileSize(Var f:File):Longint;
  259. Procedure Seek(Var f:File;Pos:Longint);
  260. Function EOF(Var f:File):Boolean;
  261. Procedure Erase(Var f:File);
  262. Procedure Rename(Var f:File;const s:string);
  263. Procedure Rename(Var f:File;p:pchar);
  264. Procedure Rename(Var f:File;c:char);
  265. Procedure Truncate (Var F:File);
  266. {****************************************************************************
  267. Typed File Management
  268. ****************************************************************************}
  269. Procedure Assign(Var f:TypedFile;const Name:string);
  270. Procedure Assign(Var f:TypedFile;p:pchar);
  271. Procedure Assign(Var f:TypedFile;c:char);
  272. Procedure Rewrite(Var f:TypedFile);
  273. Procedure Reset(Var f:TypedFile);
  274. {****************************************************************************
  275. Text File Management
  276. ****************************************************************************}
  277. Procedure Assign(Var t:Text;const s:string);
  278. Procedure Assign(Var t:Text;p:pchar);
  279. Procedure Assign(Var t:Text;c:char);
  280. Procedure Close(Var t:Text);
  281. Procedure Rewrite(Var t:Text);
  282. Procedure Reset(Var t:Text);
  283. Procedure Append(Var t:Text);
  284. Procedure Flush(Var t:Text);
  285. Procedure Erase(Var t:Text);
  286. Procedure Rename(Var t:Text;const s:string);
  287. Procedure Rename(Var t:Text;p:pchar);
  288. Procedure Rename(Var t:Text;c:char);
  289. Function EOF(Var t:Text):Boolean;
  290. Function EOF:Boolean;
  291. Function EOLn(Var t:Text):Boolean;
  292. Function EOLn:Boolean;
  293. Function SeekEOLn (Var t:Text):Boolean;
  294. Function SeekEOF (Var t:Text):Boolean;
  295. Function SeekEOLn:Boolean;
  296. Function SeekEOF:Boolean;
  297. Procedure SetTextBuf(Var f:Text; Var Buf);
  298. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  299. {****************************************************************************
  300. Directory Management
  301. ****************************************************************************}
  302. Procedure chdir(const s:string);
  303. Procedure mkdir(const s:string);
  304. Procedure rmdir(const s:string);
  305. Procedure getdir(drivenr:byte;Var dir:shortstring);
  306. Procedure getdir(drivenr:byte;Var dir:ansistring);
  307. {*****************************************************************************
  308. Miscelleaous
  309. *****************************************************************************}
  310. { os independent calls to allow backtraces }
  311. function get_frame:longint;
  312. function get_caller_addr(framebp:longint):longint;
  313. function get_caller_frame(framebp:longint):longint;
  314. Function IOResult:Word;
  315. Function Sptr:Longint;
  316. {*****************************************************************************
  317. Init / Exit / ExitProc
  318. *****************************************************************************}
  319. Function Paramcount:Longint;
  320. Function ParamStr(l:Longint):string;
  321. {$ifndef RTLLITE}
  322. Procedure Dump_Stack(var f : text;bp:Longint);
  323. {$endif RTLLITE}
  324. Procedure RunError(w:Word);
  325. Procedure RunError;
  326. Procedure halt(errnum:byte);
  327. {$ifndef RTLLITE}
  328. Procedure AddExitProc(Proc:TProcedure);
  329. {$endif RTLLITE}
  330. Procedure halt;
  331. {*****************************************************************************
  332. Abstract/Assert/Error Handling
  333. *****************************************************************************}
  334. procedure AbstractError;
  335. Function SysBackTraceStr(Addr: Longint): ShortString;
  336. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  337. { Error handlers }
  338. Type
  339. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  340. TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  341. TAbstractErrorProc = Procedure;
  342. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  343. const
  344. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  345. ErrorProc : TErrorProc = nil;
  346. AbstractErrorProc : TAbstractErrorProc = nil;
  347. AssertErrorProc : TAssertErrorProc = @SysAssert;
  348. {*****************************************************************************
  349. SetJmp/LongJmp
  350. *****************************************************************************}
  351. {$i setjumph.inc}
  352. {*****************************************************************************
  353. Object Pascal support
  354. *****************************************************************************}
  355. {$i objpash.inc}
  356. {
  357. $Log$
  358. Revision 1.79 2000-03-14 10:20:18 michael
  359. + Added constants and types for Delphi compatibility
  360. Revision 1.78 2000/02/09 16:59:31 peter
  361. * truncated log
  362. Revision 1.77 2000/02/06 17:19:22 peter
  363. * lineinfo unit added which uses stabs to get lineinfo for backtraces
  364. Revision 1.76 2000/01/21 15:32:07 jonas
  365. * set FPUInt64 to false for i386, because comp mul and div code for int64 is
  366. commented out in int64.inc
  367. Revision 1.75 2000/01/10 09:54:30 peter
  368. * primitives added
  369. Revision 1.74 2000/01/07 16:41:36 daniel
  370. * copyright 2000
  371. Revision 1.73 2000/01/07 16:32:25 daniel
  372. * copyright 2000 added
  373. Revision 1.72 1999/12/20 11:20:14 peter
  374. + smallint, maxsmallint
  375. * integer is redefined as smallint
  376. Revision 1.71 1999/12/18 14:55:05 florian
  377. * very basic widestring support
  378. Revision 1.70 1999/12/12 13:29:34 jonas
  379. * remove "random(longint): longint" if cardinalmulfixed is defined
  380. Revision 1.69 1999/12/01 12:37:13 jonas
  381. + function random(longint): longint
  382. Revision 1.68 1999/11/25 13:34:57 michael
  383. + Added Ansistring setstring call
  384. Revision 1.67 1999/11/20 12:48:09 jonas
  385. * reinstated old random generator, but modified it so the integer
  386. one now has a much longer period
  387. Revision 1.66 1999/11/09 20:14:12 daniel
  388. * Committed new random generator.
  389. Revision 1.65 1999/11/06 14:35:39 peter
  390. * truncated log
  391. Revision 1.64 1999/10/27 14:19:10 florian
  392. + StringOfChar
  393. Revision 1.63 1999/10/26 12:31:00 peter
  394. * *errorproc are not procvars instead of pointers which allows better
  395. error checking for the parameters (shortstring<->ansistring)
  396. Revision 1.62 1999/08/19 11:16:13 peter
  397. * settextbuf size is now longint
  398. }