system.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. {$i ndsbiosh.inc}
  15. {$i systemh.inc}
  16. {$define fpc_softfpu_interface}
  17. {$i softfpu.pp}
  18. {$undef fpc_softfpu_interface}
  19. function IsARM9(): boolean;
  20. const
  21. LineEnding = #10;
  22. LFNSupport = true;
  23. CtrlZMarksEOF: boolean = false;
  24. DirectorySeparator = '/';
  25. DriveSeparator = ':';
  26. ExtensionSeparator = '.';
  27. PathSeparator = ';';
  28. AllowDirectorySeparators : set of char = ['\','/'];
  29. AllowDriveSeparators : set of char = [':'];
  30. FileNameCaseSensitive = false;
  31. maxExitCode = 255;
  32. MaxPathLen = 255;
  33. AllFilesMask = '*';
  34. sLineBreak: string[1] = LineEnding;
  35. DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
  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_end: ^byte; cvar;
  46. irq_vector: integer; external name '__irq_vector';
  47. implementation
  48. {$define fpc_softfpu_implementation}
  49. {$i softfpu.pp}
  50. {$undef fpc_softfpu_implementation}
  51. { we get these functions and types from the softfpu code }
  52. {$define FPC_SYSTEM_HAS_float64}
  53. {$define FPC_SYSTEM_HAS_float32}
  54. {$define FPC_SYSTEM_HAS_flag}
  55. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  56. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  57. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  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. {$i system.inc}
  63. {$i ndsbios.inc}
  64. {
  65. NDS CPU detecting function
  66. --------------------------
  67. ARM946E-S processor can handle dsp extensions, but ARM7TDMI does not. FPC can
  68. detect dsp by catching a SIGILL that fires when ARM7 cpu tries to use a dsp
  69. command. Unfortunately, NDS' rtl does not have any error catching mechanism.
  70. This function takes care to check if the code is running on an ARM9 or on an
  71. ARM7 CPU, by checking the IRQ vector address ($0B003FFC for ARM9, 0380fff8
  72. for ARM7), declared in the linker script. This function is cleaner than the
  73. older one, because does not raise any memory writing error.
  74. It works on Nintendo DS only, I guess :)
  75. }
  76. function IsARM9(): boolean;
  77. begin
  78. IsARM9 := integer(@irq_vector) = $0B003FFC;
  79. end;
  80. {
  81. NDS CPU detecting function (thanks to 21o6):
  82. --------------------------------------------
  83. "You see, the ARM7 can't write to bank A of VRAM, but it doesn't give any
  84. error ... it just doesn't write there... so it's easily determinable what
  85. CPU is running the code"
  86. ARM946E-S processor can handle dsp extensions extensions, but ARM7TDMI does
  87. not. FPC can't retrieve the CPU target at compiling time, so this small
  88. function takes care to check if the code is running on an ARM9 or on an ARM7
  89. CPU. It works on Nintendo DS only, I guess :)
  90. }
  91. function IsARM92(): boolean;
  92. var
  93. Dummy : pword absolute $06800000;
  94. tmp: word;
  95. begin
  96. tmp := Dummy^;
  97. Dummy^ := $C0DE;
  98. IsARM92 := Dummy^ = $C0DE;
  99. Dummy^ := tmp;
  100. end;
  101. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  102. function GetProcessID: SizeUInt;
  103. begin
  104. GetProcessID := 0;
  105. end;
  106. {$endif}
  107. {*****************************************************************************
  108. Misc. System Dependent Functions
  109. *****************************************************************************}
  110. procedure System_exit;
  111. begin
  112. // Boo!
  113. end;
  114. {*****************************************************************************
  115. ParamStr/Randomize
  116. *****************************************************************************}
  117. { number of args }
  118. function paramcount : longint;
  119. begin
  120. paramcount := 0;
  121. end;
  122. { argument number l }
  123. function paramstr(l : longint) : string;
  124. begin
  125. paramstr := '';
  126. end;
  127. { set randseed to a new pseudo random value }
  128. procedure randomize;
  129. begin
  130. // Boo!
  131. end;
  132. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  133. procedure SysInitStdIO;
  134. begin
  135. OpenStdIO(Input,fmInput,StdInputHandle);
  136. OpenStdIO(Output,fmOutput,StdOutputHandle);
  137. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  138. end;
  139. {$endif}
  140. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  141. begin
  142. result := stklen;
  143. end;
  144. begin
  145. StackLength := CheckInitialStkLen(InitialStkLen);
  146. StackBottom := StackTop - StackLength;
  147. { OS specific startup }
  148. { Set up signals handlers }
  149. if IsARM9 then
  150. fpc_cpucodeinit;
  151. { Setup heap }
  152. InitHeap;
  153. SysInitExceptions;
  154. { Setup stdin, stdout and stderr }
  155. SysInitStdIO;
  156. { Reset IO Error }
  157. InOutRes:=0;
  158. { Arguments }
  159. InitSystemThreads;
  160. initvariantmanager;
  161. end.