system.pp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. This is a prototype file to show all function that need to be implemented
  6. for a new operating system (provided the processor specific
  7. function are already implemented !)
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. { no stack check in system }
  15. {$S-}
  16. unit system;
  17. interface
  18. { include system-independent routine headers }
  19. {$I systemh.inc}
  20. type
  21. THandle = longint;
  22. { include heap support headers }
  23. {$I heaph.inc}
  24. {Platform specific information}
  25. const
  26. LineEnding = #13#10;
  27. LFNSupport = true;
  28. DirectorySeparator = '\';
  29. DriveSeparator = ':';
  30. PathSeparator = ';';
  31. FileNameCaseSensitive = false;
  32. {The highest exit code which can be returned to the operating system.
  33. Should be at least 255.}
  34. maxExitCode = 255;
  35. const
  36. UnusedHandle = -1;
  37. StdInputHandle = 0;
  38. StdOutputHandle = 1;
  39. StdErrorHandle = 2;
  40. sLineBreak : string[1] = LineEnding;
  41. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  42. var
  43. argc : longint;
  44. argv : ppchar;
  45. envp : ppchar;
  46. implementation
  47. { include system independent routines }
  48. {$I system.inc}
  49. procedure setup_arguments;
  50. begin
  51. end;
  52. procedure setup_environment;
  53. begin
  54. end;
  55. {*****************************************************************************
  56. System Dependent Exit code
  57. *****************************************************************************}
  58. Procedure system_exit;
  59. begin
  60. end;
  61. {*****************************************************************************
  62. ParamStr/Randomize
  63. *****************************************************************************}
  64. { number of args }
  65. function paramcount : longint;
  66. begin
  67. {paramcount := argc - 1;}
  68. paramcount:=0;
  69. end;
  70. { argument number l }
  71. function paramstr(l : longint) : string;
  72. begin
  73. {if (l>=0) and (l+1<=argc) then
  74. paramstr:=strpas(argv[l])
  75. else}
  76. paramstr:='';
  77. end;
  78. { set randseed to a new pseudo random value }
  79. procedure randomize;
  80. begin
  81. {regs.realeax:=$2c00;
  82. sysrealintr($21,regs);
  83. hl:=regs.realedx and $ffff;
  84. randseed:=hl*$10000+ (regs.realecx and $ffff);}
  85. randseed:=0;
  86. end;
  87. {*****************************************************************************
  88. Heap Management
  89. *****************************************************************************}
  90. { first address of heap }
  91. function getheapstart:pointer;{assembler;
  92. asm
  93. leal HEAP,%eax
  94. end ['EAX'];}
  95. begin
  96. getheapstart:=0;
  97. end;
  98. { current length of heap }
  99. function getheapsize:longint;{assembler;
  100. asm
  101. movl HEAPSIZE,%eax
  102. end ['EAX'];}
  103. begin
  104. getheapsize:=0;
  105. end;
  106. { function to allocate size bytes more for the program }
  107. { must return the first address of new data space or nil if fail }
  108. function Sbrk(size : longint):pointer;{assembler;
  109. asm
  110. movl size,%eax
  111. pushl %eax
  112. call ___sbrk
  113. addl $4,%esp
  114. end;}
  115. begin
  116. Sbrk:=nil;
  117. end;
  118. {*****************************************************************************
  119. OS Memory allocation / deallocation
  120. ****************************************************************************}
  121. function SysOSAlloc(size: ptrint): pointer;
  122. begin
  123. result := sbrk(size);
  124. end;
  125. // If the OS is capable of freeing memory, define HAS_SYSOSFREE and implement
  126. // the SysOSFree function properly
  127. //{$define HAS_SYSOSFREE}
  128. {
  129. procedure SysOSFree(p: pointer; size: ptrint);
  130. begin
  131. // code to release memory block
  132. end;
  133. }
  134. { include standard heap management }
  135. {$I heap.inc}
  136. {****************************************************************************
  137. Low level File Routines
  138. All these functions can set InOutRes on errors
  139. ****************************************************************************}
  140. { close a file from the handle value }
  141. procedure do_close(handle : longint);
  142. begin
  143. InOutRes:=1;
  144. end;
  145. procedure do_erase(p : pchar);
  146. begin
  147. InOutRes:=1;
  148. end;
  149. procedure do_rename(p1,p2 : pchar);
  150. begin
  151. InOutRes:=1;
  152. end;
  153. function do_write(h,addr,len : longint) : longint;
  154. begin
  155. InOutRes:=1;
  156. end;
  157. function do_read(h,addr,len : longint) : longint;
  158. begin
  159. InOutRes:=1;
  160. end;
  161. function do_filepos(handle : longint) : longint;
  162. begin
  163. InOutRes:=1;
  164. end;
  165. procedure do_seek(handle,pos : longint);
  166. begin
  167. InOutRes:=1;
  168. end;
  169. function do_seekend(handle:longint):longint;
  170. begin
  171. InOutRes:=1;
  172. end;
  173. function do_filesize(handle : longint) : longint;
  174. begin
  175. InOutRes:=1;
  176. end;
  177. { truncate at a given position }
  178. procedure do_truncate (handle,pos:longint);
  179. begin
  180. InOutRes:=1;
  181. end;
  182. procedure do_open(var f;p:pchar;flags:longint);
  183. {
  184. filerec and textrec have both handle and mode as the first items so
  185. they could use the same routine for opening/creating.
  186. when (flags and $10) the file will be append
  187. when (flags and $100) the file will be truncate/rewritten
  188. when (flags and $1000) there is no check for close (needed for textfiles)
  189. }
  190. begin
  191. InOutRes:=1;
  192. end;
  193. function do_isdevice(handle:longint):boolean;
  194. begin
  195. do_isdevice:=false;
  196. end;
  197. {*****************************************************************************
  198. UnTyped File Handling
  199. *****************************************************************************}
  200. {$i file.inc}
  201. {*****************************************************************************
  202. Typed File Handling
  203. *****************************************************************************}
  204. {$i typefile.inc}
  205. {*****************************************************************************
  206. Text File Handling
  207. *****************************************************************************}
  208. { should we consider #26 as the end of a file ? }
  209. {?? $DEFINE EOF_CTRLZ}
  210. {$i text.inc}
  211. {*****************************************************************************
  212. Directory Handling
  213. *****************************************************************************}
  214. procedure mkdir(const s : string);[IOCheck];
  215. begin
  216. InOutRes:=1;
  217. end;
  218. procedure rmdir(const s : string);[IOCheck];
  219. begin
  220. InOutRes:=1;
  221. end;
  222. procedure chdir(const s : string);[IOCheck];
  223. begin
  224. InOutRes:=1;
  225. end;
  226. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  227. begin
  228. InOutRes := 1;
  229. end;
  230. {*****************************************************************************
  231. SystemUnit Initialization
  232. *****************************************************************************}
  233. Begin
  234. { To be set if this is a GUI or console application }
  235. IsConsole := TRUE;
  236. { To be set if this is a library and not a program }
  237. IsLibrary := FALSE;
  238. StackBottom := SPtr - StackLength;
  239. ExitCode := 0;
  240. { Setup heap }
  241. InitHeap;
  242. { Setup stdin, stdout and stderr }
  243. OpenStdIO(Input,fmInput,StdInputHandle);
  244. OpenStdIO(Output,fmOutput,StdOutputHandle);
  245. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  246. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  247. { Setup environment and arguments }
  248. Setup_Environment;
  249. Setup_Arguments;
  250. { Reset IO Error }
  251. InOutRes:=0;
  252. (* This should be changed to a real value during *)
  253. (* thread driver initialization if appropriate. *)
  254. ThreadID := 1;
  255. End.
  256. {
  257. $Log$
  258. Revision 1.12 2004-09-03 19:26:57 olle
  259. + added maxExitCode to all System.pp
  260. * constrained error code to be below maxExitCode in RunError et. al.
  261. Revision 1.11 2004/06/17 16:16:14 peter
  262. * New heapmanager that releases memory back to the OS, donated
  263. by Micha Nelissen
  264. Revision 1.10 2004/01/20 23:12:49 hajny
  265. * ExecuteProcess fixes, ProcessID and ThreadID added
  266. Revision 1.9 2003/09/27 11:52:36 peter
  267. * sbrk returns pointer
  268. Revision 1.8 2002/09/07 16:01:27 peter
  269. * old logs removed and tabs fixed
  270. Revision 1.7 2002/04/21 15:55:14 carl
  271. + initialize some global variables
  272. }