system.pp 6.6 KB

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