systemh.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. Needed switches
  14. ****************************************************************************}
  15. {$I-,Q-,H-,R-,V-}
  16. {$mode objfpc}
  17. { don't use FPU registervariables on the i386 }
  18. {$ifdef i386}
  19. {$maxfpuregisters 0}
  20. {$endif i386}
  21. { needed for insert,delete,readln }
  22. {$P+}
  23. { Stack check gives a note under linux }
  24. {$ifndef unix}
  25. {$S-}
  26. {$endif}
  27. {****************************************************************************
  28. Global Types and Constants
  29. ****************************************************************************}
  30. Type
  31. ShortInt = -128..127;
  32. SmallInt = -32768..32767;
  33. { can't use -2147483648 because of a bug in 1.0.2's val() procedure (JM) }
  34. Longint = +(-2147483647-1)..$7fffffff;
  35. Byte = 0..255;
  36. Word = 0..65535;
  37. DWord = Cardinal;
  38. LongWord = Cardinal;
  39. Integer = SmallInt;
  40. { at least declare Turbo Pascal real types }
  41. {$ifdef i386}
  42. StrLenInt = LongInt;
  43. {$define DEFAULT_EXTENDED}
  44. {$define SUPPORT_SINGLE}
  45. {$define SUPPORT_DOUBLE}
  46. {$define SUPPORT_EXTENDED}
  47. {$define SUPPORT_COMP}
  48. { define SUPPORT_FIXED}
  49. ValSInt = Longint;
  50. ValUInt = Cardinal;
  51. ValReal = Extended;
  52. {$endif}
  53. {$ifdef m68k}
  54. StrLenInt = Longint;
  55. ValSInt = Longint;
  56. ValUInt = Cardinal;
  57. ValReal = Real;
  58. {$define SUPPORT_SINGLE}
  59. {$endif}
  60. { Zero - terminated strings }
  61. PChar = ^Char;
  62. PPChar = ^PChar;
  63. TAnsiChar = Char;
  64. AnsiChar = TAnsiChar;
  65. PAnsiChar = ^TAnsiChar;
  66. PPAnsiChar = ^PAnsiChar;
  67. UCS4Char = Cardinal;
  68. PUCS4Char = ^UCS4Char;
  69. Currency = Int64;
  70. HRESULT = Longint;
  71. TDateTime = Double;
  72. Error = Longint;
  73. PSingle = ^Single;
  74. PDouble = ^Double;
  75. PCurrency = ^Currency;
  76. {$ifdef SUPPORT_COMP}
  77. PComp = ^Comp;
  78. {$endif SUPPORT_COMP}
  79. {$ifdef SUPPORT_EXTENDED}
  80. PExtended = ^Extended;
  81. {$endif SUPPORT_EXTENDED}
  82. PSmallInt = ^Smallint;
  83. PInteger = ^Longint;
  84. PByte = ^Byte;
  85. PWord = ^word;
  86. PDWord = ^DWord;
  87. PLongWord = ^LongWord;
  88. PLongint = ^Longint;
  89. PCardinal = ^Cardinal;
  90. PQWord = ^QWord;
  91. PInt64 = ^Int64;
  92. PPointer = ^Pointer;
  93. PPPointer = ^PPointer;
  94. PBoolean = ^Boolean;
  95. PWordBool = ^WordBool;
  96. PLongBool = ^LongBool;
  97. PShortString = ^ShortString;
  98. PAnsiString = ^AnsiString;
  99. PDate = ^TDateTime;
  100. PError = ^Error;
  101. {$ifdef HASVARIANT}
  102. PVariant = ^Variant;
  103. {$endif HASVARIANT}
  104. {$ifdef HASWIDECHAR}
  105. PWideChar = ^WideChar;
  106. PPWideChar = ^PWideChar;
  107. PWideString = ^WideString;
  108. {$endif HASWIDECHAR}
  109. TTextLineBreakStyle = (tlbsLF,tlbsCRLF,tlbsCR);
  110. { procedure type }
  111. TProcedure = Procedure;
  112. const
  113. { Maximum value of the biggest signed and unsigned integer type available}
  114. MaxSIntValue = High(ValSInt);
  115. MaxUIntValue = High(ValUInt);
  116. { max. values for longint and int}
  117. maxLongint = $7fffffff;
  118. maxSmallint = 32767;
  119. const
  120. maxint = maxsmallint;
  121. { Compatibility With TP }
  122. const
  123. { code to use comps in int64mul and div code is commented out! (JM) }
  124. FPUInt64 : boolean = false; { set this to false if you don't want that }
  125. { the fpu does int64*int64 and }
  126. { int64 div int64, if the * is overflow }
  127. { checked, it is done in software }
  128. {$ifdef i386}
  129. Test8086 : byte = 2; { Always i386 or newer }
  130. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  131. {$endif i386}
  132. {$ifdef m68k}
  133. Test68000 : byte = 0; { Must be determined at startup for both }
  134. Test68881 : byte = 0;
  135. {$endif}
  136. { max level in dumping on error }
  137. Max_Frame_Dump : Word = 8;
  138. { Exit Procedure handling consts and types }
  139. ExitProc : pointer = nil;
  140. Erroraddr: pointer = nil;
  141. Errorcode: Word = 0;
  142. { file input modes }
  143. fmClosed = $D7B0;
  144. fmInput = $D7B1;
  145. fmOutput = $D7B2;
  146. fmInOut = $D7B3;
  147. fmAppend = $D7B4;
  148. Filemode : byte = 2;
  149. CmdLine : PChar = nil;
  150. var
  151. { Standard In- and Output }
  152. Output,
  153. Input,
  154. StdOut,
  155. StdErr : Text;
  156. ExitCode : Word;
  157. StackBottom,
  158. LowestStack,
  159. RandSeed : Cardinal;
  160. { Delphi compatible }
  161. IsLibrary,IsMultiThreaded,IsConsole : boolean;
  162. {$ifdef MT}
  163. ThreadVar
  164. {$else MT}
  165. Var
  166. {$endif MT}
  167. InOutRes : Word;
  168. {****************************************************************************
  169. Processor specific routines
  170. ****************************************************************************}
  171. Procedure Move(const source;var dest;count:Longint);
  172. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  173. Procedure FillChar(Var x;count:Longint;Value:Char);
  174. Procedure FillChar(Var x;count:Longint;Value:Byte);
  175. procedure FillByte(var x;count:longint;value:byte);
  176. Procedure FillWord(Var x;count:Longint;Value:Word);
  177. procedure FillDWord(var x;count:longint;value:DWord);
  178. function IndexChar(var buf;len:longint;b:char):longint;
  179. function IndexByte(var buf;len:longint;b:byte):longint;
  180. function Indexword(var buf;len:longint;b:word):longint;
  181. function IndexDWord(var buf;len:longint;b:DWord):longint;
  182. function CompareChar(var buf1,buf2;len:longint):longint;
  183. function CompareByte(var buf1,buf2;len:longint):longint;
  184. function CompareWord(var buf1,buf2;len:longint):longint;
  185. function CompareDWord(var buf1,buf2;len:longint):longint;
  186. procedure MoveChar0(var buf1,buf2;len:longint);
  187. function IndexChar0(var buf;len:longint;b:char):longint;
  188. function CompareChar0(var buf1,buf2;len:longint):longint;
  189. {****************************************************************************
  190. Math Routines
  191. ****************************************************************************}
  192. Function lo(w:Word):byte;
  193. Function lo(l:Longint):Word;
  194. Function lo(l:DWord):Word;
  195. Function lo(i:Integer):byte;
  196. Function lo(B: Byte):Byte;
  197. Function hi(w:Word):byte;
  198. Function hi(i:Integer):byte;
  199. Function hi(l:Longint):Word;
  200. Function hi(b : Byte) : Byte;
  201. Function hi(l: DWord): Word;
  202. Function Swap (X:Word):Word;
  203. Function Swap (X:Integer):Integer;
  204. Function Swap (X:Cardinal):Cardinal;
  205. Function Swap (X:LongInt):LongInt;
  206. Function lo(q : QWord) : DWord;
  207. Function lo(i : Int64) : DWord;
  208. Function hi(q : QWord) : DWord;
  209. Function hi(i : Int64) : DWord;
  210. Function Swap (X:QWord):QWord;
  211. Function Swap (X:Int64):Int64;
  212. Function Random(l:cardinal):cardinal;
  213. Function Random(l:longint):longint;
  214. Function Random: extended;
  215. Procedure Randomize;
  216. Function abs(l:Longint):Longint;
  217. Function sqr(l:Longint):Longint;
  218. Function odd(l:Longint):Boolean;
  219. Function odd(l:Cardinal):Boolean;
  220. Function odd(l:Int64):Boolean;
  221. Function odd(l:QWord):Boolean;
  222. { float math routines }
  223. {$I mathh.inc}
  224. {****************************************************************************
  225. Addr/Pointer Handling
  226. ****************************************************************************}
  227. Function ptr(sel,off:Longint):farpointer;
  228. Function Cseg:Word;
  229. Function Dseg:Word;
  230. Function Sseg:Word;
  231. {****************************************************************************
  232. PChar and String Handling
  233. ****************************************************************************}
  234. function strpas(p:pchar):shortstring;
  235. function strlen(p:pchar):longint;
  236. { Shortstring functions }
  237. {$ifndef INTERNSETLENGTH}
  238. Procedure SetLength (Var S:ShortString;len:StrLenInt);
  239. {$endif INTERNSETLENGTH}
  240. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  241. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  242. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  243. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  244. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  245. Function Pos(C:Char;const s:shortstring):StrLenInt;
  246. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  247. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  248. Function Length(s:string):byte;
  249. Function upCase(const s:shortstring):shortstring;
  250. Function lowerCase(const s:shortstring):shortstring;
  251. Function Space(b:byte):shortstring;
  252. Function hexStr(Val:Longint;cnt:byte):shortstring;
  253. Function binStr(Val:Longint;cnt:byte):shortstring;
  254. Function hexStr(Val:int64;cnt:byte):shortstring;
  255. Function binStr(Val:int64;cnt:byte):shortstring;
  256. { Char functions }
  257. Function Chr(b:byte):Char;
  258. Function upCase(c:Char):Char;
  259. Function lowerCase(c:Char):Char;
  260. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  261. function pos(const substr : shortstring;c:char): StrLenInt;
  262. function length(c:char):byte;
  263. {****************************************************************************
  264. AnsiString Handling
  265. ****************************************************************************}
  266. {$ifndef INTERNSETLENGTH}
  267. Procedure SetLength (Var S : AnsiString; l : Longint);
  268. {$endif INTERNSETLENGTH}
  269. Procedure UniqueString (Var S : AnsiString);
  270. Function Length (Const S : AnsiString) : Longint;
  271. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  272. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  273. Function Pos (c : Char; Const s : AnsiString) : Longint;
  274. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  275. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  276. Function StringOfChar(c : char;l : longint) : AnsiString;
  277. function upcase(const s : ansistring) : ansistring;
  278. function lowercase(const s : ansistring) : ansistring;
  279. {****************************************************************************
  280. WideString Handling
  281. ****************************************************************************}
  282. {$ifdef haswidechar}
  283. {$ifndef INTERNSETLENGTH}
  284. Procedure SetLength (Var S : WideString; l : Longint);
  285. {$endif INTERNSETLENGTH}
  286. Procedure UniqueString (Var S : WideString);
  287. Function Length (Const S : WideString) : Longint;
  288. Function Copy (Const S : WideString; Index,Size : Longint) : WideString;
  289. Function Pos (Const Substr : WideString; Const Source : WideString) : Longint;
  290. Procedure Insert (Const Source : WideString; Var S : WideString; Index : Longint);
  291. Procedure Delete (Var S : WideString; Index,Size: Longint);
  292. {$endif haswidechar}
  293. {****************************************************************************
  294. Untyped File Management
  295. ****************************************************************************}
  296. Procedure Assign(Var f:File;const Name:string);
  297. Procedure Assign(Var f:File;p:pchar);
  298. Procedure Assign(Var f:File;c:char);
  299. Procedure Rewrite(Var f:File;l:Longint);
  300. Procedure Rewrite(Var f:File);
  301. Procedure Reset(Var f:File;l:Longint);
  302. Procedure Reset(Var f:File);
  303. Procedure Close(Var f:File);
  304. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  305. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  306. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  307. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  308. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  309. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  310. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  311. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  312. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  313. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  314. Function FilePos(Var f:File):Longint;
  315. Function FileSize(Var f:File):Longint;
  316. Procedure Seek(Var f:File;Pos:Longint);
  317. Function EOF(Var f:File):Boolean;
  318. Procedure Erase(Var f:File);
  319. Procedure Rename(Var f:File;const s:string);
  320. Procedure Rename(Var f:File;p:pchar);
  321. Procedure Rename(Var f:File;c:char);
  322. Procedure Truncate (Var F:File);
  323. {****************************************************************************
  324. Typed File Management
  325. ****************************************************************************}
  326. Procedure Assign(Var f:TypedFile;const Name:string);
  327. Procedure Assign(Var f:TypedFile;p:pchar);
  328. Procedure Assign(Var f:TypedFile;c:char);
  329. Procedure Rewrite(Var f:TypedFile);
  330. Procedure Reset(Var f:TypedFile);
  331. {****************************************************************************
  332. Text File Management
  333. ****************************************************************************}
  334. Procedure Assign(Var t:Text;const s:string);
  335. Procedure Assign(Var t:Text;p:pchar);
  336. Procedure Assign(Var t:Text;c:char);
  337. Procedure Close(Var t:Text);
  338. Procedure Rewrite(Var t:Text);
  339. Procedure Reset(Var t:Text);
  340. Procedure Append(Var t:Text);
  341. Procedure Flush(Var t:Text);
  342. Procedure Erase(Var t:Text);
  343. Procedure Rename(Var t:Text;const s:string);
  344. Procedure Rename(Var t:Text;p:pchar);
  345. Procedure Rename(Var t:Text;c:char);
  346. Function EOF(Var t:Text):Boolean;
  347. Function EOF:Boolean;
  348. Function EOLn(Var t:Text):Boolean;
  349. Function EOLn:Boolean;
  350. Function SeekEOLn (Var t:Text):Boolean;
  351. Function SeekEOF (Var t:Text):Boolean;
  352. Function SeekEOLn:Boolean;
  353. Function SeekEOF:Boolean;
  354. Procedure SetTextBuf(Var f:Text; Var Buf);
  355. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  356. {****************************************************************************
  357. Directory Management
  358. ****************************************************************************}
  359. Procedure chdir(const s:string);
  360. Procedure mkdir(const s:string);
  361. Procedure rmdir(const s:string);
  362. Procedure getdir(drivenr:byte;Var dir:shortstring);
  363. Procedure getdir(drivenr:byte;Var dir:ansistring);
  364. {*****************************************************************************
  365. Miscelleaous
  366. *****************************************************************************}
  367. { os independent calls to allow backtraces }
  368. function get_frame:longint;
  369. function get_caller_addr(framebp:longint):longint;
  370. function get_caller_frame(framebp:longint):longint;
  371. Function IOResult:Word;
  372. Function Sptr:Longint;
  373. {*****************************************************************************
  374. Init / Exit / ExitProc
  375. *****************************************************************************}
  376. Function Paramcount:Longint;
  377. Function ParamStr(l:Longint):string;
  378. Procedure Dump_Stack(var f : text;bp:Longint);
  379. Procedure RunError(w:Word);
  380. Procedure RunError;
  381. Procedure halt(errnum:byte);
  382. Procedure AddExitProc(Proc:TProcedure);
  383. Procedure halt;
  384. {*****************************************************************************
  385. Abstract/Assert/Error Handling
  386. *****************************************************************************}
  387. procedure AbstractError;
  388. Function SysBackTraceStr(Addr: Longint): ShortString;
  389. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  390. { Error handlers }
  391. Type
  392. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  393. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  394. TAbstractErrorProc = Procedure;
  395. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  396. const
  397. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  398. ErrorProc : TErrorProc = nil;
  399. AbstractErrorProc : TAbstractErrorProc = nil;
  400. AssertErrorProc : TAssertErrorProc = @SysAssert;
  401. {*****************************************************************************
  402. SetJmp/LongJmp
  403. *****************************************************************************}
  404. {$i setjumph.inc}
  405. {*****************************************************************************
  406. Object Pascal support
  407. *****************************************************************************}
  408. {$i objpash.inc}
  409. {
  410. $Log$
  411. Revision 1.24 2001-06-04 11:43:51 peter
  412. * Formal const to var fixes
  413. * Hexstr(int64) added
  414. Revision 1.23 2001/06/03 20:17:06 peter
  415. * ucs4char added
  416. Revision 1.22 2001/05/16 17:44:25 jonas
  417. + odd() for cardinal, int64 and qword (merged)
  418. Revision 1.21 2001/05/09 19:57:07 peter
  419. *** empty log message ***
  420. Revision 1.20 2001/04/23 18:25:45 peter
  421. * m68k updates
  422. Revision 1.19 2001/04/13 18:06:07 peter
  423. * upcase, lowercase for ansistring
  424. Revision 1.18 2001/03/22 23:26:05 florian
  425. * some new types added like PBoolean
  426. Revision 1.17 2001/03/21 23:29:40 florian
  427. + sLineBreak and misc. stuff for Kylix compatiblity
  428. Revision 1.16 2001/01/24 21:47:18 florian
  429. + more MT stuff added
  430. Revision 1.15 2000/12/16 15:56:19 jonas
  431. - removed all ifdef cardinalmulfix code
  432. Revision 1.14 2000/12/08 14:04:43 jonas
  433. + added pos(char,ansistring), because there is also a pos(char,shortstring)
  434. and without the ansistring version, the shortstring version is always
  435. called when calling pos(char,pchar), even when using $h+ (because the
  436. first parameter matches exactly) (merged)
  437. Revision 1.13 2000/12/07 17:19:47 jonas
  438. * new constant handling: from now on, hex constants >$7fffffff are
  439. parsed as unsigned constants (otherwise, $80000000 got sign extended
  440. and became $ffffffff80000000), all constants in the longint range
  441. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  442. are cardinals and the rest are int64's.
  443. * added lots of longint typecast to prevent range check errors in the
  444. compiler and rtl
  445. * type casts of symbolic ordinal constants are now preserved
  446. * fixed bug where the original resulttype wasn't restored correctly
  447. after doing a 64bit rangecheck
  448. Revision 1.12 2000/11/13 13:40:04 marco
  449. * Renamefest
  450. Revision 1.11 2000/11/11 16:12:01 peter
  451. * ptr returns farpointer
  452. Revision 1.10 2000/11/06 21:35:59 peter
  453. * removed some warnings
  454. Revision 1.9 2000/11/06 20:34:24 peter
  455. * changed ver1_0 defines to temporary defs
  456. Revision 1.8 2000/10/23 16:15:40 jonas
  457. * renamed strlenint to longint since 1.0 doesn't know that type
  458. Revision 1.7 2000/10/23 14:00:59 florian
  459. * setlength export declaration for 1.0.2 fixed
  460. Revision 1.6 2000/10/21 18:20:17 florian
  461. * a lot of small changes:
  462. - setlength is internal
  463. - win32 graph unit extended
  464. ....
  465. Revision 1.5 2000/08/13 17:55:15 michael
  466. + Added some delphi compatibility types
  467. Revision 1.4 2000/08/08 22:11:45 sg
  468. * Added declarations for WideString utility functions
  469. Revision 1.3 2000/07/14 10:33:10 michael
  470. + Conditionals fixed
  471. Revision 1.2 2000/07/13 11:33:45 michael
  472. + removed logs
  473. }