2
0

system.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. interface
  15. {$define FPC_IS_SYSTEM}
  16. {$define FPC_STDOUT_TRUE_ALIAS}
  17. {$define FPC_ANSI_TEXTFILEREC}
  18. {$define FPC_SYSTEM_EXIT_NO_RETURN}
  19. {$define FPC_SYSTEM_NO_VERBOSE_UNICODEERROR}
  20. {.$define FPC_ATARI_USE_TINYHEAP}
  21. {$ifdef FPC_ATARI_USE_TINYHEAP}
  22. {$define HAS_MEMORYMANAGER}
  23. {$endif FPC_ATARI_USE_TINYHEAP}
  24. {$i systemh.inc}
  25. {$ifdef FPC_ATARI_USE_TINYHEAP}
  26. {$i tnyheaph.inc}
  27. {$endif FPC_ATARI_USE_TINYHEAP}
  28. {Platform specific information}
  29. const
  30. LineEnding = #13#10;
  31. LFNSupport = false;
  32. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  33. DirectorySeparator = '\';
  34. DriveSeparator = ':';
  35. ExtensionSeparator = '.';
  36. PathSeparator = ';';
  37. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  38. AllowDriveSeparators : set of AnsiChar = [':'];
  39. FileNameCaseSensitive = false;
  40. FileNameCasePreserving = false;
  41. maxExitCode = 255;
  42. MaxPathLen = 255;
  43. AllFilesMask = '*.*';
  44. sLineBreak = LineEnding;
  45. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  46. const
  47. UnusedHandle = $ffff;
  48. StdInputHandle = 0;
  49. StdOutputHandle = 1;
  50. StdErrorHandle = 2;
  51. var
  52. args: PAnsiChar;
  53. argc: LongInt;
  54. argv: PPAnsiChar;
  55. envp: PPAnsiChar;
  56. AppFlag: Boolean; { Application or Accessory }
  57. {$if defined(FPUSOFT)}
  58. {$define fpc_softfpu_interface}
  59. {$i softfpu.pp}
  60. {$undef fpc_softfpu_interface}
  61. {$endif defined(FPUSOFT)}
  62. implementation
  63. {$define FPC_SYSTEM_HAS_STACKTOP}
  64. {$define FPC_SYSTEM_HAS_BACKTRACESTR}
  65. {$if defined(FPUSOFT)}
  66. {$define fpc_softfpu_implementation}
  67. {$define softfpu_compiler_mul32to64}
  68. {$define softfpu_inline}
  69. {$i softfpu.pp}
  70. {$undef fpc_softfpu_implementation}
  71. { we get these functions and types from the softfpu code }
  72. {$define FPC_SYSTEM_HAS_float64}
  73. {$define FPC_SYSTEM_HAS_float32}
  74. {$define FPC_SYSTEM_HAS_flag}
  75. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  76. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  77. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  78. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  79. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  80. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  81. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  82. {$endif defined(FPUSOFT)}
  83. {$i system.inc}
  84. {$ifdef FPC_ATARI_USE_TINYHEAP}
  85. {$i tinyheap.inc}
  86. {$endif FPC_ATARI_USE_TINYHEAP}
  87. {$i syspara.inc}
  88. function GetProcessID:SizeUInt;
  89. begin
  90. {$WARNING To be checked by platform maintainer}
  91. GetProcessID := 1;
  92. end;
  93. procedure SysInitParamsAndEnv;
  94. begin
  95. // [0] index contains the args length...
  96. args:=@basepage^.p_cmdlin[0];
  97. GenerateArgs;
  98. end;
  99. procedure randomize;
  100. begin
  101. {$WARNING: randseed initial value is 24bit}
  102. randseed:=xbios_random;
  103. end;
  104. function fpGetEnv(const envvar : ShortString): RawByteString; public name '_fpc_atari_getenv';
  105. var
  106. hp : PAnsiChar;
  107. i : longint;
  108. upperenv, str : RawByteString;
  109. begin
  110. fpGetEnv:='';
  111. hp:=basepage^.p_env;
  112. if (hp=nil) then
  113. exit;
  114. upperenv:=upcase(envvar);
  115. while hp^<>#0 do
  116. begin
  117. str:=hp;
  118. i:=pos('=',str);
  119. if upcase(copy(str,1,i-1))=upperenv then
  120. begin
  121. fpGetEnv:=copy(str,i+1,length(str)-i);
  122. break;
  123. end;
  124. { next string entry}
  125. hp:=hp+strlen(hp)+1;
  126. end;
  127. end;
  128. {*****************************************************************************
  129. System Dependent Exit code
  130. *****************************************************************************}
  131. procedure haltproc(e:longint); cdecl; external name 'haltproc'; noreturn;
  132. Procedure system_exit; noreturn;
  133. begin
  134. haltproc(ExitCode);
  135. end;
  136. {*****************************************************************************
  137. SystemUnit Initialization
  138. *****************************************************************************}
  139. Procedure ConsoleRead(var t:TextRec);
  140. var
  141. dosResult: longint;
  142. Begin
  143. dosResult:=gemdos_fread(t.Handle,t.BufSize,t.Bufptr);
  144. t.BufPos:=0;
  145. { Reading from console on TOS does not include the terminating CR/LF }
  146. if (dosResult >= 0) then
  147. begin
  148. t.BufEnd := dosResult;
  149. if (dosResult>=1) and (t.Bufptr^[dosResult-1] = #10) then
  150. begin end
  151. else
  152. if (t.BufEnd < t.BufSize) then
  153. begin
  154. t.BufPtr^[t.BufEnd] := #13;
  155. inc(t.BufEnd);
  156. end;
  157. if (t.BufEnd < t.BufSize) then
  158. begin
  159. t.BufPtr^[t.BufEnd] := #10;
  160. inc(t.BufEnd);
  161. end;
  162. end
  163. else
  164. Error2InOutRes(dosResult);
  165. End;
  166. procedure myOpenStdIO(var f:text;mode:longint;hdl:thandle);
  167. begin
  168. OpenStdIO(f, mode, hdl);
  169. if (InOutRes=0) and (Mode=fmInput) and Do_Isdevice(hdl) then
  170. begin
  171. TextRec(f).InOutFunc:=@ConsoleRead;
  172. end;
  173. end;
  174. procedure SysInitStdIO;
  175. begin
  176. myOpenStdIO(Input,fmInput,StdInputHandle);
  177. myOpenStdIO(Output,fmOutput,StdOutputHandle);
  178. myOpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  179. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  180. myOpenStdIO(StdOut,fmOutput,StdOutputHandle);
  181. myOpenStdIO(StdErr,fmOutput,StdErrorHandle);
  182. {$endif FPC_STDOUT_TRUE_ALIAS}
  183. end;
  184. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  185. begin
  186. CheckInitialStkLen := StkLen;
  187. end;
  188. begin
  189. StackLength := CheckInitialStkLen (InitialStkLen);
  190. StackBottom := StackTop - StackLength;
  191. StackMargin := min(align(StackLength div 20,2),STACK_MARGIN_MAX);
  192. { Initialize ExitProc }
  193. ExitProc:=Nil;
  194. {$ifndef FPC_ATARI_USE_TINYHEAP}
  195. { Setup heap }
  196. InitHeap;
  197. {$endif FPC_ATARI_USE_TINYHEAP}
  198. SysInitExceptions;
  199. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  200. InitUnicodeStringManager;
  201. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  202. { Setup stdin, stdout and stderr }
  203. SysInitStdIO;
  204. { Reset IO Error }
  205. InOutRes:=0;
  206. { Setup command line arguments }
  207. SysInitParamsAndEnv;
  208. {$ifdef FPC_HAS_FEATURE_THREADING}
  209. InitSystemThreads;
  210. {$endif FPC_HAS_FEATURE_THREADING}
  211. end.