system.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Florian Klaempfl
  4. member of the Free Pascal development team.
  5. System unit for embedded systems
  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. Unit System;
  13. {*****************************************************************************}
  14. interface
  15. {*****************************************************************************}
  16. {$define FPC_IS_SYSTEM}
  17. {$define HAS_CMDLINE}
  18. {$define USE_NOTHREADMANAGER}
  19. { Do not use standard memory manager }
  20. {$define HAS_MEMORYMANAGER}
  21. {$I check.inc}
  22. {$I systemh.inc}
  23. const
  24. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  25. LineEnding = #10;
  26. {$endif FPC_HAS_FEATURE_TEXTIO}
  27. {$ifdef FPC_HAS_FEATURE_FILEIO}
  28. LFNSupport = true;
  29. DirectorySeparator = '/';
  30. DriveSeparator = ':';
  31. ExtensionSeparator = '.';
  32. PathSeparator = ':';
  33. AllowDirectorySeparators : set of char = ['\','/'];
  34. AllowDriveSeparators : set of char = [':'];
  35. {$endif FPC_HAS_FEATURE_FILEIO}
  36. { FileNameCaseSensitive is defined below! }
  37. {$ifdef FPC_HAS_FEATURE_EXITCODE}
  38. maxExitCode = 255;
  39. {$endif FPC_HAS_FEATURE_EXITCODE}
  40. {$ifdef FPC_HAS_FEATURE_FILEIO}
  41. MaxPathLen = 1024; // BSDs since 1993, Solaris 10, Darwin
  42. AllFilesMask = '*';
  43. UnusedHandle = -1;
  44. StdInputHandle = 0;
  45. StdOutputHandle = 1;
  46. StdErrorHandle = 2;
  47. FileNameCaseSensitive : boolean = true;
  48. {$endif FPC_HAS_FEATURE_FILEIO}
  49. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  50. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  51. sLineBreak = LineEnding;
  52. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  53. {$endif FPC_HAS_FEATURE_TEXTIO}
  54. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  55. var
  56. argc: LongInt = 0;
  57. argv: PPChar = nil;
  58. envp: PPChar = nil;
  59. cmdline: PChar = nil;
  60. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  61. {$ifndef FPUNONE}
  62. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  63. {$define fpc_softfpu_interface}
  64. {$i softfpu.pp}
  65. {$undef fpc_softfpu_interface}
  66. {$endif FPC_HAS_FEATURE_SOFTFPU}
  67. {$endif FPUNONE}
  68. {*****************************************************************************}
  69. implementation
  70. {*****************************************************************************}
  71. { Include ELF resources }
  72. const calculated_cmdline:Pchar=nil;
  73. {$ifndef FPUNONE}
  74. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  75. {$define fpc_softfpu_implementation}
  76. {$i softfpu.pp}
  77. {$undef fpc_softfpu_implementation}
  78. {$endif FPUNONE}
  79. { we get these functions and types from the softfpu code }
  80. {$define FPC_SYSTEM_HAS_float64}
  81. {$define FPC_SYSTEM_HAS_float32}
  82. {$define FPC_SYSTEM_HAS_flag}
  83. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  84. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  85. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  86. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  87. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  88. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  89. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  90. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  91. {$endif FPC_HAS_FEATURE_SOFTFPU}
  92. {$I system.inc}
  93. {*****************************************************************************
  94. Misc. System Dependent Functions
  95. *****************************************************************************}
  96. procedure haltproc(e:longint);cdecl;external name '_haltproc';
  97. procedure System_exit;
  98. begin
  99. {$ifdef FPC_HAS_FEATURE_EXITCODE}
  100. haltproc(ExitCode);
  101. {$else FPC_HAS_FEATURE_EXITCODE}
  102. haltproc(0);
  103. {$endif FPC_HAS_FEATURE_EXITCODE}
  104. End;
  105. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  106. function GetProcessID: SizeUInt;
  107. begin
  108. GetProcessID := 0;
  109. end;
  110. {$endif}
  111. {$ifdef FPC_HAS_FEATURE_RANDOM}
  112. Procedure Randomize;
  113. Begin
  114. RandSeed := 63458;
  115. End;
  116. {$endif FPC_HAS_FEATURE_RANDOM}
  117. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  118. Function ParamCount: Longint;
  119. Begin
  120. Paramcount:=argc-1
  121. End;
  122. function paramstr(l: longint) : string;
  123. begin
  124. if l=0 then
  125. begin
  126. paramstr := '';
  127. end
  128. else
  129. paramstr:=strpas(argv[l]);
  130. end;
  131. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  132. {*****************************************************************************
  133. SystemUnit Initialization
  134. *****************************************************************************}
  135. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  136. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;inline;
  137. begin
  138. result := stklen;
  139. end;
  140. var
  141. initialstkptr : Pointer; // external name '__stkptr';
  142. {$endif FPC_HAS_FEATURE_STACKCHECK}
  143. begin
  144. {$ifdef FPC_HAS_FEATURE_FPU}
  145. SysResetFPU;
  146. if not(IsLibrary) then
  147. SysInitFPU;
  148. {$endif FPC_HAS_FEATURE_FPU}
  149. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  150. IsConsole := TRUE;
  151. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  152. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  153. StackLength := CheckInitialStkLen(initialStkLen);
  154. StackBottom := initialstkptr - StackLength;
  155. {$endif FPC_HAS_FEATURE_STACKCHECK}
  156. {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}
  157. SysInitExceptions;
  158. {$endif FPC_HAS_FEATURE_EXCEPTIONS}
  159. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  160. { Reset IO Error }
  161. InOutRes:=0;
  162. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  163. {$ifdef FPC_HAS_FEATURE_THREADING}
  164. { threading }
  165. InitSystemThreads;
  166. {$endif FPC_HAS_FEATURE_THREADING}
  167. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  168. initvariantmanager;
  169. {$endif FPC_HAS_FEATURE_VARIANTS}
  170. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  171. // initunicodestringmanager;
  172. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  173. end.