system.pp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. {$define softfpu_compiler_mul32to64}
  60. {$define softfpu_inline}
  61. {$i softfpu.pp}
  62. {$undef fpc_softfpu_implementation}
  63. { we get these functions and types from the softfpu code }
  64. {$define FPC_SYSTEM_HAS_float64}
  65. {$define FPC_SYSTEM_HAS_float32}
  66. {$define FPC_SYSTEM_HAS_flag}
  67. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  68. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  69. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  70. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  71. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  72. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  73. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  74. {$endif defined(FPUSOFT)}
  75. {$I system.inc}
  76. {$I syspara.inc}
  77. var
  78. basepage: PPD; external name '__base';
  79. function GetProcessID:SizeUInt;
  80. begin
  81. {$WARNING To be checked by platform maintainer}
  82. GetProcessID := 1;
  83. end;
  84. {$S-}
  85. (* procedure Stack_Check; assembler;
  86. { Check for local variable allocation }
  87. { On Entry -> d0 : size of local stack we are trying to allocate }
  88. asm
  89. XDEF STACKCHECK
  90. move.l sp,d1 { get value of stack pointer }
  91. sub.l d0,d1 { sp - stack_size }
  92. sub.l #2048,d1
  93. cmp.l __BREAK,d1
  94. bgt @st1nosweat
  95. move.l #202,d0
  96. jsr HALT_ERROR
  97. @st1nosweat:
  98. end;*)
  99. procedure SysInitParamsAndEnv;
  100. begin
  101. // [0] index contains the args length...
  102. args:=@basepage^.p_cmdlin[1];
  103. GenerateArgs;
  104. end;
  105. { This routine is used to grow the heap. }
  106. { But here we do a trick, we say that the }
  107. { heap cannot be regrown! }
  108. function sbrk( size: longint): pointer;
  109. { on exit nil = if fails. }
  110. Begin
  111. sbrk:=nil;
  112. end;
  113. procedure randomize;
  114. begin
  115. {$WARNING: randseed initial value is 24bit}
  116. randseed:=xbios_random;
  117. end;
  118. {*****************************************************************************
  119. System Dependent Exit code
  120. *****************************************************************************}
  121. Procedure system_exit;
  122. begin
  123. gemdos_pterm(ExitCode);
  124. end;
  125. {*****************************************************************************
  126. SystemUnit Initialization
  127. *****************************************************************************}
  128. procedure SysInitStdIO;
  129. begin
  130. OpenStdIO(Input,fmInput,StdInputHandle);
  131. OpenStdIO(Output,fmOutput,StdOutputHandle);
  132. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  133. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  134. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  135. end;
  136. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  137. begin
  138. CheckInitialStkLen := StkLen;
  139. end;
  140. begin
  141. StackLength := CheckInitialStkLen (InitialStkLen);
  142. { Initialize ExitProc }
  143. ExitProc:=Nil;
  144. { Setup heap }
  145. InitHeap;
  146. SysInitExceptions;
  147. InitUnicodeStringManager;
  148. { Setup stdin, stdout and stderr }
  149. SysInitStdIO;
  150. { Reset IO Error }
  151. InOutRes:=0;
  152. { Setup command line arguments }
  153. SysInitParamsAndEnv;
  154. {$ifdef FPC_HAS_FEATURE_THREADING}
  155. InitSystemThreads;
  156. {$endif}
  157. end.