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