system.pp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2004 by Karoly Balogh for Genesi Sarl
  5. System unit for MorphOS.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { These things are set in the makefile, }
  13. { But you can override them here.}
  14. { If you use an aout system, set the conditional AOUT}
  15. { $Define AOUT}
  16. unit {$ifdef VER1_0}SysMorph{$else}System{$endif};
  17. interface
  18. {$define FPC_IS_SYSTEM}
  19. {$I systemh.inc}
  20. type
  21. THandle = DWord;
  22. {$I heaph.inc}
  23. const
  24. LineEnding = #10;
  25. LFNSupport = True;
  26. DirectorySeparator = '/';
  27. DriveSeparator = ':';
  28. PathSeparator = ';';
  29. const
  30. UnusedHandle : LongInt = -1;
  31. StdInputHandle : LongInt = 0;
  32. StdOutputHandle : LongInt = 0;
  33. StdErrorHandle : LongInt = 0;
  34. FileNameCaseSensitive : Boolean = False;
  35. sLineBreak : string[1] = LineEnding;
  36. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  37. var
  38. MOS_ExecBase : LongInt; external name '_ExecBase';
  39. int_heap : LongInt; external name 'HEAP';
  40. int_heapsize : LongInt; external name 'HEAPSIZE';
  41. function exec_OpenLibrary(libname: PChar location 'a1'; libver: LongInt location 'd0'; LIBBASE: DWORD LOCATION 'LIBBASE') : LongInt; SysCall 552;
  42. implementation
  43. {$I system.inc}
  44. { OS dependant parts }
  45. { $I errno.inc} // error numbers
  46. { $I bunxtype.inc} // c-types, unix base types, unix
  47. // base structures
  48. { $I ossysc.inc} // base syscalls
  49. { $I osmain.inc} // base wrappers *nix RTL (derivatives)
  50. {*****************************************************************************
  51. Misc. System Dependent Functions
  52. *****************************************************************************}
  53. procedure haltproc(e:longint);cdecl;external name '_haltproc';
  54. procedure System_exit;
  55. begin
  56. haltproc(ExitCode);
  57. End;
  58. {*****************************************************************************
  59. ParamStr/Randomize
  60. *****************************************************************************}
  61. { number of args }
  62. function paramcount : longint;
  63. begin
  64. {paramcount := argc - 1;}
  65. paramcount:=0;
  66. end;
  67. { argument number l }
  68. function paramstr(l : longint) : string;
  69. begin
  70. {if (l>=0) and (l+1<=argc) then
  71. paramstr:=strpas(argv[l])
  72. else}
  73. paramstr:='';
  74. end;
  75. { set randseed to a new pseudo random value }
  76. procedure randomize;
  77. begin
  78. {regs.realeax:=$2c00;
  79. sysrealintr($21,regs);
  80. hl:=regs.realedx and $ffff;
  81. randseed:=hl*$10000+ (regs.realecx and $ffff);}
  82. randseed:=0;
  83. end;
  84. {*****************************************************************************
  85. Heap Management
  86. *****************************************************************************}
  87. { first address of heap }
  88. function getheapstart:pointer;
  89. begin
  90. getheapstart:=@int_heap;
  91. end;
  92. { current length of heap }
  93. function getheapsize:longint;
  94. begin
  95. getheapsize:=int_heapsize;
  96. end;
  97. { function to allocate size bytes more for the program }
  98. { must return the first address of new data space or nil if fail }
  99. function Sbrk(size : longint):pointer;{assembler;
  100. asm
  101. movl size,%eax
  102. pushl %eax
  103. call ___sbrk
  104. addl $4,%esp
  105. end;}
  106. begin
  107. Sbrk:=nil;
  108. end;
  109. {$I heap.inc}
  110. {****************************************************************************
  111. Low level File Routines
  112. All these functions can set InOutRes on errors
  113. ****************************************************************************}
  114. { close a file from the handle value }
  115. procedure do_close(handle : longint);
  116. begin
  117. InOutRes:=1;
  118. end;
  119. procedure do_erase(p : pchar);
  120. begin
  121. InOutRes:=1;
  122. end;
  123. procedure do_rename(p1,p2 : pchar);
  124. begin
  125. InOutRes:=1;
  126. end;
  127. function do_write(h:longint; addr: pointer; len: longint) : longint;
  128. begin
  129. InOutRes:=1;
  130. end;
  131. function do_read(h:longint; addr: pointer; len: longint) : longint;
  132. begin
  133. InOutRes:=1;
  134. end;
  135. function do_filepos(handle : longint) : longint;
  136. begin
  137. InOutRes:=1;
  138. end;
  139. procedure do_seek(handle,pos : longint);
  140. begin
  141. InOutRes:=1;
  142. end;
  143. function do_seekend(handle:longint):longint;
  144. begin
  145. InOutRes:=1;
  146. end;
  147. function do_filesize(handle : longint) : longint;
  148. begin
  149. InOutRes:=1;
  150. end;
  151. { truncate at a given position }
  152. procedure do_truncate (handle,pos:longint);
  153. begin
  154. InOutRes:=1;
  155. end;
  156. procedure do_open(var f;p:pchar;flags:longint);
  157. {
  158. filerec and textrec have both handle and mode as the first items so
  159. they could use the same routine for opening/creating.
  160. when (flags and $10) the file will be append
  161. when (flags and $100) the file will be truncate/rewritten
  162. when (flags and $1000) there is no check for close (needed for textfiles)
  163. }
  164. begin
  165. InOutRes:=1;
  166. end;
  167. function do_isdevice(handle:longint):boolean;
  168. begin
  169. do_isdevice:=false;
  170. end;
  171. {*****************************************************************************
  172. UnTyped File Handling
  173. *****************************************************************************}
  174. {$i file.inc}
  175. {*****************************************************************************
  176. Typed File Handling
  177. *****************************************************************************}
  178. {$i typefile.inc}
  179. {*****************************************************************************
  180. Text File Handling
  181. *****************************************************************************}
  182. {$I text.inc}
  183. {*****************************************************************************
  184. Directory Handling
  185. *****************************************************************************}
  186. procedure mkdir(const s : string);[IOCheck];
  187. begin
  188. InOutRes:=1;
  189. end;
  190. procedure rmdir(const s : string);[IOCheck];
  191. begin
  192. InOutRes:=1;
  193. end;
  194. procedure chdir(const s : string);[IOCheck];
  195. begin
  196. InOutRes:=1;
  197. end;
  198. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  199. begin
  200. InOutRes := 1;
  201. end;
  202. procedure SysInitStdIO;
  203. begin
  204. OpenStdIO(Input,fmInput,StdInputHandle);
  205. OpenStdIO(Output,fmOutput,StdOutputHandle);
  206. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  207. { * MorphOS doesn't have a separate stderr, just like AmigaOS (???) * }
  208. StdErrorHandle:=StdOutputHandle;
  209. // OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  210. end;
  211. {procedure SysInitExecPath;
  212. var
  213. hs : string[16];
  214. link : string;
  215. i : longint;
  216. begin
  217. str(Fpgetpid,hs);
  218. hs:='/proc/'+hs+'/exe'#0;
  219. i:=Fpreadlink(@hs[1],@link[1],high(link));
  220. { it must also be an absolute filename, linux 2.0 points to a memory
  221. location so this will skip that }
  222. if (i>0) and (link[1]='/') then
  223. begin
  224. link[0]:=chr(i);
  225. ExecPathStr:=link;
  226. end;
  227. end;
  228. }
  229. Begin
  230. IsConsole := TRUE;
  231. IsLibrary := FALSE;
  232. StackLength := InitialStkLen;
  233. StackBottom := Sptr - StackLength;
  234. { Set up signals handlers }
  235. // InstallSignals;
  236. { Setup heap }
  237. InitHeap;
  238. // SysInitExceptions;
  239. { Arguments }
  240. // SetupCmdLine;
  241. // SysInitExecPath;
  242. { Setup stdin, stdout and stderr }
  243. // SysInitStdIO;
  244. { Reset IO Error }
  245. InOutRes:=0;
  246. (* This should be changed to a real value during *)
  247. (* thread driver initialization if appropriate. *)
  248. // ThreadID := 1;
  249. {$ifdef HASVARIANT}
  250. initvariantmanager;
  251. {$endif HASVARIANT}
  252. End.
  253. {
  254. $Log$
  255. Revision 1.3 2004-05-01 15:09:47 karoly
  256. * first working system unit (very limited yet)
  257. Revision 1.1 2004/02/13 07:19:53 karoly
  258. * quick hack from Linux system unit
  259. }