systemh.inc 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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. InitProc : Pointer = nil;
  294. var
  295. ExitCode : Word; public name 'operatingsystem_result';
  296. RandSeed : Cardinal;
  297. { Delphi compatibility }
  298. IsLibrary : boolean;
  299. IsConsole : boolean;
  300. { Threading support }
  301. fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
  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. {****************************************************************************
  388. Addr/Pointer Handling
  389. ****************************************************************************}
  390. Function ptr(sel,off:Longint):farpointer;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  391. Function Cseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  392. Function Dseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  393. Function Sseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  394. {****************************************************************************
  395. PChar and String Handling
  396. ****************************************************************************}
  397. function strpas(p:pchar):shortstring;external name 'FPC_PCHAR_TO_SHORTSTR';
  398. function strlen(p:pchar):longint;external name 'FPC_PCHAR_LENGTH';
  399. { Shortstring functions }
  400. {$ifndef INTERNSETLENGTH}
  401. Procedure SetLength (Var S:ShortString;len:SizeInt);
  402. {$endif INTERNSETLENGTH}
  403. {$ifndef InternCopy}
  404. Function Copy(const s:shortstring;index:SizeInt;count:SizeInt):shortstring;
  405. {$endif interncopy}
  406. Procedure Delete(Var s:shortstring;index:SizeInt;count:SizeInt);
  407. Procedure Insert(const source:shortstring;Var s:shortstring;index:SizeInt);
  408. Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
  409. Function Pos(const substr:shortstring;const s:shortstring):SizeInt;
  410. Function Pos(C:Char;const s:shortstring):SizeInt;
  411. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
  412. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
  413. {$ifndef INTERNLENGTH}
  414. Function Length(s:string):byte;
  415. {$endif INTERNLENGTH}
  416. Function upCase(const s:shortstring):shortstring;
  417. Function lowerCase(const s:shortstring):shortstring; overload;
  418. Function Space(b:byte):shortstring;
  419. Function hexStr(Val:Longint;cnt:byte):shortstring;
  420. Function OctStr(Val:Longint;cnt:byte):shortstring;
  421. Function binStr(Val:Longint;cnt:byte):shortstring;
  422. Function hexStr(Val:int64;cnt:byte):shortstring;
  423. Function OctStr(Val:int64;cnt:byte):shortstring;
  424. Function binStr(Val:int64;cnt:byte):shortstring;
  425. { Char functions }
  426. {$ifdef INTERNCONSTINTF}
  427. Function chr(b : byte) : Char; [INTERNPROC: fpc_in_chr_byte];
  428. {$else}
  429. Function Chr(b:byte):Char;
  430. {$endif}
  431. Function upCase(c:Char):Char;
  432. Function lowerCase(c:Char):Char; overload;
  433. {$ifndef InternCopy}
  434. function copy(c:char;index : SizeInt;count : SizeInt): shortstring;
  435. {$endif interncopy}
  436. function pos(const substr : shortstring;c:char): SizeInt;
  437. {$ifndef INTERNLENGTH}
  438. function length(c:char):byte;
  439. {$endif INTERNLENGTH}
  440. {****************************************************************************
  441. AnsiString Handling
  442. ****************************************************************************}
  443. {$ifndef INTERNSETLENGTH}
  444. Procedure SetLength (Var S : AnsiString; l : SizeInt);
  445. {$endif INTERNSETLENGTH}
  446. Procedure UniqueString(Var S : AnsiString);external name 'FPC_ANSISTR_UNIQUE';
  447. {$ifndef INTERNLENGTH}
  448. Function Length (Const S : AnsiString) : SizeInt;
  449. {$endif INTERNLENGTH}
  450. {$ifndef InternCopy}
  451. Function Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;
  452. {$endif interncopy}
  453. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
  454. Function Pos (c : Char; Const s : AnsiString) : SizeInt;
  455. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : SizeInt);
  456. Procedure Delete (Var S : AnsiString; Index,Size: SizeInt);
  457. Function StringOfChar(c : char;l : SizeInt) : AnsiString;
  458. function upcase(const s : ansistring) : ansistring;
  459. function lowercase(const s : ansistring) : ansistring;
  460. {****************************************************************************
  461. WideString Handling
  462. ****************************************************************************}
  463. {$ifdef HASWIDESTRING}
  464. {$i wstringh.inc}
  465. {$endif HASWIDESTRING}
  466. {****************************************************************************
  467. Untyped File Management
  468. ****************************************************************************}
  469. Procedure Assign(Var f:File;const Name:string);
  470. Procedure Assign(Var f:File;p:pchar);
  471. Procedure Assign(Var f:File;c:char);
  472. Procedure Rewrite(Var f:File;l:Longint);
  473. Procedure Rewrite(Var f:File);
  474. Procedure Reset(Var f:File;l:Longint);
  475. Procedure Reset(Var f:File);
  476. Procedure Close(Var f:File);
  477. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  478. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  479. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  480. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  481. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  482. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  483. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  484. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  485. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  486. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  487. Function FilePos(Var f:File):Longint;
  488. Function FileSize(Var f:File):Longint;
  489. Procedure Seek(Var f:File;Pos:Longint);
  490. Function EOF(Var f:File):Boolean;
  491. Procedure Erase(Var f:File);
  492. Procedure Rename(Var f:File;const s:string);
  493. Procedure Rename(Var f:File;p:pchar);
  494. Procedure Rename(Var f:File;c:char);
  495. Procedure Truncate (Var F:File);
  496. {****************************************************************************
  497. Typed File Management
  498. ****************************************************************************}
  499. Procedure Assign(Var f:TypedFile;const Name:string);
  500. Procedure Assign(Var f:TypedFile;p:pchar);
  501. Procedure Assign(Var f:TypedFile;c:char);
  502. {$ifdef INTERNCONSTINTF}
  503. Procedure Reset(var f : TypedFile); [INTERNPROC: fpc_in_Reset_TypedFile];
  504. Procedure Rewrite(var f : TypedFile); [INTERNPROC: fpc_in_Rewrite_TypedFile];
  505. {$else}
  506. Procedure Rewrite(Var f:TypedFile);
  507. Procedure Reset(Var f:TypedFile);
  508. {$endif}
  509. {****************************************************************************
  510. Text File Management
  511. ****************************************************************************}
  512. Procedure Assign(Var t:Text;const s:string);
  513. Procedure Assign(Var t:Text;p:pchar);
  514. Procedure Assign(Var t:Text;c:char);
  515. Procedure Close(Var t:Text);
  516. Procedure Rewrite(Var t:Text);
  517. Procedure Reset(Var t:Text);
  518. Procedure Append(Var t:Text);
  519. Procedure Flush(Var t:Text);
  520. Procedure Erase(Var t:Text);
  521. Procedure Rename(Var t:Text;const s:string);
  522. Procedure Rename(Var t:Text;p:pchar);
  523. Procedure Rename(Var t:Text;c:char);
  524. Function EOF(Var t:Text):Boolean;
  525. Function EOF:Boolean;
  526. Function EOLn(Var t:Text):Boolean;
  527. Function EOLn:Boolean;
  528. Function SeekEOLn (Var t:Text):Boolean;
  529. Function SeekEOF (Var t:Text):Boolean;
  530. Function SeekEOLn:Boolean;
  531. Function SeekEOF:Boolean;
  532. Procedure SetTextBuf(Var f:Text; Var Buf);{$ifdef INTERNCONSTINTF}[INTERNPROC:fpc_in_settextbuf_file_x];{$endif}
  533. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  534. Procedure SetTextLineEnding(Var f:Text; Ending:string);
  535. {****************************************************************************
  536. Directory Management
  537. ****************************************************************************}
  538. Procedure chdir(const s:string);
  539. Procedure mkdir(const s:string);
  540. Procedure rmdir(const s:string);
  541. Procedure getdir(drivenr:byte;Var dir:shortstring);
  542. Procedure getdir(drivenr:byte;Var dir:ansistring);
  543. {*****************************************************************************
  544. Miscellaneous
  545. *****************************************************************************}
  546. { os independent calls to allow backtraces }
  547. function get_frame:pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  548. function get_caller_addr(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  549. function get_caller_frame(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  550. Function IOResult:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  551. Function Sptr:Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}
  552. Function GetProcessID:SizeUInt;
  553. Function GetThreadID:SizeUInt;
  554. {*****************************************************************************
  555. Init / Exit / ExitProc
  556. *****************************************************************************}
  557. Function Paramcount:Longint;
  558. Function ParamStr(l:Longint):string;
  559. Procedure Dump_Stack(var f : text;bp:pointer);
  560. Procedure RunError(w:Word);
  561. Procedure RunError;{$ifdef SYSTEMINLINE}inline;{$endif}
  562. Procedure halt(errnum:byte);
  563. Procedure AddExitProc(Proc:TProcedure);
  564. Procedure halt;{$ifdef SYSTEMINLINE}inline;{$endif}
  565. { Need to be exported for threads unit }
  566. Procedure SysInitExceptions;
  567. procedure SysInitStdIO;
  568. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  569. {*****************************************************************************
  570. Abstract/Assert/Error Handling
  571. *****************************************************************************}
  572. function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
  573. Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
  574. Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
  575. procedure AbstractError;external name 'FPC_ABSTRACTERROR';
  576. Function SysBackTraceStr(Addr:Pointer): ShortString;
  577. Procedure SysAssert(Const Msg,FName:ShortString;LineNo:Longint;ErrorAddr:Pointer);
  578. { Error handlers }
  579. Type
  580. TBackTraceStrFunc = Function (Addr: Pointer): ShortString;
  581. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  582. TAbstractErrorProc = Procedure;
  583. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno:longint;erroraddr:pointer);
  584. const
  585. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  586. ErrorProc : TErrorProc = nil;
  587. AbstractErrorProc : TAbstractErrorProc = nil;
  588. AssertErrorProc : TAssertErrorProc = @SysAssert;
  589. {*****************************************************************************
  590. SetJmp/LongJmp
  591. *****************************************************************************}
  592. {$i setjumph.inc}
  593. {*****************************************************************************
  594. Object Pascal support
  595. *****************************************************************************}
  596. {$i objpash.inc}
  597. {*****************************************************************************
  598. Variant support
  599. *****************************************************************************}
  600. {$ifdef HASVARIANT}
  601. {$i varianth.inc}
  602. {$endif HASVARIANT}
  603. {*****************************************************************************
  604. Internal helper routines support
  605. *****************************************************************************}
  606. {$i dynarrh.inc}
  607. {$i compproc.inc}
  608. {*****************************************************************************
  609. Heap
  610. *****************************************************************************}
  611. {$i heaph.inc}
  612. {*****************************************************************************
  613. Thread support
  614. *****************************************************************************}
  615. { Generic threadmanager }
  616. {$i threadh.inc}
  617. {*****************************************************************************
  618. FPDoc phony declarations.
  619. *****************************************************************************}
  620. {$ifdef fpdocsystem}
  621. {$i system.fpd}
  622. {$endif}
  623. {
  624. $Log$
  625. Revision 1.119 2005-02-08 20:25:28 florian
  626. - killed power from system unit
  627. * move operator ** to math unit
  628. Revision 1.118 2005/02/06 20:37:31 florian
  629. * InitProc gets an inital value
  630. Revision 1.117 2005/02/06 20:35:54 florian
  631. + InitProc
  632. Revision 1.116 2005/02/06 11:20:52 peter
  633. * threading in system unit
  634. * removed systhrds unit
  635. Revision 1.115 2005/02/05 10:47:38 florian
  636. * fixed previous commit
  637. Revision 1.114 2005/02/05 10:07:21 florian
  638. * map farpointer to pointer on platforms not having farpointers
  639. Revision 1.113 2005/02/01 20:22:49 florian
  640. * improved widestring infrastructure manager
  641. Revision 1.112 2005/01/24 18:03:19 peter
  642. * pinteger in non-delphi/objfpc mode is psmallint
  643. Revision 1.111 2004/12/05 14:36:37 hajny
  644. + GetProcessID added
  645. Revision 1.110 2004/11/26 22:26:30 peter
  646. * internconst for ptr()
  647. Revision 1.109 2004/11/22 22:48:10 michael
  648. + Added phony documentation declarations
  649. Revision 1.108 2004/11/17 22:19:04 peter
  650. internconst, internproc and some external declarations moved to interface
  651. Revision 1.107 2004/11/09 23:10:22 peter
  652. * use helper call to retrieve address of input/output to reduce
  653. code that is generated in the main program for loading the
  654. threadvar
  655. Revision 1.106 2004/11/04 09:32:31 peter
  656. ErrOutput added
  657. Revision 1.105 2004/10/30 20:49:10 marco
  658. * arraytostring added
  659. Revision 1.104 2004/10/14 17:39:33 florian
  660. + added system.align
  661. + threadvars are now aligned
  662. Revision 1.103 2004/10/09 21:00:46 jonas
  663. + cgenmath with libc math functions. Faster than the routines in genmath
  664. and also have full double support (exp() only has support for values in
  665. the single range in genmath, for example). Used in FPC_USE_LIBC is
  666. defined
  667. * several fixes to allow compilation with -dHASINLINE, but internalerrors
  668. because of missing support for inlining assembler code
  669. Revision 1.102 2004/09/22 05:56:11 hajny
  670. * compilation fix
  671. Revision 1.101 2004/09/21 23:43:26 hajny
  672. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  673. Revision 1.100 2004/09/21 15:04:22 peter
  674. * AnsiChar is equivalent of Char, use only type renamings
  675. Revision 1.99 2004/08/29 10:23:12 peter
  676. no message
  677. Revision 1.98 2004/07/18 20:21:44 florian
  678. + several unicode (to/from utf-8 conversion) stuff added
  679. * some longint -> SizeInt changes
  680. Revision 1.97 2004/07/07 15:15:40 daniel
  681. * Add inline directive to sysresetfpu
  682. Revision 1.96 2004/07/03 21:50:31 daniel
  683. * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  684. longer necessary
  685. Revision 1.95 2004/06/11 19:21:53 florian
  686. * fixed wrong commit
  687. Revision 1.94 2004/06/11 13:45:33 florian
  688. * fixed arm system unit compilation
  689. Revision 1.93 2004/05/30 16:51:38 peter
  690. * sparc need software shl shr
  691. Revision 1.92 2004/05/05 21:26:34 florian
  692. * some m68k and amiga related stuff fixed
  693. Revision 1.91 2004/05/01 23:55:18 peter
  694. * replace strlenint with sizeint
  695. Revision 1.90 2004/05/01 20:52:50 peter
  696. * ValSInt fixed for 64 bit
  697. Revision 1.89 2004/04/29 18:59:43 peter
  698. * str() helpers now also use valint/valuint
  699. * int64/qword helpers disabled for cpu64
  700. Revision 1.88 2004/04/22 17:10:38 peter
  701. * random(int64) added
  702. Revision 1.87 2004/03/23 22:35:45 peter
  703. * new compiler has smallint,longint,word internal defined
  704. Revision 1.86 2004/02/20 22:15:16 florian
  705. + x86_64 dependend sysutils part added
  706. * some 64 bit adaptions
  707. Revision 1.85 2004/02/20 11:01:20 daniel
  708. * Applied
  709. Revision 1.84 2004/02/02 20:39:27 florian
  710. + added prefetch(const mem)
  711. Revision 1.83 2004/01/26 11:48:24 florian
  712. * compilation on arm fixed
  713. Revision 1.82 2004/01/20 23:13:53 hajny
  714. * ExecuteProcess fixes, ProcessID and ThreadID added
  715. Revision 1.81 2003/12/29 19:24:12 florian
  716. + introduced PtrInt and PtrUInt
  717. * made strscan 64 bit safe
  718. Revision 1.80 2003/11/29 17:27:05 michael
  719. + Added overloaded version of SetWideStringManager without old parameter
  720. Revision 1.79 2003/11/28 20:36:13 michael
  721. + Added WideStringManager
  722. Revision 1.78 2003/11/15 19:01:27 florian
  723. * fixed rtl to work with the integrated fpc ppc assembler reader
  724. Revision 1.77 2003/11/03 09:42:28 marco
  725. * Peter's Cardinal<->Longint fixes patch
  726. Revision 1.76 2003/10/17 20:52:12 olle
  727. * Changed m68k to cpum68k, i386 to cpui386
  728. Revision 1.75 2003/10/16 15:43:13 peter
  729. * THandle is platform dependent
  730. Revision 1.74 2003/10/08 16:24:47 florian
  731. * fixed some variant issues
  732. * improved type declarations
  733. Revision 1.72 2003/09/04 16:07:31 florian
  734. * fixed qword_to_double conversion on powerpc
  735. Revision 1.71 2003/09/03 14:09:37 florian
  736. * arm fixes to the common rtl code
  737. * some generic math code fixed
  738. * ...
  739. Revision 1.70 2003/09/01 20:47:23 peter
  740. * pcomp added for sparc
  741. Revision 1.69 2003/05/01 08:05:23 florian
  742. * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
  743. Revision 1.68 2003/04/30 16:36:39 florian
  744. + support for generic pchar routines added
  745. + some basic rtl stuff for x86-64 added
  746. Revision 1.67 2003/04/25 21:09:44 peter
  747. * remove dos lf
  748. Revision 1.66 2003/04/23 22:46:41 florian
  749. + powerpc defines now pcomp as well
  750. Revision 1.65 2003/04/01 15:36:31 peter
  751. * make HResult unique type
  752. Revision 1.64 2003/03/17 14:30:11 peter
  753. * changed address parameter/return values to pointer instead
  754. of longint
  755. Revision 1.63 2003/01/13 14:37:11 florian
  756. * cpu defines fixed
  757. * ... = type ...; stuff reactived, should work now with 1.1
  758. Revision 1.62 2002/12/21 17:20:27 florian
  759. + some types for D6 compatibility added
  760. Revision 1.61 2002/12/15 22:33:12 peter
  761. * SetString(WideString,[PChar|PWideChar],Len) added
  762. Revision 1.60 2002/11/16 20:12:22 florian
  763. + sparc types added
  764. + UTF*/UCS* types added
  765. Revision 1.59 2002/10/14 19:39:17 peter
  766. * threads unit added for thread support
  767. Revision 1.58 2002/10/06 13:56:47 carl
  768. - remove stack checking for every target in system unit
  769. Revision 1.57 2002/10/02 18:21:51 peter
  770. * Copy() changed to internal function calling compilerprocs
  771. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  772. new copy functions
  773. Revision 1.56 2002/09/28 21:18:02 florian
  774. * map comp to int64 for the powerpc
  775. Revision 1.55 2002/09/26 21:50:37 florian
  776. + some WideString<->AnsiString conversion functions added
  777. Revision 1.54 2002/09/07 21:20:50 carl
  778. * cardinal -> longword
  779. - remove FPUInt64 variable
  780. Revision 1.53 2002/09/07 15:07:46 peter
  781. * old logs removed and tabs fixed
  782. Revision 1.52 2002/08/19 19:34:02 peter
  783. * SYSTEMINLINE define that will add inline directives for small
  784. functions and wrappers. This will be defined automaticly when
  785. the compiler defines the HASINLINE directive
  786. Revision 1.51 2002/08/06 20:53:38 michael
  787. + Added support for octal strings (using &)
  788. Revision 1.50 2002/07/26 22:46:06 florian
  789. * interface of system unit for Linux/PowerPC compiles
  790. Revision 1.49 2002/07/26 21:29:03 florian
  791. + powerpc type support
  792. Revision 1.48 2002/07/04 20:40:09 florian
  793. + some x86-64 support added
  794. Revision 1.47 2002/07/01 16:29:05 peter
  795. * sLineBreak changed to normal constant like Kylix
  796. Revision 1.46 2002/06/02 10:49:30 marco
  797. * Renamefest supports_double for FreeBSD too
  798. Revision 1.45 2002/04/21 15:51:51 carl
  799. * StackError is now a typed constant
  800. + $S can be used under unix
  801. Revision 1.44 2002/04/12 17:35:24 carl
  802. - removed unused variable
  803. Revision 1.43 2002/01/25 17:41:05 peter
  804. * moved array types to objpas unit
  805. Revision 1.42 2002/01/25 17:39:35 peter
  806. * array types added
  807. Revision 1.41 2002/01/24 18:27:06 peter
  808. * lowercase() overloaded
  809. Revision 1.40 2002/01/24 12:33:53 jonas
  810. * adapted ranges of native types to int64 (e.g. high cardinal is no
  811. longer longint($ffffffff), but just $fffffff in psystem)
  812. * small additional fix in 64bit rangecheck code generation for 32 bit
  813. processors
  814. * adaption of ranges required the matching talgorithm used for selecting
  815. which overloaded procedure to call to be adapted. It should now always
  816. select the closest match for ordinal parameters.
  817. + inttostr(qword) in sysstr.inc/sysstrh.inc
  818. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  819. fixes were required to be able to add them)
  820. * is_in_limit() moved from ncal to types unit, should always be used
  821. instead of direct comparisons of low/high values of orddefs because
  822. qword is a special case
  823. }