2
0

system.pp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Florian Klaempfl
  4. member of the Free Pascal development team.
  5. System unit for FreeRTOS systems
  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. Unit System;
  13. {*****************************************************************************}
  14. interface
  15. {*****************************************************************************}
  16. {$define FPC_SYSTEM_HAS_STACKTOP}
  17. {$define FPC_IS_SYSTEM}
  18. {$define HAS_CMDLINE}
  19. { $define USE_NOTHREADMANAGER}
  20. {$define DISABLE_NO_THREAD_MANAGER}
  21. { Do not use standard memory manager }
  22. {$define HAS_MEMORYMANAGER}
  23. {$define FPC_NO_DEFAULT_HEAP}
  24. {$define FPC_ANSI_TEXTFILEREC}
  25. { make output and stdout as well as input and stdin equal to save memory }
  26. {$define FPC_STDOUT_TRUE_ALIAS}
  27. {$ifdef CPUI8086}
  28. {$DEFINE FPC_INCLUDE_SOFTWARE_MUL}
  29. {$DEFINE FPC_INCLUDE_SOFTWARE_MOD_DIV}
  30. {$endif CPUI8086}
  31. {$I check.inc}
  32. {$I systemh.inc}
  33. const
  34. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  35. LineEnding = #10;
  36. {$endif FPC_HAS_FEATURE_TEXTIO}
  37. {$ifdef FPC_HAS_FEATURE_FILEIO}
  38. LFNSupport = true;
  39. DirectorySeparator = '/';
  40. DriveSeparator = ':';
  41. ExtensionSeparator = '.';
  42. PathSeparator = ':';
  43. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  44. AllowDriveSeparators : set of AnsiChar = [':'];
  45. {$endif FPC_HAS_FEATURE_FILEIO}
  46. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  47. {$ifdef FPC_HAS_FEATURE_EXITCODE}
  48. maxExitCode = 255;
  49. {$endif FPC_HAS_FEATURE_EXITCODE}
  50. {$ifdef FPC_HAS_FEATURE_FILEIO}
  51. MaxPathLen = 1024; // BSDs since 1993, Solaris 10, Darwin
  52. AllFilesMask = '*';
  53. UnusedHandle = -1;
  54. StdInputHandle = 0;
  55. StdOutputHandle = 1;
  56. StdErrorHandle = 2;
  57. FileNameCaseSensitive : boolean = true;
  58. FileNameCasePreserving: boolean = true;
  59. {$endif FPC_HAS_FEATURE_FILEIO}
  60. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  61. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  62. sLineBreak = LineEnding;
  63. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCrLF;
  64. {$endif FPC_HAS_FEATURE_TEXTIO}
  65. {$ifdef CPUI8086}
  66. { The value that needs to be added to the segment to move the pointer by
  67. 64K bytes (BP7 compatibility) }
  68. SelectorInc: Word = $1000;
  69. {$endif CPUI8086}
  70. type
  71. trtl_do_close = procedure (handle : longint);
  72. trtl_do_erase = procedure (p : PAnsiChar);
  73. trtl_do_rename = procedure (p1,p2 : PAnsiChar);
  74. trtl_do_write = function (h: longint; addr: pointer; len: longint) : longint;
  75. trtl_do_read = function (h: longint; addr: pointer; len: longint) : longint;
  76. trtl_do_filepos = function (handle: longint) : longint;
  77. trtl_do_seek = procedure (handle, pos: longint);
  78. trtl_do_seekend = function (handle: longint):longint;
  79. trtl_do_filesize = function (handle : longint) : longint;
  80. trtl_do_truncate = procedure (handle, pos: longint);
  81. trtl_do_open = procedure (var f;p:PAnsiChar;flags:longint);
  82. trtl_do_isdevice = function (handle: longint): boolean;
  83. var
  84. rtl_do_close : trtl_do_close = nil;
  85. rtl_do_erase : trtl_do_erase = nil;
  86. rtl_do_rename : trtl_do_rename = nil;
  87. rtl_do_write : trtl_do_write = nil;
  88. rtl_do_read : trtl_do_read = nil;
  89. rtl_do_filepos : trtl_do_filepos = nil;
  90. rtl_do_seek : trtl_do_seek = nil;
  91. rtl_do_seekend : trtl_do_seekend = nil;
  92. rtl_do_filesize : trtl_do_filesize = nil;
  93. rtl_do_truncate : trtl_do_truncate = nil;
  94. rtl_do_open : trtl_do_open = nil;
  95. rtl_do_isdevice : trtl_do_isdevice = nil;
  96. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  97. var
  98. argc: LongInt = 0;
  99. argv: PPAnsiChar = nil;
  100. envp: PPAnsiChar = nil;
  101. cmdline: PAnsiChar = nil;
  102. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  103. {$ifndef FPUNONE}
  104. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  105. {$define fpc_softfpu_interface}
  106. {$i softfpu.pp}
  107. {$undef fpc_softfpu_interface}
  108. {$endif FPC_HAS_FEATURE_SOFTFPU}
  109. {$endif FPUNONE}
  110. {$ifdef CPUI8086}
  111. var
  112. { Mem[] support }
  113. mem : array[0..$7fff-1] of byte absolute $0:$0;
  114. memw : array[0..($7fff div sizeof(word))-1] of word absolute $0:$0;
  115. meml : array[0..($7fff div sizeof(longint))-1] of longint absolute $0:$0;
  116. __stkbottom : pointer;public name '__stkbottom';
  117. {$endif CPUI8086}
  118. {*****************************************************************************}
  119. implementation
  120. {*****************************************************************************}
  121. {$ifdef CPUI8086}
  122. { used for an offset fixup for accessing the proc parameters in asm routines
  123. that use nostackframe. We can't use the parameter name directly, because
  124. i8086 doesn't support sp relative addressing. }
  125. const
  126. {$ifdef FPC_X86_CODE_FAR}
  127. extra_param_offset = 2;
  128. {$else FPC_X86_CODE_FAR}
  129. extra_param_offset = 0;
  130. {$endif FPC_X86_CODE_FAR}
  131. {$if defined(FPC_X86_DATA_FAR) or defined(FPC_X86_DATA_HUGE)}
  132. extra_data_offset = 2;
  133. {$else}
  134. extra_data_offset = 0;
  135. {$endif}
  136. {$endif CPUI8086}
  137. { Include ELF resources }
  138. const calculated_cmdline:PAnsiChar=nil;
  139. {$ifndef FPUNONE}
  140. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  141. {$define fpc_softfpu_implementation}
  142. {$i softfpu.pp}
  143. {$undef fpc_softfpu_implementation}
  144. { we get these functions and types from the softfpu code }
  145. {$define FPC_SYSTEM_HAS_float64}
  146. {$define FPC_SYSTEM_HAS_float32}
  147. {$define FPC_SYSTEM_HAS_flag}
  148. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  149. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  150. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  151. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  152. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  153. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  154. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  155. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  156. {$endif FPC_HAS_FEATURE_SOFTFPU}
  157. {$endif FPUNONE}
  158. {$define FPC_SYSTEM_EXIT_NO_RETURN}
  159. {$I system.inc}
  160. {*****************************************************************************
  161. Misc. System Dependent Functions
  162. *****************************************************************************}
  163. var
  164. _stack_top: record end; external name '_stack_top';
  165. { Interim fix for now, set to large address
  166. TODO: provide more realistic value, possibly by inspecting stack pointer
  167. when main or task is started
  168. }
  169. function StackTop: pointer;
  170. begin
  171. StackTop:=pointer($3fffffff);
  172. end;
  173. procedure haltproc;cdecl;external name '_haltproc';
  174. procedure System_exit;noreturn;external name '_haltproc';
  175. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  176. function GetProcessID: SizeUInt;
  177. begin
  178. GetProcessID := 0;
  179. end;
  180. {$endif}
  181. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  182. Function ParamCount: Longint;
  183. Begin
  184. Paramcount:=argc-1
  185. End;
  186. function paramstr(l: longint) : Shortstring;
  187. begin
  188. paramstr := '';
  189. end;
  190. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  191. {$ifdef FPC_HAS_FEATURE_RANDOM}
  192. procedure randomize();
  193. begin
  194. RandSeed := 63458;
  195. end;
  196. {$endif FPC_HAS_FEATURE_RANDOM}
  197. {*****************************************************************************
  198. SystemUnit Initialization
  199. *****************************************************************************}
  200. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  201. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;inline;
  202. begin
  203. result := stklen;
  204. end;
  205. var
  206. initialstkptr : record end; external name '_stack_top';
  207. {$endif FPC_HAS_FEATURE_STACKCHECK}
  208. begin
  209. { FPU (hard or soft) is initialized from fpc_cpuinit, which is included
  210. per-cpu unconditionally.
  211. SysResetFPU;
  212. if not(IsLibrary) then
  213. SysInitFPU;
  214. }
  215. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  216. IsConsole := TRUE;
  217. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  218. {$ifdef FPC_HAS_FEATURE_STACKCHECK}
  219. StackLength := CheckInitialStkLen(initialStkLen);
  220. StackBottom := @initialstkptr - StackLength;
  221. {$endif FPC_HAS_FEATURE_STACKCHECK}
  222. {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}
  223. { SysInitExceptions initializes only ExceptObjectstack and ExceptAddrStack
  224. with nil since both are located in the bss section, they are zeroed at startup
  225. anyways so not calling SysInitExceptions saves some bytes for simple programs. Even for threaded
  226. programs this does not matter because in the main thread, the variables are located
  227. in bss
  228. }
  229. SysInitExceptions;
  230. {$endif FPC_HAS_FEATURE_EXCEPTIONS}
  231. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  232. { Reset IO Error }
  233. InOutRes:=0;
  234. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  235. { $ifdef FPC_HAS_FEATURE_THREADING}
  236. { threading }
  237. InitSystemThreads;
  238. { $endif FPC_HAS_FEATURE_THREADING}
  239. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  240. initunicodestringmanager;
  241. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  242. end.