systemh.inc 17 KB

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