systemh.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. currency = int64;
  73. HRESULT = Longint;
  74. TDateTime = Double;
  75. Error = Longint;
  76. PSmallInt = ^Smallint;
  77. PInteger = ^Longint;
  78. PSingle = ^Single;
  79. PDouble = ^Double;
  80. PCurrency = ^Currency;
  81. PDate = ^TDateTime;
  82. PPWideChar = ^PWideChar;
  83. PError = ^Error;
  84. PWordBool = ^WordBool;
  85. PByte = ^Byte;
  86. PWord = ^word;
  87. PDWord = ^DWord;
  88. PLongint = ^Longint;
  89. {$ifdef HASWIDECHAR}
  90. PWideChar = ^WideChar;
  91. {$endif HASWIDECHAR}
  92. { procedure type }
  93. TProcedure = Procedure;
  94. const
  95. { Maximum value of the biggest signed and unsigned integer type available}
  96. MaxSIntValue = High(ValSInt);
  97. MaxUIntValue = High(ValUInt);
  98. { max. values for longint and int}
  99. maxLongint = $7fffffff;
  100. maxSmallint = 32767;
  101. { Integer type definition }
  102. type
  103. Integer = smallint;
  104. const
  105. maxint = maxsmallint;
  106. { Compatibility With TP }
  107. const
  108. {$ifdef i386}
  109. Test8086 : byte = 2; { Always i386 or newer }
  110. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  111. { code to use comps in int64mul and div code is commented out! (JM) }
  112. FPUInt64 : boolean = false; { set this to false if you don't want that }
  113. { the fpu does int64*int64 and }
  114. { int64 div int64, if the * is overflow }
  115. { checked, it is done in software }
  116. {$endif i386}
  117. {$ifdef m68k}
  118. Test68000 : byte = 0; { Must be determined at startup for both }
  119. Test68881 : byte = 0;
  120. {$endif}
  121. { max level in dumping on error }
  122. Max_Frame_Dump : Word = 8;
  123. { Exit Procedure handling consts and types }
  124. ExitProc : pointer = nil;
  125. Erroraddr: pointer = nil;
  126. Errorcode: Word = 0;
  127. { file input modes }
  128. fmClosed = $D7B0;
  129. fmInput = $D7B1;
  130. fmOutput = $D7B2;
  131. fmInOut = $D7B3;
  132. fmAppend = $D7B4;
  133. Filemode : byte = 2;
  134. CmdLine : PChar = nil;
  135. var
  136. { Standard In- and Output }
  137. Output,
  138. Input,
  139. StdOut,
  140. StdErr : Text;
  141. ExitCode,
  142. InOutRes : Word;
  143. StackBottom,
  144. LowestStack,
  145. RandSeed : Cardinal;
  146. { Delphi compatible }
  147. IsLibrary,IsMultiThreaded,IsConsole : boolean;
  148. {****************************************************************************
  149. Processor specific routines
  150. ****************************************************************************}
  151. Procedure Move(const source;var dest;count:Longint);
  152. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  153. Procedure FillChar(Var x;count:Longint;Value:Char);
  154. Procedure FillChar(Var x;count:Longint;Value:Byte);
  155. {$ifndef RTLLITE}
  156. procedure FillByte(var x;count:longint;value:byte);
  157. Procedure FillWord(Var x;count:Longint;Value:Word);
  158. procedure FillDWord(var x;count:longint;value:DWord);
  159. function IndexChar(var buf;len:longint;b:char):longint;
  160. function IndexByte(var buf;len:longint;b:byte):longint;
  161. function Indexword(var buf;len:longint;b:word):longint;
  162. function IndexDWord(var buf;len:longint;b:DWord):longint;
  163. function CompareChar(var buf1,buf2;len:longint):longint;
  164. function CompareByte(var buf1,buf2;len:longint):longint;
  165. function CompareWord(var buf1,buf2;len:longint):longint;
  166. function CompareDWord(var buf1,buf2;len:longint):longint;
  167. procedure MoveChar0(var buf1,buf2;len:longint);
  168. function IndexChar0(var buf;len:longint;b:char):longint;
  169. function CompareChar0(var buf1,buf2;len:longint):longint;
  170. {$endif}
  171. {****************************************************************************
  172. Math Routines
  173. ****************************************************************************}
  174. {$ifndef RTLLITE}
  175. Function lo(w:Word):byte;
  176. Function lo(l:Longint):Word;
  177. Function lo(l:DWord):Word;
  178. Function lo(i:Integer):byte;
  179. Function lo(B: Byte):Byte;
  180. Function hi(w:Word):byte;
  181. Function hi(i:Integer):byte;
  182. Function hi(l:Longint):Word;
  183. Function hi(b : Byte) : Byte;
  184. Function hi(l: DWord): Word;
  185. Function Swap (X:Word):Word;
  186. Function Swap (X:Integer):Integer;
  187. Function Swap (X:Cardinal):Cardinal;
  188. Function Swap (X:LongInt):LongInt;
  189. Function lo(q : QWord) : DWord;
  190. Function lo(i : Int64) : DWord;
  191. Function hi(q : QWord) : DWord;
  192. Function hi(i : Int64) : DWord;
  193. Function Swap (X:QWord):QWord;
  194. Function Swap (X:Int64):Int64;
  195. {$endif RTLLITE}
  196. Function Random(l:cardinal):cardinal;
  197. {$ifndef cardinalmulfixed}
  198. Function Random(l:longint):longint;
  199. {$endif cardinalmulfixed}
  200. Function Random: extended;
  201. Procedure Randomize;
  202. Function abs(l:Longint):Longint;
  203. Function sqr(l:Longint):Longint;
  204. Function odd(l:Longint):Boolean;
  205. { float math routines }
  206. {$I mathh.inc}
  207. {****************************************************************************
  208. Addr/Pointer Handling
  209. ****************************************************************************}
  210. {$ifndef RTLLITE}
  211. Function ptr(sel,off:Longint):pointer;
  212. Function Cseg:Word;
  213. Function Dseg:Word;
  214. Function Sseg:Word;
  215. {$endif RTLLITE}
  216. {****************************************************************************
  217. PChar and String Handling
  218. ****************************************************************************}
  219. function strpas(p:pchar):shortstring;
  220. function strlen(p:pchar):longint;
  221. { Shortstring functions }
  222. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  223. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  224. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  225. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  226. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  227. Function Pos(C:Char;const s:shortstring):StrLenInt;
  228. Procedure SetLength(var s:shortstring;len:StrLenInt);
  229. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  230. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  231. Function Length(s:string):byte;
  232. Function upCase(const s:shortstring):shortstring;
  233. {$ifndef RTLLITE}
  234. Function lowerCase(const s:shortstring):shortstring;
  235. {$endif}
  236. Function Space(b:byte):shortstring;
  237. {$ifndef RTLLITE}
  238. Function hexStr(Val:Longint;cnt:byte):shortstring;
  239. Function binStr(Val:Longint;cnt:byte):shortstring;
  240. {$endif RTLLITE}
  241. { Char functions }
  242. Function Chr(b:byte):Char;
  243. Function upCase(c:Char):Char;
  244. {$ifndef RTLLITE}
  245. Function lowerCase(c:Char):Char;
  246. {$endif RTLLITE}
  247. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  248. function pos(const substr : shortstring;c:char): StrLenInt;
  249. function length(c:char):byte;
  250. {****************************************************************************
  251. AnsiString Handling
  252. ****************************************************************************}
  253. Procedure SetLength (Var S : AnsiString; l : Longint);
  254. Procedure UniqueString (Var S : AnsiString);
  255. Function Length (Const S : AnsiString) : Longint;
  256. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  257. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  258. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  259. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  260. Function StringOfChar(c : char;l : longint) : AnsiString;
  261. {****************************************************************************
  262. WideString Handling
  263. ****************************************************************************}
  264. Procedure SetLength (Var S : WideString; l : Longint);
  265. Procedure UniqueString (Var S : WideString);
  266. Function Length (Const S : WideString) : Longint;
  267. Function Copy (Const S : WideString; Index,Size : Longint) : WideString;
  268. Function Pos (Const Substr : WideString; Const Source : WideString) : Longint;
  269. Procedure Insert (Const Source : WideString; Var S : WideString; Index : Longint);
  270. Procedure Delete (Var S : WideString; Index,Size: Longint);
  271. {****************************************************************************
  272. Untyped File Management
  273. ****************************************************************************}
  274. Procedure Assign(Var f:File;const Name:string);
  275. Procedure Assign(Var f:File;p:pchar);
  276. Procedure Assign(Var f:File;c:char);
  277. Procedure Rewrite(Var f:File;l:Longint);
  278. Procedure Rewrite(Var f:File);
  279. Procedure Reset(Var f:File;l:Longint);
  280. Procedure Reset(Var f:File);
  281. Procedure Close(Var f:File);
  282. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  283. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  284. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  285. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  286. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  287. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  288. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  289. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  290. Function FilePos(Var f:File):Longint;
  291. Function FileSize(Var f:File):Longint;
  292. Procedure Seek(Var f:File;Pos:Longint);
  293. Function EOF(Var f:File):Boolean;
  294. Procedure Erase(Var f:File);
  295. Procedure Rename(Var f:File;const s:string);
  296. Procedure Rename(Var f:File;p:pchar);
  297. Procedure Rename(Var f:File;c:char);
  298. Procedure Truncate (Var F:File);
  299. {****************************************************************************
  300. Typed File Management
  301. ****************************************************************************}
  302. Procedure Assign(Var f:TypedFile;const Name:string);
  303. Procedure Assign(Var f:TypedFile;p:pchar);
  304. Procedure Assign(Var f:TypedFile;c:char);
  305. Procedure Rewrite(Var f:TypedFile);
  306. Procedure Reset(Var f:TypedFile);
  307. {****************************************************************************
  308. Text File Management
  309. ****************************************************************************}
  310. Procedure Assign(Var t:Text;const s:string);
  311. Procedure Assign(Var t:Text;p:pchar);
  312. Procedure Assign(Var t:Text;c:char);
  313. Procedure Close(Var t:Text);
  314. Procedure Rewrite(Var t:Text);
  315. Procedure Reset(Var t:Text);
  316. Procedure Append(Var t:Text);
  317. Procedure Flush(Var t:Text);
  318. Procedure Erase(Var t:Text);
  319. Procedure Rename(Var t:Text;const s:string);
  320. Procedure Rename(Var t:Text;p:pchar);
  321. Procedure Rename(Var t:Text;c:char);
  322. Function EOF(Var t:Text):Boolean;
  323. Function EOF:Boolean;
  324. Function EOLn(Var t:Text):Boolean;
  325. Function EOLn:Boolean;
  326. Function SeekEOLn (Var t:Text):Boolean;
  327. Function SeekEOF (Var t:Text):Boolean;
  328. Function SeekEOLn:Boolean;
  329. Function SeekEOF:Boolean;
  330. Procedure SetTextBuf(Var f:Text; Var Buf);
  331. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  332. {****************************************************************************
  333. Directory Management
  334. ****************************************************************************}
  335. Procedure chdir(const s:string);
  336. Procedure mkdir(const s:string);
  337. Procedure rmdir(const s:string);
  338. Procedure getdir(drivenr:byte;Var dir:shortstring);
  339. Procedure getdir(drivenr:byte;Var dir:ansistring);
  340. {*****************************************************************************
  341. Miscelleaous
  342. *****************************************************************************}
  343. { os independent calls to allow backtraces }
  344. function get_frame:longint;
  345. function get_caller_addr(framebp:longint):longint;
  346. function get_caller_frame(framebp:longint):longint;
  347. Function IOResult:Word;
  348. Function Sptr:Longint;
  349. {*****************************************************************************
  350. Init / Exit / ExitProc
  351. *****************************************************************************}
  352. Function Paramcount:Longint;
  353. Function ParamStr(l:Longint):string;
  354. {$ifndef RTLLITE}
  355. Procedure Dump_Stack(var f : text;bp:Longint);
  356. {$endif RTLLITE}
  357. Procedure RunError(w:Word);
  358. Procedure RunError;
  359. Procedure halt(errnum:byte);
  360. {$ifndef RTLLITE}
  361. Procedure AddExitProc(Proc:TProcedure);
  362. {$endif RTLLITE}
  363. Procedure halt;
  364. {*****************************************************************************
  365. Abstract/Assert/Error Handling
  366. *****************************************************************************}
  367. procedure AbstractError;
  368. Function SysBackTraceStr(Addr: Longint): ShortString;
  369. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  370. { Error handlers }
  371. Type
  372. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  373. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  374. TAbstractErrorProc = Procedure;
  375. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  376. const
  377. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  378. ErrorProc : TErrorProc = nil;
  379. AbstractErrorProc : TAbstractErrorProc = nil;
  380. AssertErrorProc : TAssertErrorProc = @SysAssert;
  381. {*****************************************************************************
  382. SetJmp/LongJmp
  383. *****************************************************************************}
  384. {$i setjumph.inc}
  385. {*****************************************************************************
  386. Object Pascal support
  387. *****************************************************************************}
  388. {$i objpash.inc}
  389. {
  390. $Log$
  391. Revision 1.5 2000-08-13 17:55:15 michael
  392. + Added some delphi compatibility types
  393. Revision 1.4 2000/08/08 22:11:45 sg
  394. * Added declarations for WideString utility functions
  395. Revision 1.3 2000/07/14 10:33:10 michael
  396. + Conditionals fixed
  397. Revision 1.2 2000/07/13 11:33:45 michael
  398. + removed logs
  399. }