system.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. {$define DISABLE_NO_THREAD_MANAGER}
  20. { Do not use standard memory manager }
  21. {$define HAS_MEMORYMANAGER}
  22. {$define FPC_ANSI_TEXTFILEREC}
  23. {$I check.inc}
  24. {$I systemh.inc}
  25. const
  26. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  27. LineEnding = #10;
  28. {$endif FPC_HAS_FEATURE_TEXTIO}
  29. {$ifdef FPC_HAS_FEATURE_FILEIO}
  30. LFNSupport = true;
  31. DirectorySeparator = '/';
  32. DriveSeparator = ':';
  33. ExtensionSeparator = '.';
  34. PathSeparator = ':';
  35. AllowDirectorySeparators : set of char = ['\','/'];
  36. AllowDriveSeparators : set of char = [':'];
  37. {$endif FPC_HAS_FEATURE_FILEIO}
  38. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  39. {$ifdef FPC_HAS_FEATURE_EXITCODE}
  40. maxExitCode = 255;
  41. {$endif FPC_HAS_FEATURE_EXITCODE}
  42. {$ifdef FPC_HAS_FEATURE_FILEIO}
  43. MaxPathLen = 1024; // BSDs since 1993, Solaris 10, Darwin
  44. AllFilesMask = '*';
  45. UnusedHandle = -1;
  46. StdInputHandle = 0;
  47. StdOutputHandle = 1;
  48. StdErrorHandle = 2;
  49. FileNameCaseSensitive : boolean = true;
  50. FileNameCasePreserving: boolean = true;
  51. {$endif FPC_HAS_FEATURE_FILEIO}
  52. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  53. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  54. sLineBreak = LineEnding;
  55. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCrLF;
  56. {$endif FPC_HAS_FEATURE_TEXTIO}
  57. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  58. var
  59. argc: LongInt = 0;
  60. argv: PPChar = nil;
  61. envp: PPChar = nil;
  62. cmdline: PChar = nil;
  63. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  64. {$ifndef FPUNONE}
  65. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  66. {$define fpc_softfpu_interface}
  67. {$i softfpu.pp}
  68. {$undef fpc_softfpu_interface}
  69. {$endif FPC_HAS_FEATURE_SOFTFPU}
  70. {$endif FPUNONE}
  71. {*****************************************************************************}
  72. implementation
  73. {*****************************************************************************}
  74. { Include ELF resources }
  75. const calculated_cmdline:Pchar=nil;
  76. {$ifndef FPUNONE}
  77. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  78. {$define fpc_softfpu_implementation}
  79. {$i softfpu.pp}
  80. {$undef fpc_softfpu_implementation}
  81. {$endif FPUNONE}
  82. { we get these functions and types from the softfpu code }
  83. {$define FPC_SYSTEM_HAS_float64}
  84. {$define FPC_SYSTEM_HAS_float32}
  85. {$define FPC_SYSTEM_HAS_flag}
  86. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  87. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  88. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  89. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  90. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  91. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  92. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  93. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  94. {$endif FPC_HAS_FEATURE_SOFTFPU}
  95. {$I system.inc}
  96. {*****************************************************************************
  97. Misc. System Dependent Functions
  98. *****************************************************************************}
  99. procedure haltproc(e:longint);cdecl;external name '_haltproc';
  100. procedure System_exit;
  101. begin
  102. {$ifdef FPC_HAS_FEATURE_EXITCODE}
  103. haltproc(ExitCode);
  104. {$else FPC_HAS_FEATURE_EXITCODE}
  105. haltproc(0);
  106. {$endif FPC_HAS_FEATURE_EXITCODE}
  107. End;
  108. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  109. function GetProcessID: SizeUInt;
  110. begin
  111. GetProcessID := 0;
  112. end;
  113. {$endif}
  114. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  115. Function ParamCount: Longint;
  116. Begin
  117. Paramcount:=argc-1
  118. End;
  119. function paramstr(l: longint) : string;
  120. begin
  121. paramstr := '';
  122. end;
  123. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  124. const
  125. QRAN_SHIFT = 15;
  126. QRAN_MASK = ((1 shl QRAN_SHIFT) - 1);
  127. QRAN_MAX = QRAN_MASK;
  128. QRAN_A = 1664525;
  129. QRAN_C = 1013904223;
  130. {$ifdef FPC_HAS_FEATURE_RANDOM}
  131. procedure randomize();
  132. begin
  133. RandSeed := 63458;
  134. end;
  135. procedure randomize(value: integer);
  136. begin
  137. RandSeed := value;
  138. end;
  139. function random(): integer;
  140. begin
  141. RandSeed := QRAN_A * RandSeed + QRAN_C;
  142. random := (RandSeed shr 16) and QRAN_MAX;
  143. end;
  144. function random(value: integer): integer;
  145. var
  146. a: integer;
  147. begin
  148. RandSeed := QRAN_A * RandSeed + QRAN_C;
  149. a := (RandSeed shr 16) and QRAN_MAX;
  150. random := (a * value) shr 15;
  151. end;
  152. {$endif FPC_HAS_FEATURE_RANDOM}
  153. {*****************************************************************************
  154. SystemUnit Initialization
  155. *****************************************************************************}
  156. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  157. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;inline;
  158. begin
  159. result := stklen;
  160. end;
  161. var
  162. initialstkptr : Pointer; // external name '__stkptr';
  163. {$endif FPC_HAS_FEATURE_STACKCHECK}
  164. begin
  165. { FPU (hard or soft) is initialized from fpc_cpuinit, which is included
  166. per-cpu unconditionally.
  167. SysResetFPU;
  168. if not(IsLibrary) then
  169. SysInitFPU;
  170. }
  171. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  172. IsConsole := TRUE;
  173. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  174. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  175. StackLength := CheckInitialStkLen(initialStkLen);
  176. StackBottom := initialstkptr - StackLength;
  177. {$endif FPC_HAS_FEATURE_STACKCHECK}
  178. {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}
  179. { SysInitExceptions initializes only ExceptObjectstack and ExceptAddrStack
  180. with nil since both are located in the bss section, they are zeroed at startup
  181. anyways so not calling SysInitExceptions saves some bytes for simple programs. Even for threaded
  182. programs this does not matter because in the main thread, the variables are located
  183. in bss
  184. SysInitExceptions;
  185. }
  186. {$endif FPC_HAS_FEATURE_EXCEPTIONS}
  187. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  188. { Reset IO Error }
  189. InOutRes:=0;
  190. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  191. {$ifdef FPC_HAS_FEATURE_THREADING}
  192. { threading }
  193. //InitSystemThreads; // Empty call for embedded anyway
  194. {$endif FPC_HAS_FEATURE_THREADING}
  195. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  196. // initunicodestringmanager;
  197. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  198. end.