system.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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: Pointer; external name '__ARGS'; { Defined in the startup code }
  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. function GetProcessID:SizeUInt;
  75. begin
  76. {$WARNING To be checked by platform maintainer}
  77. GetProcessID := 1;
  78. end;
  79. {$S-}
  80. (* procedure Stack_Check; assembler;
  81. { Check for local variable allocation }
  82. { On Entry -> d0 : size of local stack we are trying to allocate }
  83. asm
  84. XDEF STACKCHECK
  85. move.l sp,d1 { get value of stack pointer }
  86. sub.l d0,d1 { sp - stack_size }
  87. sub.l #2048,d1
  88. cmp.l __BREAK,d1
  89. bgt @st1nosweat
  90. move.l #202,d0
  91. jsr HALT_ERROR
  92. @st1nosweat:
  93. end;*)
  94. Function GetParamCount(const p: pchar): longint;
  95. var
  96. i: word;
  97. count: word;
  98. Begin
  99. i:=0;
  100. count:=0;
  101. while p[count] <> #0 do
  102. Begin
  103. if (p[count] <> ' ') and (p[count] <> #9) and (p[count] <> #0) then
  104. Begin
  105. i:=i+1;
  106. while (p[count] <> ' ') and (p[count] <> #9) and (p[count] <> #0) do
  107. count:=count+1;
  108. end;
  109. if p[count] = #0 then break;
  110. count:=count+1;
  111. end;
  112. GetParamCount:=longint(i);
  113. end;
  114. Function GetParam(index: word; const p : pchar): string;
  115. { On Entry: index = string index to correct parameter }
  116. { On exit: = correct character index into pchar array }
  117. { Returns correct index to command line argument }
  118. var
  119. count: word;
  120. localindex: word;
  121. l: byte;
  122. temp: string;
  123. Begin
  124. temp:='';
  125. count := 0;
  126. { first index is one }
  127. localindex := 1;
  128. l:=0;
  129. While p[count] <> #0 do
  130. Begin
  131. if (p[count] <> ' ') and (p[count] <> #9) then
  132. Begin
  133. if localindex = index then
  134. Begin
  135. while (p[count] <> #0) and (p[count] <> ' ') and (p[count] <> #9) and (l < 256) do
  136. Begin
  137. temp:=temp+p[count];
  138. l:=l+1;
  139. count:=count+1;
  140. end;
  141. temp[0]:=char(l);
  142. GetParam:=temp;
  143. exit;
  144. end;
  145. { Point to next argument in list }
  146. while (p[count] <> #0) and (p[count] <> ' ') and (p[count] <> #9) do
  147. Begin
  148. count:=count+1;
  149. end;
  150. localindex:=localindex+1;
  151. end;
  152. if p[count] = #0 then break;
  153. count:=count+1;
  154. end;
  155. GetParam:=temp;
  156. end;
  157. function paramstr(l : longint) : string;
  158. var
  159. p : pchar;
  160. s1 : string;
  161. begin
  162. if l = 0 then
  163. Begin
  164. s1 := '';
  165. end
  166. else
  167. if (l>0) and (l<=paramcount) then
  168. begin
  169. p:=args;
  170. paramstr:=GetParam(word(l),p);
  171. end
  172. else paramstr:='';
  173. end;
  174. function paramcount : longint;
  175. Begin
  176. paramcount := argc;
  177. end;
  178. { This routine is used to grow the heap. }
  179. { But here we do a trick, we say that the }
  180. { heap cannot be regrown! }
  181. function sbrk( size: longint): pointer;
  182. { on exit nil = if fails. }
  183. Begin
  184. sbrk:=nil;
  185. end;
  186. procedure randomize;
  187. begin
  188. {$WARNING: randseed initial value is 24bit}
  189. randseed:=xbios_random;
  190. end;
  191. {*****************************************************************************
  192. System Dependent Exit code
  193. *****************************************************************************}
  194. Procedure system_exit;
  195. begin
  196. gemdos_pterm(ExitCode);
  197. end;
  198. {*****************************************************************************
  199. SystemUnit Initialization
  200. *****************************************************************************}
  201. procedure SysInitStdIO;
  202. begin
  203. OpenStdIO(Input,fmInput,StdInputHandle);
  204. OpenStdIO(Output,fmOutput,StdOutputHandle);
  205. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  206. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  207. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  208. end;
  209. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  210. begin
  211. CheckInitialStkLen := StkLen;
  212. end;
  213. begin
  214. StackLength := CheckInitialStkLen (InitialStkLen);
  215. { Initialize ExitProc }
  216. ExitProc:=Nil;
  217. { Setup heap }
  218. InitHeap;
  219. SysInitExceptions;
  220. InitUnicodeStringManager;
  221. { Setup stdin, stdout and stderr }
  222. SysInitStdIO;
  223. { Reset IO Error }
  224. InOutRes:=0;
  225. { Setup command line arguments }
  226. // argc:=GetParamCount(args);
  227. {$ifdef FPC_HAS_FEATURE_THREADING}
  228. InitSystemThreads;
  229. {$endif}
  230. end.