system.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. {$DEFINE FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
  5. {$I systemh.inc}
  6. {$ifndef FPUNONE}
  7. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  8. {$define fpc_softfpu_interface}
  9. {$i softfpu.pp}
  10. {$undef fpc_softfpu_interface}
  11. {$endif FPC_HAS_FEATURE_SOFTFPU}
  12. {$endif FPUNONE}
  13. const
  14. maxExitCode = 255;
  15. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  16. DirectorySeparator = '/';
  17. { Default filehandles }
  18. UnusedHandle = $ffff;{ instead of -1, as it is a word value}
  19. StdInputHandle = 0;
  20. StdOutputHandle = 1;
  21. StdErrorHandle = 2;
  22. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  23. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  24. LineEnding = #10;
  25. PathSeparator = '/';
  26. MaxPathLen = 255;
  27. LFNSupport = true;
  28. FileNameCaseSensitive = true;
  29. sLineBreak = #10;
  30. AllFilesMask = '*';
  31. var
  32. argc:longint=0;
  33. argv:PPAnsiChar;
  34. envp:PPAnsiChar;
  35. implementation
  36. var
  37. StkLen: SizeUInt; external name '__stklen';
  38. bss_end: record end; external name '__bss_end__';
  39. procedure _InitHeap(p: pdword; l: dword); external name 'InitHeap2';
  40. procedure _free(p: pointer); external name 'free2';
  41. function _malloc(l: dword): pointer; external name 'malloc2';
  42. procedure _putchar(ch: char); external name 'putchar';
  43. {I ../mips/setjump.inc}
  44. {$I system.inc}
  45. {$ifndef FPUNONE}
  46. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  47. {$define fpc_softfpu_implementation}
  48. {$i softfpu.pp}
  49. {$undef fpc_softfpu_implementation}
  50. { we get these functions and types from the softfpu code }
  51. {$define FPC_SYSTEM_HAS_float64}
  52. {$define FPC_SYSTEM_HAS_float32}
  53. {$define FPC_SYSTEM_HAS_flag}
  54. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  55. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  56. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  57. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  58. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  59. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  60. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  61. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  62. {$endif FPC_HAS_FEATURE_SOFTFPU}
  63. {$endif FPUNONE}
  64. procedure Randomize;
  65. begin
  66. randseed:= 1234;
  67. end;
  68. function GetProcessID: LongWord;
  69. begin
  70. result:= 0;
  71. end;
  72. function ParamCount: LongInt;
  73. begin
  74. ParamCount:= 0;
  75. end;
  76. function ParamStr(l: LongInt): ShortString;
  77. begin
  78. result:='';
  79. end;
  80. procedure SysInitStdIO;
  81. begin
  82. OpenStdIO(Input,fmInput,StdInputHandle);
  83. OpenStdIO(Output,fmOutput,StdOutputHandle);
  84. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  85. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  86. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  87. end;
  88. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  89. const
  90. MinHeap = 1024; // always leave at least 1k heap
  91. var
  92. MaxStack: SizeInt;
  93. begin
  94. MaxStack:=SizeInt(PtrUInt($801FFFF0)-PtrUInt(@bss_end))-MinHeap;
  95. if stklen<MaxStack then
  96. result:= stklen
  97. else
  98. result:=MaxStack;
  99. end;
  100. procedure system_exit;
  101. begin
  102. repeat
  103. until false;
  104. end;
  105. function alignvalue(x, a : dword): dword;
  106. var r : dword;
  107. begin
  108. r:= x mod a;
  109. if r <> 0 then begin
  110. result:= x + (a - r);
  111. end else result:= x;
  112. end;
  113. begin
  114. StackLength:=CheckInitialStkLen(stklen);
  115. StackBottom:=Pointer(PtrUInt($801FFFF0)-PtrUInt(StackLength));
  116. { Debug printing via writeln (visible in emulator logs) is possible, so
  117. pretend to be a console application. }
  118. IsConsole := TRUE;
  119. { To be set if this is a library and not a program }
  120. IsLibrary := FALSE;
  121. { Setup heap }
  122. _InitHeap(pdword(@bss_end),alignvalue(PtrUInt(StackBottom)-PtrUInt(@bss_end), 4));
  123. InitHeap;
  124. { Init exceptions }
  125. SysInitExceptions;
  126. { Init unicode strings }
  127. initunicodestringmanager;
  128. { Setup stdin, stdout and stderr }
  129. SysInitStdIO;
  130. { Reset IO Error }
  131. InOutRes:= 0;
  132. {$ifdef FPC_HAS_FEATURE_THREADING}
  133. { Initialize the thread manager }
  134. InitSystemThreads;
  135. {$endif}
  136. end.