systemh.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. {****************************************************************************
  130. Processor specific routines
  131. ****************************************************************************}
  132. Procedure Move(Var source,dest;count:Longint);
  133. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  134. Procedure FillChar(Var x;count:Longint;Value:Char);
  135. Procedure FillChar(Var x;count:Longint;Value:Byte);
  136. {$ifndef RTLLITE}
  137. procedure FillByte(var x;count:longint;value:byte);
  138. Procedure FillWord(Var x;count:Longint;Value:Word);
  139. procedure FillDWord(var x;count:longint;value:DWord);
  140. function IndexChar(var buf;len:longint;b:char):longint;
  141. function IndexByte(var buf;len:longint;b:byte):longint;
  142. function Indexword(var buf;len:longint;b:word):longint;
  143. function IndexDWord(var buf;len:longint;b:DWord):longint;
  144. function CompareChar(var buf1,buf2;len:longint):longint;
  145. function CompareByte(var buf1,buf2;len:longint):longint;
  146. function CompareWord(var buf1,buf2;len:longint):longint;
  147. function CompareDWord(var buf1,buf2;len:longint):longint;
  148. procedure MoveChar0(var buf1,buf2;len:longint);
  149. function IndexChar0(var buf;len:longint;b:char):longint;
  150. function CompareChar0(var buf1,buf2;len:longint):longint;
  151. {$endif}
  152. {****************************************************************************
  153. Math Routines
  154. ****************************************************************************}
  155. {$ifndef RTLLITE}
  156. Function lo(w:Word):byte;
  157. Function lo(l:Longint):Word;
  158. Function lo(l:DWord):Word;
  159. Function lo(i:Integer):byte;
  160. Function lo(B: Byte):Byte;
  161. Function hi(w:Word):byte;
  162. Function hi(i:Integer):byte;
  163. Function hi(l:Longint):Word;
  164. Function hi(b : Byte) : Byte;
  165. Function hi(l: DWord): Word;
  166. Function Swap (X:Word):Word;
  167. Function Swap (X:Integer):Integer;
  168. Function Swap (X:Cardinal):Cardinal;
  169. Function Swap (X:LongInt):LongInt;
  170. {$ifdef INT64}
  171. Function lo(q : QWord) : DWord;
  172. Function lo(i : Int64) : DWord;
  173. Function hi(q : QWord) : DWord;
  174. Function hi(i : Int64) : DWord;
  175. Function Swap (X:QWord):QWord;
  176. Function Swap (X:Int64):Int64;
  177. {$endif}
  178. {$endif RTLLITE}
  179. Function Random(l:cardinal):cardinal;
  180. {$ifndef cardinalmulfixed}
  181. Function Random(l:longint):longint;
  182. {$endif cardinalmulfixed}
  183. Function Random: extended;
  184. Procedure Randomize;
  185. Function abs(l:Longint):Longint;
  186. Function sqr(l:Longint):Longint;
  187. Function odd(l:Longint):Boolean;
  188. { float math routines }
  189. {$I mathh.inc}
  190. {****************************************************************************
  191. Addr/Pointer Handling
  192. ****************************************************************************}
  193. {$ifndef RTLLITE}
  194. Function ptr(sel,off:Longint):pointer;
  195. Function Cseg:Word;
  196. Function Dseg:Word;
  197. Function Sseg:Word;
  198. {$endif RTLLITE}
  199. {****************************************************************************
  200. PChar and String Handling
  201. ****************************************************************************}
  202. function strpas(p:pchar):shortstring;
  203. function strlen(p:pchar):longint;
  204. { Shortstring functions }
  205. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  206. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  207. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  208. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  209. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  210. Function Pos(C:Char;const s:shortstring):StrLenInt;
  211. Procedure SetLength(var s:shortstring;len:StrLenInt);
  212. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  213. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  214. Function Length(s:string):byte;
  215. Function upCase(const s:shortstring):shortstring;
  216. {$ifndef RTLLITE}
  217. Function lowerCase(const s:shortstring):shortstring;
  218. {$endif}
  219. Function Space(b:byte):shortstring;
  220. {$ifndef RTLLITE}
  221. Function hexStr(Val:Longint;cnt:byte):shortstring;
  222. Function binStr(Val:Longint;cnt:byte):shortstring;
  223. {$endif RTLLITE}
  224. { Char functions }
  225. Function Chr(b:byte):Char;
  226. Function upCase(c:Char):Char;
  227. {$ifndef RTLLITE}
  228. Function lowerCase(c:Char):Char;
  229. {$endif RTLLITE}
  230. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  231. function pos(const substr : shortstring;c:char): StrLenInt;
  232. function length(c:char):byte;
  233. {****************************************************************************
  234. AnsiString Handling
  235. ****************************************************************************}
  236. Procedure SetLength (Var S : AnsiString; l : Longint);
  237. Procedure UniqueString (Var S : AnsiString);
  238. Function Length (Const S : AnsiString) : Longint;
  239. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  240. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  241. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  242. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  243. Function StringOfChar(c : char;l : longint) : AnsiString;
  244. {****************************************************************************
  245. Untyped File Management
  246. ****************************************************************************}
  247. Procedure Assign(Var f:File;const Name:string);
  248. Procedure Assign(Var f:File;p:pchar);
  249. Procedure Assign(Var f:File;c:char);
  250. Procedure Rewrite(Var f:File;l:Longint);
  251. Procedure Rewrite(Var f:File);
  252. Procedure Reset(Var f:File;l:Longint);
  253. Procedure Reset(Var f:File);
  254. Procedure Close(Var f:File);
  255. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  256. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  257. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  258. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  259. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  260. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  261. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  262. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  263. Function FilePos(Var f:File):Longint;
  264. Function FileSize(Var f:File):Longint;
  265. Procedure Seek(Var f:File;Pos:Longint);
  266. Function EOF(Var f:File):Boolean;
  267. Procedure Erase(Var f:File);
  268. Procedure Rename(Var f:File;const s:string);
  269. Procedure Rename(Var f:File;p:pchar);
  270. Procedure Rename(Var f:File;c:char);
  271. Procedure Truncate (Var F:File);
  272. {****************************************************************************
  273. Typed File Management
  274. ****************************************************************************}
  275. Procedure Assign(Var f:TypedFile;const Name:string);
  276. Procedure Assign(Var f:TypedFile;p:pchar);
  277. Procedure Assign(Var f:TypedFile;c:char);
  278. Procedure Rewrite(Var f:TypedFile);
  279. Procedure Reset(Var f:TypedFile);
  280. {****************************************************************************
  281. Text File Management
  282. ****************************************************************************}
  283. Procedure Assign(Var t:Text;const s:string);
  284. Procedure Assign(Var t:Text;p:pchar);
  285. Procedure Assign(Var t:Text;c:char);
  286. Procedure Close(Var t:Text);
  287. Procedure Rewrite(Var t:Text);
  288. Procedure Reset(Var t:Text);
  289. Procedure Append(Var t:Text);
  290. Procedure Flush(Var t:Text);
  291. Procedure Erase(Var t:Text);
  292. Procedure Rename(Var t:Text;const s:string);
  293. Procedure Rename(Var t:Text;p:pchar);
  294. Procedure Rename(Var t:Text;c:char);
  295. Function EOF(Var t:Text):Boolean;
  296. Function EOF:Boolean;
  297. Function EOLn(Var t:Text):Boolean;
  298. Function EOLn:Boolean;
  299. Function SeekEOLn (Var t:Text):Boolean;
  300. Function SeekEOF (Var t:Text):Boolean;
  301. Function SeekEOLn:Boolean;
  302. Function SeekEOF:Boolean;
  303. Procedure SetTextBuf(Var f:Text; Var Buf);
  304. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  305. {****************************************************************************
  306. Directory Management
  307. ****************************************************************************}
  308. Procedure chdir(const s:string);
  309. Procedure mkdir(const s:string);
  310. Procedure rmdir(const s:string);
  311. Procedure getdir(drivenr:byte;Var dir:shortstring);
  312. Procedure getdir(drivenr:byte;Var dir:ansistring);
  313. {*****************************************************************************
  314. Miscelleaous
  315. *****************************************************************************}
  316. { os independent calls to allow backtraces }
  317. function get_frame:longint;
  318. function get_caller_addr(framebp:longint):longint;
  319. function get_caller_frame(framebp:longint):longint;
  320. Function IOResult:Word;
  321. Function Sptr:Longint;
  322. {*****************************************************************************
  323. Init / Exit / ExitProc
  324. *****************************************************************************}
  325. Function Paramcount:Longint;
  326. Function ParamStr(l:Longint):string;
  327. {$ifndef RTLLITE}
  328. Procedure Dump_Stack(var f : text;bp:Longint);
  329. {$endif RTLLITE}
  330. Procedure RunError(w:Word);
  331. Procedure RunError;
  332. Procedure halt(errnum:byte);
  333. {$ifndef RTLLITE}
  334. Procedure AddExitProc(Proc:TProcedure);
  335. {$endif RTLLITE}
  336. Procedure halt;
  337. {*****************************************************************************
  338. Abstract/Assert/Error Handling
  339. *****************************************************************************}
  340. procedure AbstractError;
  341. Function SysBackTraceStr(Addr: Longint): ShortString;
  342. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  343. { Error handlers }
  344. Type
  345. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  346. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  347. TAbstractErrorProc = Procedure;
  348. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  349. const
  350. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  351. ErrorProc : TErrorProc = nil;
  352. AbstractErrorProc : TAbstractErrorProc = nil;
  353. AssertErrorProc : TAssertErrorProc = @SysAssert;
  354. {*****************************************************************************
  355. SetJmp/LongJmp
  356. *****************************************************************************}
  357. {$i setjumph.inc}
  358. {*****************************************************************************
  359. Object Pascal support
  360. *****************************************************************************}
  361. {$i objpash.inc}
  362. {
  363. $Log$
  364. Revision 1.83 2000-06-11 07:02:30 peter
  365. * UniqueAnsiString -> UniqueString for Delphi compatibility
  366. Revision 1.82 2000/05/14 18:46:54 florian
  367. * TVarRec with In64/QWord stuff extended
  368. Revision 1.81 2000/04/24 11:11:50 peter
  369. * backtraces for exceptions are now only generated from the place of the
  370. exception
  371. * frame is also pushed for exceptions
  372. * raise statement enhanced with [,<frame>]
  373. Revision 1.80 2000/03/26 11:36:28 jonas
  374. + $maxfpuregisters 0 for i386 in systemh (to avoid requiring too much
  375. empty FPU registers for sysstem routines
  376. * fixed bug in str_real when using :x:0
  377. * str_real now doesn't call exp() anymore at runtime, so it should
  378. require less free FPU registers now (and be slightly faster)
  379. Revision 1.79 2000/03/14 10:20:18 michael
  380. + Added constants and types for Delphi compatibility
  381. Revision 1.78 2000/02/09 16:59:31 peter
  382. * truncated log
  383. Revision 1.77 2000/02/06 17:19:22 peter
  384. * lineinfo unit added which uses stabs to get lineinfo for backtraces
  385. Revision 1.76 2000/01/21 15:32:07 jonas
  386. * set FPUInt64 to false for i386, because comp mul and div code for int64 is
  387. commented out in int64.inc
  388. Revision 1.75 2000/01/10 09:54:30 peter
  389. * primitives added
  390. Revision 1.74 2000/01/07 16:41:36 daniel
  391. * copyright 2000
  392. Revision 1.73 2000/01/07 16:32:25 daniel
  393. * copyright 2000 added
  394. Revision 1.72 1999/12/20 11:20:14 peter
  395. + smallint, maxsmallint
  396. * integer is redefined as smallint
  397. Revision 1.71 1999/12/18 14:55:05 florian
  398. * very basic widestring support
  399. Revision 1.70 1999/12/12 13:29:34 jonas
  400. * remove "random(longint): longint" if cardinalmulfixed is defined
  401. Revision 1.69 1999/12/01 12:37:13 jonas
  402. + function random(longint): longint
  403. Revision 1.68 1999/11/25 13:34:57 michael
  404. + Added Ansistring setstring call
  405. Revision 1.67 1999/11/20 12:48:09 jonas
  406. * reinstated old random generator, but modified it so the integer
  407. one now has a much longer period
  408. Revision 1.66 1999/11/09 20:14:12 daniel
  409. * Committed new random generator.
  410. Revision 1.65 1999/11/06 14:35:39 peter
  411. * truncated log
  412. Revision 1.64 1999/10/27 14:19:10 florian
  413. + StringOfChar
  414. Revision 1.63 1999/10/26 12:31:00 peter
  415. * *errorproc are not procvars instead of pointers which allows better
  416. error checking for the parameters (shortstring<->ansistring)
  417. Revision 1.62 1999/08/19 11:16:13 peter
  418. * settextbuf size is now longint
  419. }