system.pp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Francesco Lombardi.
  4. System unit for Nintendo DS
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit System;
  12. interface
  13. {$define FPC_IS_SYSTEM}
  14. { $define USE_NOTHREADMANAGER}
  15. { $define HAS_MEMORYMANAGER}
  16. { $undef FPC_HAS_FEATURE_TEXTIO}
  17. {$i ndsbiosh.inc}
  18. {$I systemh.inc}
  19. {$define fpc_softfpu_interface}
  20. {$i softfpu.pp}
  21. {$undef fpc_softfpu_interface}
  22. procedure InitHeapThread;
  23. const
  24. LineEnding = #10;
  25. LFNSupport = true;
  26. CtrlZMarksEOF: boolean = false;
  27. DirectorySeparator = '/';
  28. DriveSeparator = ':';
  29. PathSeparator = ';';
  30. FileNameCaseSensitive = false;
  31. maxExitCode = 255;
  32. MaxPathLen = 255;
  33. sLineBreak : string[1] = LineEnding;
  34. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  35. const
  36. UnusedHandle = $ffff;
  37. StdInputHandle = 0;
  38. StdOutputHandle = 1;
  39. StdErrorHandle = $ffff;
  40. var
  41. argc: LongInt = 0;
  42. argv: PPChar;
  43. envp: PPChar;
  44. errno: integer;
  45. // fake_heap_start: ^byte; cvar;
  46. fake_heap_end: ^byte; cvar;
  47. // heap_start: longint; external name 'end';
  48. // heap_end: longint; external name '__eheap_end';
  49. heap_start: longint; external name 'end';
  50. heap_end: longint; external name 'fake_heap_end';
  51. // __eheap_start: longint; cvar; external;
  52. // fake_heap_end: longint; cvar; external;
  53. implementation
  54. {$define fpc_softfpu_implementation}
  55. {$i softfpu.pp}
  56. {$undef fpc_softfpu_implementation}
  57. { we get these functions and types from the softfpu code }
  58. {$define FPC_SYSTEM_HAS_float64}
  59. {$define FPC_SYSTEM_HAS_float32}
  60. {$define FPC_SYSTEM_HAS_flag}
  61. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  62. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  63. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  64. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  65. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  66. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  67. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  68. {$I system.inc}
  69. {$i ndsbios.inc}
  70. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  71. function GetProcessID: SizeUInt;
  72. begin
  73. end;
  74. {$endif}
  75. {*****************************************************************************
  76. Misc. System Dependent Functions
  77. *****************************************************************************}
  78. procedure System_exit;
  79. begin
  80. end;
  81. {*****************************************************************************
  82. ParamStr/Randomize
  83. *****************************************************************************}
  84. { number of args }
  85. function paramcount : longint;
  86. begin
  87. paramcount:=0;
  88. end;
  89. { argument number l }
  90. function paramstr(l : longint) : string;
  91. begin
  92. paramstr:='';
  93. end;
  94. { set randseed to a new pseudo random value }
  95. procedure randomize;
  96. begin
  97. end;
  98. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  99. procedure SysInitStdIO;
  100. begin
  101. OpenStdIO(Input,fmInput,StdInputHandle);
  102. OpenStdIO(Output,fmOutput,StdOutputHandle);
  103. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  104. end;
  105. {$endif}
  106. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  107. begin
  108. result := stklen;
  109. end;
  110. (*
  111. procedure InitHeap;
  112. begin
  113. FillChar(freelists_fixed,sizeof(tfreelists),0);
  114. FillChar(freelists_free_chunk,sizeof(freelists_free_chunk),0);
  115. freelist_var:=nil;
  116. {The GBA has no operating system from which we ask memory, so we
  117. initialize the heap with a single block of memory.}
  118. freeoslistcount:=1;
  119. //freeoslist:=pointer($023FF000);
  120. freeoslist:=pointer(heap_start);
  121. fillchar(freeoslist^,sizeof(freeoslist^),0);
  122. //freeoslist^.size:=$00040000;//$003FF000;
  123. freeoslist^.size:=heap_end-heap_start;
  124. fillchar(internal_status,sizeof(internal_status),0);
  125. end;
  126. *)
  127. procedure InitHeap;
  128. var
  129. loc_freelists: pfreelists;
  130. begin
  131. { we cannot initialize the locks here yet, thread support is
  132. not loaded yet }
  133. loc_freelists := @freelists;
  134. // PROVA -->
  135. loc_freelists^.varlist := nil;
  136. loc_freelists^.oscount := 1;
  137. loc_freelists := pointer(heap_start);
  138. fillchar(loc_freelists^, sizeof(tfreelists), 0);
  139. fillchar(orphaned_freelists, sizeof(orphaned_freelists), 0);
  140. loc_freelists^.oslist^.size := heap_end - heap_start;
  141. fillchar(loc_freelists^.internal_status, sizeof(TFPCHeapStatus), 0);
  142. // <-- PROVA
  143. end;
  144. procedure InitHeapThread;
  145. var
  146. loc_freelists: pfreelists;
  147. begin
  148. loc_freelists := @freelists;
  149. fillchar(loc_freelists^,sizeof(tfreelists),0);
  150. {$ifdef DUMP_MEM_USAGE}
  151. fillchar(sizeusage,sizeof(sizeusage),0);
  152. fillchar(maxsizeusage,sizeof(sizeusage),0);
  153. {$endif}
  154. end;
  155. begin
  156. StackLength := CheckInitialStkLen(InitialStkLen);
  157. ///StackBottom := Sptr - StackLength;
  158. StackBottom := StackTop - StackLength;
  159. { OS specific startup }
  160. // fake_heap_start := pchar(0);
  161. // fake_heap_end := pchar(0);
  162. { Set up signals handlers }
  163. fpc_cpucodeinit;
  164. { Setup heap }
  165. InitHeap;
  166. SysInitExceptions;
  167. { Setup stdin, stdout and stderr }
  168. SysInitStdIO;
  169. { Reset IO Error }
  170. InOutRes:=0;
  171. { Arguments }
  172. InitSystemThreads;
  173. initvariantmanager;
  174. end.