system.pp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. function IsARM9(): boolean;
  23. procedure InitHeapThread;
  24. const
  25. LineEnding = #10;
  26. LFNSupport = true;
  27. CtrlZMarksEOF: boolean = false;
  28. DirectorySeparator = '/';
  29. DriveSeparator = ':';
  30. PathSeparator = ';';
  31. FileNameCaseSensitive = false;
  32. maxExitCode = 255;
  33. MaxPathLen = 255;
  34. sLineBreak : string[1] = LineEnding;
  35. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  36. const
  37. UnusedHandle = $ffff;
  38. StdInputHandle = 0;
  39. StdOutputHandle = 1;
  40. StdErrorHandle = $ffff;
  41. var
  42. argc: LongInt = 0;
  43. argv: PPChar;
  44. envp: PPChar;
  45. errno: integer;
  46. // fake_heap_start: ^byte; cvar;
  47. fake_heap_end: ^byte; cvar;
  48. // heap_start: longint; external name 'end';
  49. // heap_end: longint; external name '__eheap_end';
  50. heap_start: longint; external name 'end';
  51. heap_end: longint; external name 'fake_heap_end';
  52. // __eheap_start: longint; cvar; external;
  53. // fake_heap_end: longint; cvar; external;
  54. implementation
  55. {$define fpc_softfpu_implementation}
  56. {$i softfpu.pp}
  57. {$undef fpc_softfpu_implementation}
  58. { we get these functions and types from the softfpu code }
  59. {$define FPC_SYSTEM_HAS_float64}
  60. {$define FPC_SYSTEM_HAS_float32}
  61. {$define FPC_SYSTEM_HAS_flag}
  62. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  63. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  64. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  65. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  66. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  67. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  68. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  69. {$I system.inc}
  70. {$i ndsbios.inc}
  71. { NDS CPU detecting function (thanks to 21o6):
  72. --------------------------------------------
  73. "You see, the ARM7 can't write to bank A of VRAM, but it doesn't give any
  74. error ... it just doesn't write there... so it's easily determinable what
  75. CPU is running the code"}
  76. function IsARM9(): boolean;
  77. var
  78. Dummy : pword absolute $06800000;
  79. tmp: word;
  80. begin
  81. tmp := Dummy^;
  82. Dummy^ := $C0DE;
  83. IsARM9 := Dummy^ = $C0DE;
  84. Dummy^ := tmp;
  85. end;
  86. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  87. function GetProcessID: SizeUInt;
  88. begin
  89. end;
  90. {$endif}
  91. {*****************************************************************************
  92. Misc. System Dependent Functions
  93. *****************************************************************************}
  94. procedure System_exit;
  95. begin
  96. end;
  97. {*****************************************************************************
  98. ParamStr/Randomize
  99. *****************************************************************************}
  100. { number of args }
  101. function paramcount : longint;
  102. begin
  103. paramcount:=0;
  104. end;
  105. { argument number l }
  106. function paramstr(l : longint) : string;
  107. begin
  108. paramstr:='';
  109. end;
  110. { set randseed to a new pseudo random value }
  111. procedure randomize;
  112. begin
  113. end;
  114. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  115. procedure SysInitStdIO;
  116. begin
  117. OpenStdIO(Input,fmInput,StdInputHandle);
  118. OpenStdIO(Output,fmOutput,StdOutputHandle);
  119. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  120. end;
  121. {$endif}
  122. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  123. begin
  124. result := stklen;
  125. end;
  126. (*
  127. procedure InitHeap;
  128. begin
  129. FillChar(freelists_fixed,sizeof(tfreelists),0);
  130. FillChar(freelists_free_chunk,sizeof(freelists_free_chunk),0);
  131. freelist_var:=nil;
  132. {The GBA has no operating system from which we ask memory, so we
  133. initialize the heap with a single block of memory.}
  134. freeoslistcount:=1;
  135. //freeoslist:=pointer($023FF000);
  136. freeoslist:=pointer(heap_start);
  137. fillchar(freeoslist^,sizeof(freeoslist^),0);
  138. //freeoslist^.size:=$00040000;//$003FF000;
  139. freeoslist^.size:=heap_end-heap_start;
  140. fillchar(internal_status,sizeof(internal_status),0);
  141. end;
  142. *)
  143. procedure InitHeap;
  144. var
  145. loc_freelists: pfreelists;
  146. begin
  147. { we cannot initialize the locks here yet, thread support is
  148. not loaded yet }
  149. loc_freelists := @freelists;
  150. // PROVA -->
  151. loc_freelists^.varlist := nil;
  152. loc_freelists^.oscount := 1;
  153. loc_freelists := pointer(heap_start);
  154. fillchar(loc_freelists^, sizeof(tfreelists), 0);
  155. fillchar(orphaned_freelists, sizeof(orphaned_freelists), 0);
  156. loc_freelists^.oslist^.size := heap_end - heap_start;
  157. fillchar(loc_freelists^.internal_status, sizeof(TFPCHeapStatus), 0);
  158. // <-- PROVA
  159. end;
  160. procedure InitHeapThread;
  161. var
  162. loc_freelists: pfreelists;
  163. begin
  164. loc_freelists := @freelists;
  165. fillchar(loc_freelists^,sizeof(tfreelists),0);
  166. {$ifdef DUMP_MEM_USAGE}
  167. fillchar(sizeusage,sizeof(sizeusage),0);
  168. fillchar(maxsizeusage,sizeof(sizeusage),0);
  169. {$endif}
  170. end;
  171. begin
  172. StackLength := CheckInitialStkLen(InitialStkLen);
  173. ///StackBottom := Sptr - StackLength;
  174. StackBottom := StackTop - StackLength;
  175. { OS specific startup }
  176. // fake_heap_start := pchar(0);
  177. // fake_heap_end := pchar(0);
  178. { Set up signals handlers }
  179. if IsARM9 then
  180. fpc_cpucodeinit;
  181. { Setup heap }
  182. InitHeap;
  183. SysInitExceptions;
  184. { Setup stdin, stdout and stderr }
  185. SysInitStdIO;
  186. { Reset IO Error }
  187. InOutRes:=0;
  188. { Arguments }
  189. InitSystemThreads;
  190. initvariantmanager;
  191. end.