systemh.inc 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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. { Using inlining for small system functions/wrappers }
  18. {$ifdef HASINLINE}
  19. {$inline on}
  20. {$define SYSTEMINLINE}
  21. {$endif}
  22. { Use threadvars when the compiler supports it }
  23. {$ifdef HASTHREADVAR}
  24. {$define SUPPORT_THREADVAR}
  25. {$endif HASTHREADVAR}
  26. { don't use FPU registervariables on the i386 }
  27. {$ifdef CPUI386}
  28. {$maxfpuregisters 0}
  29. {$endif CPUI386}
  30. { the assembler helpers need this }
  31. {$ifdef POWERPC}
  32. {$goto+}
  33. {$endif POWERPC}
  34. { needed for insert,delete,readln }
  35. {$P+}
  36. { stack checking always disabled
  37. for system unit. This is because
  38. the startup code might not
  39. have been called yet when we
  40. get a stack error, this will
  41. cause big crashes
  42. }
  43. {$S-}
  44. {****************************************************************************
  45. Global Types and Constants
  46. ****************************************************************************}
  47. Type
  48. {$Ifdef HAS_INTERNAL_INTTYPES}
  49. { The compiler has all integer types defined internally. Here
  50. we define only aliases }
  51. DWord = LongWord;
  52. Cardinal = LongWord;
  53. Integer = SmallInt;
  54. {$else HAS_INTERNAL_INTTYPES}
  55. ShortInt = -128..127;
  56. SmallInt = -32768..32767;
  57. { can't use -2147483648 because of a bug in 1.0.2's val() procedure (JM) }
  58. Longint = +(-2147483647-1)..$7fffffff;
  59. Byte = 0..255;
  60. Word = 0..65535;
  61. {$ifndef ver1_0}
  62. DWord = LongWord;
  63. Cardinal = LongWord;
  64. {$else}
  65. Longword = cardinal;
  66. Dword = cardinal;
  67. {$endif}
  68. Integer = SmallInt;
  69. {$endif HAS_INTERNAL_INTTYPES}
  70. {$ifdef CPUI386}
  71. { for bootstrapping with 1.0.x }
  72. {$define CPU32}
  73. {$define DEFAULT_EXTENDED}
  74. {$define SUPPORT_SINGLE}
  75. {$define SUPPORT_DOUBLE}
  76. {$define SUPPORT_EXTENDED}
  77. {$define SUPPORT_COMP}
  78. ValReal = Extended;
  79. {$endif CPUI386}
  80. {$ifdef CPUX86_64}
  81. {$define DEFAULT_EXTENDED}
  82. {$define SUPPORT_SINGLE}
  83. {$define SUPPORT_DOUBLE}
  84. {$define SUPPORT_EXTENDED}
  85. {$define SUPPORT_COMP}
  86. ValReal = Extended;
  87. {$endif CPUX86_64}
  88. {$ifdef CPUM68K}
  89. ValReal = Real;
  90. {$define SUPPORT_SINGLE}
  91. {$IFDEF Unix}
  92. { Linux FPU emulator will be used }
  93. {$define SUPPORT_DOUBLE}
  94. {$ENDIF}
  95. {$IFOPT E-}
  96. { If not compiling with emulation }
  97. { then support double type. }
  98. {$define SUPPORT_DOUBLE}
  99. {$ENDIF}
  100. { Comp type does not exist on fpu }
  101. Comp = int64;
  102. PComp = ^Comp;
  103. {$ifdef FPC_HASNOFARPOINTER}
  104. FarPointer = Pointer;
  105. {$endif FPC_HASNOFARPOINTER}
  106. {$endif CPUM68K}
  107. {$ifdef CPUPOWERPC}
  108. {$define DEFAULT_DOUBLE}
  109. {$define SUPPORT_SINGLE}
  110. {$define SUPPORT_DOUBLE}
  111. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  112. ValReal = Double;
  113. { map comp to int64, but this doesn't mean we compile the comp support in! }
  114. Comp = Int64;
  115. PComp = ^Comp;
  116. {$ifdef FPC_HASNOFARPOINTER}
  117. FarPointer = Pointer;
  118. {$endif FPC_HASNOFARPOINTER}
  119. {$endif CPUPOWERPC}
  120. {$ifdef CPUSPARC}
  121. {$define DEFAULT_DOUBLE}
  122. {$define SUPPORT_SINGLE}
  123. {$define SUPPORT_DOUBLE}
  124. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  125. ValReal = Double;
  126. { map comp to int64, but this doesn't mean we compile the comp support in! }
  127. Comp = Int64;
  128. PComp = ^Comp;
  129. {$ifdef FPC_HASNOFARPOINTER}
  130. FarPointer = Pointer;
  131. {$endif FPC_HASNOFARPOINTER}
  132. {$endif CPUSPARC}
  133. {$ifdef CPUARM}
  134. {$define DEFAULT_DOUBLE}
  135. {$define SUPPORT_SINGLE}
  136. {$define SUPPORT_DOUBLE}
  137. {$define FPC_INCLUDE_SOFTWARE_MOD_DIV}
  138. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  139. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  140. ValReal = Real;
  141. { map comp to int64, but this doesn't mean we compile the comp support in! }
  142. Comp = Int64;
  143. PComp = ^Comp;
  144. {$ifdef FPC_HASNOFARPOINTER}
  145. FarPointer = Pointer;
  146. {$endif FPC_HASNOFARPOINTER}
  147. {$endif CPUARM}
  148. {$ifdef CPU64}
  149. SizeInt = Int64;
  150. SizeUInt = QWord;
  151. PtrInt = Int64;
  152. PtrUInt = QWord;
  153. ValSInt = int64;
  154. ValUInt = qword;
  155. {$endif CPU64}
  156. {$ifdef CPU32}
  157. SizeInt = Longint;
  158. SizeUInt = DWord;
  159. PtrInt = Longint;
  160. PtrUInt = DWord;
  161. ValSInt = Longint;
  162. ValUInt = Cardinal;
  163. {$endif CPU32}
  164. { Zero - terminated strings }
  165. PChar = ^Char;
  166. PPChar = ^PChar;
  167. { AnsiChar is equivalent of Char, so we need
  168. to use type renamings }
  169. TAnsiChar = Char;
  170. AnsiChar = Char;
  171. PAnsiChar = PChar;
  172. PPAnsiChar = PPChar;
  173. UCS4Char = type LongWord;
  174. PUCS4Char = ^UCS4Char;
  175. TUCS4CharArray = array[0..$effffff] of UCS4Char;
  176. PUCS4CharArray = ^TUCS4CharArray;
  177. {$ifndef VER1_0}
  178. UCS4String = array of UCS4Char;
  179. {$endif VER1_0}
  180. UTF8String = type ansistring;
  181. PUTF8String = ^UTF8String;
  182. {$ifndef HASCURRENCY}
  183. Currency = Int64;
  184. {$endif HASCURRENCY}
  185. HRESULT = type Longint;
  186. TDateTime = type Double;
  187. Error = type Longint;
  188. PSingle = ^Single;
  189. PDouble = ^Double;
  190. PCurrency = ^Currency;
  191. {$ifdef SUPPORT_COMP}
  192. PComp = ^Comp;
  193. {$endif SUPPORT_COMP}
  194. PExtended = ^Extended;
  195. PSmallInt = ^Smallint;
  196. PShortInt = ^Shortint;
  197. PInteger = ^Integer;
  198. PByte = ^Byte;
  199. PWord = ^word;
  200. PDWord = ^DWord;
  201. PLongWord = ^LongWord;
  202. PLongint = ^Longint;
  203. PCardinal = ^Cardinal;
  204. PQWord = ^QWord;
  205. PInt64 = ^Int64;
  206. PPtrInt = ^PtrInt;
  207. PSizeInt = ^SizeInt;
  208. PPointer = ^Pointer;
  209. PPPointer = ^PPointer;
  210. PBoolean = ^Boolean;
  211. PWordBool = ^WordBool;
  212. PLongBool = ^LongBool;
  213. PShortString = ^ShortString;
  214. PAnsiString = ^AnsiString;
  215. PDate = ^TDateTime;
  216. PError = ^Error;
  217. {$ifdef HASVARIANT}
  218. PVariant = ^Variant;
  219. POleVariant = ^OleVariant;
  220. {$endif HASVARIANT}
  221. {$ifdef HASWIDECHAR}
  222. PWideChar = ^WideChar;
  223. PPWideChar = ^PWideChar;
  224. { 1.0.x also has HASWIDECHAR defined, but doesn't support it
  225. fully, setting WChar to Word as fallback (PFV) }
  226. {$ifndef VER1_0}
  227. WChar = Widechar;
  228. {$else}
  229. WChar = Word;
  230. {$endif}
  231. UCS2Char = WideChar;
  232. PUCS2Char = PWideChar;
  233. {$else}
  234. WChar = Word;
  235. {$endif HASWIDECHAR}
  236. {$ifdef HASWIDESTRING}
  237. PWideString = ^WideString;
  238. {$endif HASWIDESTRING}
  239. { Needed for fpc_get_output }
  240. PText = ^Text;
  241. TTextLineBreakStyle = (tlbsLF,tlbsCRLF,tlbsCR);
  242. { procedure type }
  243. TProcedure = Procedure;
  244. { platform dependent types }
  245. {$i sysosh.inc}
  246. const
  247. { Maximum value of the biggest signed and unsigned integer type available}
  248. MaxSIntValue = High(ValSInt);
  249. MaxUIntValue = High(ValUInt);
  250. { max. values for longint and int}
  251. maxLongint = $7fffffff;
  252. maxSmallint = 32767;
  253. maxint = maxsmallint;
  254. type
  255. IntegerArray = array[0..$effffff] of Integer;
  256. PIntegerArray = ^IntegerArray;
  257. PointerArray = array [0..512*1024*1024 - 2] of Pointer;
  258. PPointerArray = ^PointerArray;
  259. {$ifndef VER1_0}
  260. TBoundArray = array of Integer;
  261. {$endif VER1_0}
  262. TPCharArray = packed array[0..(MaxLongint div SizeOf(PChar))-1] of PChar;
  263. PPCharArray = ^TPCharArray;
  264. const
  265. {$ifdef cpui386}
  266. Test8086 : byte = 2; { Always i386 or newer }
  267. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  268. {$endif cpui386}
  269. {$ifdef cpum68k}
  270. Test68000 : byte = 0; { Must be determined at startup for both }
  271. Test68881 : byte = 0;
  272. {$endif cpum68k}
  273. { max level in dumping on error }
  274. Max_Frame_Dump : Word = 8;
  275. { Exit Procedure handling consts and types }
  276. ExitProc : pointer = nil;
  277. Erroraddr: pointer = nil;
  278. Errorcode: Word = 0;
  279. { file input modes }
  280. fmClosed = $D7B0;
  281. fmInput = $D7B1;
  282. fmOutput = $D7B2;
  283. fmInOut = $D7B3;
  284. fmAppend = $D7B4;
  285. Filemode : byte = 2;
  286. CmdLine : PChar = nil;
  287. (* Value should be changed during system initialization as appropriate. *)
  288. { assume that this program will not spawn other threads, when the
  289. first thread is started the following constants need to be filled }
  290. IsMultiThread : boolean = FALSE;
  291. { Indicates if there was an error }
  292. StackError : boolean = FALSE;
  293. var
  294. ExitCode : Word; public name 'operatingsystem_result';
  295. RandSeed : Cardinal;
  296. { Delphi compatibility }
  297. IsLibrary : boolean;
  298. IsConsole : boolean;
  299. { Threading support }
  300. fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
  301. InitProc : Pointer;
  302. {$ifdef SUPPORT_THREADVAR}
  303. ThreadVar
  304. {$else SUPPORT_THREADVAR}
  305. Var
  306. {$endif SUPPORT_THREADVAR}
  307. ThreadID : SizeUInt;
  308. { Standard In- and Output }
  309. ErrOutput,
  310. Output,
  311. Input,
  312. StdOut,
  313. StdErr : Text;
  314. InOutRes : Word;
  315. { Stack checking }
  316. StackBottom : Pointer;
  317. StackLength : Cardinal;
  318. { Numbers for routines that have compiler magic }
  319. {$I innr.inc}
  320. {****************************************************************************
  321. Processor specific routines
  322. ****************************************************************************}
  323. {$ifdef FPC_USE_LIBC}
  324. {$ifdef SYSTEMINLINE}
  325. {$define INLINEGENERICS}
  326. {$endif}
  327. {$endif}
  328. Procedure Move(const source;var dest;count:SizeInt);{$ifdef INLINEGENERICS}inline;{$endif}
  329. Procedure FillChar(Var x;count:SizeInt;Value:Boolean);{$ifdef SYSTEMINLINE}inline;{$endif}
  330. Procedure FillChar(Var x;count:SizeInt;Value:Char);{$ifdef SYSTEMINLINE}inline;{$endif}
  331. Procedure FillChar(Var x;count:SizeInt;Value:Byte);{$ifdef INLINEGENERICS}inline;{$endif}
  332. procedure FillByte(var x;count:SizeInt;value:byte);{$ifdef INLINEGENERICS}inline;{$endif}
  333. Procedure FillWord(Var x;count:SizeInt;Value:Word);
  334. procedure FillDWord(var x;count:SizeInt;value:DWord);
  335. function IndexChar(const buf;len:SizeInt;b:char):SizeInt;
  336. function IndexByte(const buf;len:SizeInt;b:byte):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  337. function Indexword(const buf;len:SizeInt;b:word):SizeInt;
  338. function IndexDWord(const buf;len:SizeInt;b:DWord):SizeInt;
  339. function CompareChar(const buf1,buf2;len:SizeInt):SizeInt;
  340. function CompareByte(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  341. function CompareWord(const buf1,buf2;len:SizeInt):SizeInt;
  342. function CompareDWord(const buf1,buf2;len:SizeInt):SizeInt;
  343. procedure MoveChar0(const buf1;var buf2;len:SizeInt);
  344. function IndexChar0(const buf;len:SizeInt;b:char):SizeInt;
  345. function CompareChar0(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  346. procedure prefetch(const mem);{$ifdef INTERNCONSTINTF}[internproc:fpc_in_prefetch_var];{$endif}
  347. {****************************************************************************
  348. Math Routines
  349. ****************************************************************************}
  350. Function lo(B: Byte):Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  351. Function hi(b : Byte) : Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  352. Function lo(i : Integer) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_Word];{$endif}
  353. Function lo(w : Word) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_Word];{$endif}
  354. Function lo(l : Longint) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_long];{$endif}
  355. Function lo(l : DWord) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_long];{$endif}
  356. Function lo(i : Int64) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_qword];{$endif}
  357. Function lo(q : QWord) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_qword];{$endif}
  358. Function hi(i : Integer) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_Word];{$endif}
  359. Function hi(w : Word) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_Word];{$endif}
  360. Function hi(l : Longint) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_long];{$endif}
  361. Function hi(l : DWord) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_long];{$endif}
  362. Function hi(i : Int64) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_qword];{$endif}
  363. Function hi(q : QWord) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_qword];{$endif}
  364. Function swap (X : Word) : Word;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_word];{$endif}
  365. Function Swap (X : Integer) : Integer;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_word];{$endif}
  366. Function swap (X : Longint) : Longint;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_long];{$endif}
  367. Function Swap (X : Cardinal) : Cardinal;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_long];{$endif}
  368. Function Swap (X : QWord) : QWord;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_qword];{$endif}
  369. Function swap (X : Int64) : Int64;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_qword];{$endif}
  370. Function Align (Addr : PtrInt; Alignment : PtrInt) : PtrInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  371. Function Align (Addr : Pointer; Alignment : PtrInt) : Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  372. Function Random(l:longint):longint;
  373. Function Random(l:int64):int64;
  374. Function Random: extended;
  375. Procedure Randomize;
  376. Function abs(l:Longint):Longint;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_abs];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  377. Function abs(l:Int64):Int64;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_abs];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  378. Function sqr(l:Longint):Longint;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  379. Function sqr(l:Int64):Int64;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  380. Function sqr(l:QWord):QWord;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  381. Function odd(l:Longint):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  382. Function odd(l:Longword):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  383. Function odd(l:Int64):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  384. Function odd(l:QWord):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  385. { float math routines }
  386. {$I mathh.inc}
  387. operator ** (bas,expo : real) e: real;
  388. operator ** (bas,expo : int64) i: int64;
  389. {****************************************************************************
  390. Addr/Pointer Handling
  391. ****************************************************************************}
  392. Function ptr(sel,off:Longint):farpointer;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  393. Function Cseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  394. Function Dseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  395. Function Sseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  396. {****************************************************************************
  397. PChar and String Handling
  398. ****************************************************************************}
  399. function strpas(p:pchar):shortstring;external name 'FPC_PCHAR_TO_SHORTSTR';
  400. function strlen(p:pchar):longint;external name 'FPC_PCHAR_LENGTH';
  401. { Shortstring functions }
  402. {$ifndef INTERNSETLENGTH}
  403. Procedure SetLength (Var S:ShortString;len:SizeInt);
  404. {$endif INTERNSETLENGTH}
  405. {$ifndef InternCopy}
  406. Function Copy(const s:shortstring;index:SizeInt;count:SizeInt):shortstring;
  407. {$endif interncopy}
  408. Procedure Delete(Var s:shortstring;index:SizeInt;count:SizeInt);
  409. Procedure Insert(const source:shortstring;Var s:shortstring;index:SizeInt);
  410. Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
  411. Function Pos(const substr:shortstring;const s:shortstring):SizeInt;
  412. Function Pos(C:Char;const s:shortstring):SizeInt;
  413. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
  414. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
  415. {$ifndef INTERNLENGTH}
  416. Function Length(s:string):byte;
  417. {$endif INTERNLENGTH}
  418. Function upCase(const s:shortstring):shortstring;
  419. Function lowerCase(const s:shortstring):shortstring; overload;
  420. Function Space(b:byte):shortstring;
  421. Function hexStr(Val:Longint;cnt:byte):shortstring;
  422. Function OctStr(Val:Longint;cnt:byte):shortstring;
  423. Function binStr(Val:Longint;cnt:byte):shortstring;
  424. Function hexStr(Val:int64;cnt:byte):shortstring;
  425. Function OctStr(Val:int64;cnt:byte):shortstring;
  426. Function binStr(Val:int64;cnt:byte):shortstring;
  427. { Char functions }
  428. {$ifdef INTERNCONSTINTF}
  429. Function chr(b : byte) : Char; [INTERNPROC: fpc_in_chr_byte];
  430. {$else}
  431. Function Chr(b:byte):Char;
  432. {$endif}
  433. Function upCase(c:Char):Char;
  434. Function lowerCase(c:Char):Char; overload;
  435. {$ifndef InternCopy}
  436. function copy(c:char;index : SizeInt;count : SizeInt): shortstring;
  437. {$endif interncopy}
  438. function pos(const substr : shortstring;c:char): SizeInt;
  439. {$ifndef INTERNLENGTH}
  440. function length(c:char):byte;
  441. {$endif INTERNLENGTH}
  442. {****************************************************************************
  443. AnsiString Handling
  444. ****************************************************************************}
  445. {$ifndef INTERNSETLENGTH}
  446. Procedure SetLength (Var S : AnsiString; l : SizeInt);
  447. {$endif INTERNSETLENGTH}
  448. Procedure UniqueString(Var S : AnsiString);external name 'FPC_ANSISTR_UNIQUE';
  449. {$ifndef INTERNLENGTH}
  450. Function Length (Const S : AnsiString) : SizeInt;
  451. {$endif INTERNLENGTH}
  452. {$ifndef InternCopy}
  453. Function Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;
  454. {$endif interncopy}
  455. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
  456. Function Pos (c : Char; Const s : AnsiString) : SizeInt;
  457. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : SizeInt);
  458. Procedure Delete (Var S : AnsiString; Index,Size: SizeInt);
  459. Function StringOfChar(c : char;l : SizeInt) : AnsiString;
  460. function upcase(const s : ansistring) : ansistring;
  461. function lowercase(const s : ansistring) : ansistring;
  462. {****************************************************************************
  463. WideString Handling
  464. ****************************************************************************}
  465. {$ifdef HASWIDESTRING}
  466. {$i wstringh.inc}
  467. {$endif HASWIDESTRING}
  468. {****************************************************************************
  469. Untyped File Management
  470. ****************************************************************************}
  471. Procedure Assign(Var f:File;const Name:string);
  472. Procedure Assign(Var f:File;p:pchar);
  473. Procedure Assign(Var f:File;c:char);
  474. Procedure Rewrite(Var f:File;l:Longint);
  475. Procedure Rewrite(Var f:File);
  476. Procedure Reset(Var f:File;l:Longint);
  477. Procedure Reset(Var f:File);
  478. Procedure Close(Var f:File);
  479. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  480. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  481. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  482. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  483. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  484. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  485. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  486. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  487. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  488. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  489. Function FilePos(Var f:File):Longint;
  490. Function FileSize(Var f:File):Longint;
  491. Procedure Seek(Var f:File;Pos:Longint);
  492. Function EOF(Var f:File):Boolean;
  493. Procedure Erase(Var f:File);
  494. Procedure Rename(Var f:File;const s:string);
  495. Procedure Rename(Var f:File;p:pchar);
  496. Procedure Rename(Var f:File;c:char);
  497. Procedure Truncate (Var F:File);
  498. {****************************************************************************
  499. Typed File Management
  500. ****************************************************************************}
  501. Procedure Assign(Var f:TypedFile;const Name:string);
  502. Procedure Assign(Var f:TypedFile;p:pchar);
  503. Procedure Assign(Var f:TypedFile;c:char);
  504. {$ifdef INTERNCONSTINTF}
  505. Procedure Reset(var f : TypedFile); [INTERNPROC: fpc_in_Reset_TypedFile];
  506. Procedure Rewrite(var f : TypedFile); [INTERNPROC: fpc_in_Rewrite_TypedFile];
  507. {$else}
  508. Procedure Rewrite(Var f:TypedFile);
  509. Procedure Reset(Var f:TypedFile);
  510. {$endif}
  511. {****************************************************************************
  512. Text File Management
  513. ****************************************************************************}
  514. Procedure Assign(Var t:Text;const s:string);
  515. Procedure Assign(Var t:Text;p:pchar);
  516. Procedure Assign(Var t:Text;c:char);
  517. Procedure Close(Var t:Text);
  518. Procedure Rewrite(Var t:Text);
  519. Procedure Reset(Var t:Text);
  520. Procedure Append(Var t:Text);
  521. Procedure Flush(Var t:Text);
  522. Procedure Erase(Var t:Text);
  523. Procedure Rename(Var t:Text;const s:string);
  524. Procedure Rename(Var t:Text;p:pchar);
  525. Procedure Rename(Var t:Text;c:char);
  526. Function EOF(Var t:Text):Boolean;
  527. Function EOF:Boolean;
  528. Function EOLn(Var t:Text):Boolean;
  529. Function EOLn:Boolean;
  530. Function SeekEOLn (Var t:Text):Boolean;
  531. Function SeekEOF (Var t:Text):Boolean;
  532. Function SeekEOLn:Boolean;
  533. Function SeekEOF:Boolean;
  534. Procedure SetTextBuf(Var f:Text; Var Buf);{$ifdef INTERNCONSTINTF}[INTERNPROC:fpc_in_settextbuf_file_x];{$endif}
  535. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  536. Procedure SetTextLineEnding(Var f:Text; Ending:string);
  537. {****************************************************************************
  538. Directory Management
  539. ****************************************************************************}
  540. Procedure chdir(const s:string);
  541. Procedure mkdir(const s:string);
  542. Procedure rmdir(const s:string);
  543. Procedure getdir(drivenr:byte;Var dir:shortstring);
  544. Procedure getdir(drivenr:byte;Var dir:ansistring);
  545. {*****************************************************************************
  546. Miscellaneous
  547. *****************************************************************************}
  548. { os independent calls to allow backtraces }
  549. function get_frame:pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  550. function get_caller_addr(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  551. function get_caller_frame(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  552. Function IOResult:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  553. Function Sptr:Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}
  554. Function GetProcessID:SizeUInt;
  555. Function GetThreadID:SizeUInt;
  556. {*****************************************************************************
  557. Init / Exit / ExitProc
  558. *****************************************************************************}
  559. Function Paramcount:Longint;
  560. Function ParamStr(l:Longint):string;
  561. Procedure Dump_Stack(var f : text;bp:pointer);
  562. Procedure RunError(w:Word);
  563. Procedure RunError;{$ifdef SYSTEMINLINE}inline;{$endif}
  564. Procedure halt(errnum:byte);
  565. Procedure AddExitProc(Proc:TProcedure);
  566. Procedure halt;{$ifdef SYSTEMINLINE}inline;{$endif}
  567. { Need to be exported for threads unit }
  568. Procedure SysInitExceptions;
  569. procedure SysInitStdIO;
  570. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  571. {*****************************************************************************
  572. Abstract/Assert/Error Handling
  573. *****************************************************************************}
  574. function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
  575. Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
  576. Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
  577. procedure AbstractError;external name 'FPC_ABSTRACTERROR';
  578. Function SysBackTraceStr(Addr:Pointer): ShortString;
  579. Procedure SysAssert(Const Msg,FName:ShortString;LineNo:Longint;ErrorAddr:Pointer);
  580. { Error handlers }
  581. Type
  582. TBackTraceStrFunc = Function (Addr: Pointer): ShortString;
  583. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  584. TAbstractErrorProc = Procedure;
  585. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno:longint;erroraddr:pointer);
  586. const
  587. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  588. ErrorProc : TErrorProc = nil;
  589. AbstractErrorProc : TAbstractErrorProc = nil;
  590. AssertErrorProc : TAssertErrorProc = @SysAssert;
  591. {*****************************************************************************
  592. SetJmp/LongJmp
  593. *****************************************************************************}
  594. {$i setjumph.inc}
  595. {*****************************************************************************
  596. Object Pascal support
  597. *****************************************************************************}
  598. {$i objpash.inc}
  599. {*****************************************************************************
  600. Variant support
  601. *****************************************************************************}
  602. {$ifdef HASVARIANT}
  603. {$i varianth.inc}
  604. {$endif HASVARIANT}
  605. {*****************************************************************************
  606. Internal helper routines support
  607. *****************************************************************************}
  608. {$i dynarrh.inc}
  609. {$i compproc.inc}
  610. {*****************************************************************************
  611. Heap
  612. *****************************************************************************}
  613. {$i heaph.inc}
  614. {*****************************************************************************
  615. Thread support
  616. *****************************************************************************}
  617. { Generic threadmanager }
  618. {$i threadh.inc}
  619. {*****************************************************************************
  620. FPDoc phony declarations.
  621. *****************************************************************************}
  622. {$ifdef fpdocsystem}
  623. {$i system.fpd}
  624. {$endif}
  625. {
  626. $Log$
  627. Revision 1.117 2005-02-06 20:35:54 florian
  628. + InitProc
  629. Revision 1.116 2005/02/06 11:20:52 peter
  630. * threading in system unit
  631. * removed systhrds unit
  632. Revision 1.115 2005/02/05 10:47:38 florian
  633. * fixed previous commit
  634. Revision 1.114 2005/02/05 10:07:21 florian
  635. * map farpointer to pointer on platforms not having farpointers
  636. Revision 1.113 2005/02/01 20:22:49 florian
  637. * improved widestring infrastructure manager
  638. Revision 1.112 2005/01/24 18:03:19 peter
  639. * pinteger in non-delphi/objfpc mode is psmallint
  640. Revision 1.111 2004/12/05 14:36:37 hajny
  641. + GetProcessID added
  642. Revision 1.110 2004/11/26 22:26:30 peter
  643. * internconst for ptr()
  644. Revision 1.109 2004/11/22 22:48:10 michael
  645. + Added phony documentation declarations
  646. Revision 1.108 2004/11/17 22:19:04 peter
  647. internconst, internproc and some external declarations moved to interface
  648. Revision 1.107 2004/11/09 23:10:22 peter
  649. * use helper call to retrieve address of input/output to reduce
  650. code that is generated in the main program for loading the
  651. threadvar
  652. Revision 1.106 2004/11/04 09:32:31 peter
  653. ErrOutput added
  654. Revision 1.105 2004/10/30 20:49:10 marco
  655. * arraytostring added
  656. Revision 1.104 2004/10/14 17:39:33 florian
  657. + added system.align
  658. + threadvars are now aligned
  659. Revision 1.103 2004/10/09 21:00:46 jonas
  660. + cgenmath with libc math functions. Faster than the routines in genmath
  661. and also have full double support (exp() only has support for values in
  662. the single range in genmath, for example). Used in FPC_USE_LIBC is
  663. defined
  664. * several fixes to allow compilation with -dHASINLINE, but internalerrors
  665. because of missing support for inlining assembler code
  666. Revision 1.102 2004/09/22 05:56:11 hajny
  667. * compilation fix
  668. Revision 1.101 2004/09/21 23:43:26 hajny
  669. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  670. Revision 1.100 2004/09/21 15:04:22 peter
  671. * AnsiChar is equivalent of Char, use only type renamings
  672. Revision 1.99 2004/08/29 10:23:12 peter
  673. no message
  674. Revision 1.98 2004/07/18 20:21:44 florian
  675. + several unicode (to/from utf-8 conversion) stuff added
  676. * some longint -> SizeInt changes
  677. Revision 1.97 2004/07/07 15:15:40 daniel
  678. * Add inline directive to sysresetfpu
  679. Revision 1.96 2004/07/03 21:50:31 daniel
  680. * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  681. longer necessary
  682. Revision 1.95 2004/06/11 19:21:53 florian
  683. * fixed wrong commit
  684. Revision 1.94 2004/06/11 13:45:33 florian
  685. * fixed arm system unit compilation
  686. Revision 1.93 2004/05/30 16:51:38 peter
  687. * sparc need software shl shr
  688. Revision 1.92 2004/05/05 21:26:34 florian
  689. * some m68k and amiga related stuff fixed
  690. Revision 1.91 2004/05/01 23:55:18 peter
  691. * replace strlenint with sizeint
  692. Revision 1.90 2004/05/01 20:52:50 peter
  693. * ValSInt fixed for 64 bit
  694. Revision 1.89 2004/04/29 18:59:43 peter
  695. * str() helpers now also use valint/valuint
  696. * int64/qword helpers disabled for cpu64
  697. Revision 1.88 2004/04/22 17:10:38 peter
  698. * random(int64) added
  699. Revision 1.87 2004/03/23 22:35:45 peter
  700. * new compiler has smallint,longint,word internal defined
  701. Revision 1.86 2004/02/20 22:15:16 florian
  702. + x86_64 dependend sysutils part added
  703. * some 64 bit adaptions
  704. Revision 1.85 2004/02/20 11:01:20 daniel
  705. * Applied
  706. Revision 1.84 2004/02/02 20:39:27 florian
  707. + added prefetch(const mem)
  708. Revision 1.83 2004/01/26 11:48:24 florian
  709. * compilation on arm fixed
  710. Revision 1.82 2004/01/20 23:13:53 hajny
  711. * ExecuteProcess fixes, ProcessID and ThreadID added
  712. Revision 1.81 2003/12/29 19:24:12 florian
  713. + introduced PtrInt and PtrUInt
  714. * made strscan 64 bit safe
  715. Revision 1.80 2003/11/29 17:27:05 michael
  716. + Added overloaded version of SetWideStringManager without old parameter
  717. Revision 1.79 2003/11/28 20:36:13 michael
  718. + Added WideStringManager
  719. Revision 1.78 2003/11/15 19:01:27 florian
  720. * fixed rtl to work with the integrated fpc ppc assembler reader
  721. Revision 1.77 2003/11/03 09:42:28 marco
  722. * Peter's Cardinal<->Longint fixes patch
  723. Revision 1.76 2003/10/17 20:52:12 olle
  724. * Changed m68k to cpum68k, i386 to cpui386
  725. Revision 1.75 2003/10/16 15:43:13 peter
  726. * THandle is platform dependent
  727. Revision 1.74 2003/10/08 16:24:47 florian
  728. * fixed some variant issues
  729. * improved type declarations
  730. Revision 1.72 2003/09/04 16:07:31 florian
  731. * fixed qword_to_double conversion on powerpc
  732. Revision 1.71 2003/09/03 14:09:37 florian
  733. * arm fixes to the common rtl code
  734. * some generic math code fixed
  735. * ...
  736. Revision 1.70 2003/09/01 20:47:23 peter
  737. * pcomp added for sparc
  738. Revision 1.69 2003/05/01 08:05:23 florian
  739. * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
  740. Revision 1.68 2003/04/30 16:36:39 florian
  741. + support for generic pchar routines added
  742. + some basic rtl stuff for x86-64 added
  743. Revision 1.67 2003/04/25 21:09:44 peter
  744. * remove dos lf
  745. Revision 1.66 2003/04/23 22:46:41 florian
  746. + powerpc defines now pcomp as well
  747. Revision 1.65 2003/04/01 15:36:31 peter
  748. * make HResult unique type
  749. Revision 1.64 2003/03/17 14:30:11 peter
  750. * changed address parameter/return values to pointer instead
  751. of longint
  752. Revision 1.63 2003/01/13 14:37:11 florian
  753. * cpu defines fixed
  754. * ... = type ...; stuff reactived, should work now with 1.1
  755. Revision 1.62 2002/12/21 17:20:27 florian
  756. + some types for D6 compatibility added
  757. Revision 1.61 2002/12/15 22:33:12 peter
  758. * SetString(WideString,[PChar|PWideChar],Len) added
  759. Revision 1.60 2002/11/16 20:12:22 florian
  760. + sparc types added
  761. + UTF*/UCS* types added
  762. Revision 1.59 2002/10/14 19:39:17 peter
  763. * threads unit added for thread support
  764. Revision 1.58 2002/10/06 13:56:47 carl
  765. - remove stack checking for every target in system unit
  766. Revision 1.57 2002/10/02 18:21:51 peter
  767. * Copy() changed to internal function calling compilerprocs
  768. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  769. new copy functions
  770. Revision 1.56 2002/09/28 21:18:02 florian
  771. * map comp to int64 for the powerpc
  772. Revision 1.55 2002/09/26 21:50:37 florian
  773. + some WideString<->AnsiString conversion functions added
  774. Revision 1.54 2002/09/07 21:20:50 carl
  775. * cardinal -> longword
  776. - remove FPUInt64 variable
  777. Revision 1.53 2002/09/07 15:07:46 peter
  778. * old logs removed and tabs fixed
  779. Revision 1.52 2002/08/19 19:34:02 peter
  780. * SYSTEMINLINE define that will add inline directives for small
  781. functions and wrappers. This will be defined automaticly when
  782. the compiler defines the HASINLINE directive
  783. Revision 1.51 2002/08/06 20:53:38 michael
  784. + Added support for octal strings (using &)
  785. Revision 1.50 2002/07/26 22:46:06 florian
  786. * interface of system unit for Linux/PowerPC compiles
  787. Revision 1.49 2002/07/26 21:29:03 florian
  788. + powerpc type support
  789. Revision 1.48 2002/07/04 20:40:09 florian
  790. + some x86-64 support added
  791. Revision 1.47 2002/07/01 16:29:05 peter
  792. * sLineBreak changed to normal constant like Kylix
  793. Revision 1.46 2002/06/02 10:49:30 marco
  794. * Renamefest supports_double for FreeBSD too
  795. Revision 1.45 2002/04/21 15:51:51 carl
  796. * StackError is now a typed constant
  797. + $S can be used under unix
  798. Revision 1.44 2002/04/12 17:35:24 carl
  799. - removed unused variable
  800. Revision 1.43 2002/01/25 17:41:05 peter
  801. * moved array types to objpas unit
  802. Revision 1.42 2002/01/25 17:39:35 peter
  803. * array types added
  804. Revision 1.41 2002/01/24 18:27:06 peter
  805. * lowercase() overloaded
  806. Revision 1.40 2002/01/24 12:33:53 jonas
  807. * adapted ranges of native types to int64 (e.g. high cardinal is no
  808. longer longint($ffffffff), but just $fffffff in psystem)
  809. * small additional fix in 64bit rangecheck code generation for 32 bit
  810. processors
  811. * adaption of ranges required the matching talgorithm used for selecting
  812. which overloaded procedure to call to be adapted. It should now always
  813. select the closest match for ordinal parameters.
  814. + inttostr(qword) in sysstr.inc/sysstrh.inc
  815. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  816. fixes were required to be able to add them)
  817. * is_in_limit() moved from ncal to types unit, should always be used
  818. instead of direct comparisons of low/high values of orddefs because
  819. qword is a special case
  820. }