system.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 the Free Pascal development team
  4. Portions based on the Atari RTL for FPC 1.x
  5. Copyright (c) 1999-2000 by Carl Eric Codere
  6. member of the Free Pascal development team
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit System;
  14. {--------------------------------------------------------------------}
  15. { LEFT TO DO: }
  16. {--------------------------------------------------------------------}
  17. { o SBrk }
  18. { o Implement truncate }
  19. { o Implement paramstr(0) }
  20. {--------------------------------------------------------------------}
  21. interface
  22. {$I systemh.inc}
  23. {Platform specific information}
  24. const
  25. LineEnding = #13#10;
  26. LFNSupport = false;
  27. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  28. DirectorySeparator = '\';
  29. DriveSeparator = ':';
  30. ExtensionSeparator = '.';
  31. PathSeparator = ';';
  32. AllowDirectorySeparators : set of char = ['\','/'];
  33. AllowDriveSeparators : set of char = [':'];
  34. FileNameCaseSensitive = false;
  35. FileNameCasePreserving = false;
  36. maxExitCode = 255;
  37. MaxPathLen = 255;
  38. AllFilesMask = '*';
  39. sLineBreak = LineEnding;
  40. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  41. const
  42. UnusedHandle = $ffff;
  43. StdInputHandle = 0;
  44. StdOutputHandle = 1;
  45. StdErrorHandle = $ffff;
  46. var
  47. args: PChar;
  48. argc: LongInt;
  49. argv: PPChar;
  50. envp: PPChar;
  51. {$if defined(FPUSOFT)}
  52. {$define fpc_softfpu_interface}
  53. {$i softfpu.pp}
  54. {$undef fpc_softfpu_interface}
  55. {$endif defined(FPUSOFT)}
  56. implementation
  57. {$if defined(FPUSOFT)}
  58. {$define fpc_softfpu_implementation}
  59. {$i softfpu.pp}
  60. {$undef fpc_softfpu_implementation}
  61. { we get these functions and types from the softfpu code }
  62. {$define FPC_SYSTEM_HAS_float64}
  63. {$define FPC_SYSTEM_HAS_float32}
  64. {$define FPC_SYSTEM_HAS_flag}
  65. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  66. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  67. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  68. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  69. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  70. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  71. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  72. {$endif defined(FPUSOFT)}
  73. {$I system.inc}
  74. var
  75. basepage: PPD; external name '__base';
  76. function GetProcessID:SizeUInt;
  77. begin
  78. {$WARNING To be checked by platform maintainer}
  79. GetProcessID := 1;
  80. end;
  81. {$S-}
  82. (* procedure Stack_Check; assembler;
  83. { Check for local variable allocation }
  84. { On Entry -> d0 : size of local stack we are trying to allocate }
  85. asm
  86. XDEF STACKCHECK
  87. move.l sp,d1 { get value of stack pointer }
  88. sub.l d0,d1 { sp - stack_size }
  89. sub.l #2048,d1
  90. cmp.l __BREAK,d1
  91. bgt @st1nosweat
  92. move.l #202,d0
  93. jsr HALT_ERROR
  94. @st1nosweat:
  95. end;*)
  96. Function GetParamCount(const p: pchar): longint;
  97. var
  98. i: word;
  99. count: word;
  100. Begin
  101. i:=0;
  102. count:=0;
  103. while p[count] <> #0 do
  104. Begin
  105. if (p[count] <> ' ') and (p[count] <> #9) and (p[count] <> #0) then
  106. Begin
  107. i:=i+1;
  108. while (p[count] <> ' ') and (p[count] <> #9) and (p[count] <> #0) do
  109. count:=count+1;
  110. end;
  111. if p[count] = #0 then break;
  112. count:=count+1;
  113. end;
  114. GetParamCount:=longint(i);
  115. end;
  116. Function GetParam(index: word; const p : pchar): string;
  117. { On Entry: index = string index to correct parameter }
  118. { On exit: = correct character index into pchar array }
  119. { Returns correct index to command line argument }
  120. var
  121. count: word;
  122. localindex: word;
  123. l: byte;
  124. temp: string;
  125. Begin
  126. temp:='';
  127. count := 0;
  128. { first index is one }
  129. localindex := 1;
  130. l:=0;
  131. While p[count] <> #0 do
  132. Begin
  133. if (p[count] <> ' ') and (p[count] <> #9) then
  134. Begin
  135. if localindex = index then
  136. Begin
  137. while (p[count] <> #0) and (p[count] <> ' ') and (p[count] <> #9) and (l < 256) do
  138. Begin
  139. temp:=temp+p[count];
  140. l:=l+1;
  141. count:=count+1;
  142. end;
  143. temp[0]:=char(l);
  144. GetParam:=temp;
  145. exit;
  146. end;
  147. { Point to next argument in list }
  148. while (p[count] <> #0) and (p[count] <> ' ') and (p[count] <> #9) do
  149. Begin
  150. count:=count+1;
  151. end;
  152. localindex:=localindex+1;
  153. end;
  154. if p[count] = #0 then break;
  155. count:=count+1;
  156. end;
  157. GetParam:=temp;
  158. end;
  159. function paramstr(l : longint) : string;
  160. var
  161. p : pchar;
  162. begin
  163. {$WARNING Implement query of current command name}
  164. { ... as ParamStr(0) }
  165. if (l>0) and (l<=paramcount) then
  166. begin
  167. p:=args;
  168. paramstr:=GetParam(word(l),p);
  169. end
  170. else
  171. paramstr:='';
  172. end;
  173. function paramcount : longint;
  174. Begin
  175. paramcount := argc;
  176. end;
  177. procedure SysInitParamsAndEnv;
  178. begin
  179. args:=@basepage^.p_cmdlin;
  180. argc:=GetParamCount(args);
  181. end;
  182. { This routine is used to grow the heap. }
  183. { But here we do a trick, we say that the }
  184. { heap cannot be regrown! }
  185. function sbrk( size: longint): pointer;
  186. { on exit nil = if fails. }
  187. Begin
  188. sbrk:=nil;
  189. end;
  190. procedure randomize;
  191. begin
  192. {$WARNING: randseed initial value is 24bit}
  193. randseed:=xbios_random;
  194. end;
  195. {*****************************************************************************
  196. System Dependent Exit code
  197. *****************************************************************************}
  198. Procedure system_exit;
  199. begin
  200. gemdos_pterm(ExitCode);
  201. end;
  202. {*****************************************************************************
  203. SystemUnit Initialization
  204. *****************************************************************************}
  205. procedure SysInitStdIO;
  206. begin
  207. OpenStdIO(Input,fmInput,StdInputHandle);
  208. OpenStdIO(Output,fmOutput,StdOutputHandle);
  209. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  210. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  211. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  212. end;
  213. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  214. begin
  215. CheckInitialStkLen := StkLen;
  216. end;
  217. begin
  218. StackLength := CheckInitialStkLen (InitialStkLen);
  219. { Initialize ExitProc }
  220. ExitProc:=Nil;
  221. { Setup heap }
  222. InitHeap;
  223. SysInitExceptions;
  224. InitUnicodeStringManager;
  225. { Setup stdin, stdout and stderr }
  226. SysInitStdIO;
  227. { Reset IO Error }
  228. InOutRes:=0;
  229. { Setup command line arguments }
  230. SysInitParamsAndEnv;
  231. {$ifdef FPC_HAS_FEATURE_THREADING}
  232. InitSystemThreads;
  233. {$endif}
  234. end.