systemh.inc 15 KB

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