system.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. System unit for Linux.
  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 System;
  17. {*****************************************************************************}
  18. interface
  19. {*****************************************************************************}
  20. {$define FPC_IS_SYSTEM}
  21. {$define HAS_CMDLINE}
  22. {$define USE_NOTHREADMANAGER}
  23. {$i osdefs.inc}
  24. {$I sysunixh.inc}
  25. {$if defined(VER3_0) and defined(CPUX86_64)}
  26. {$define FPC_BOOTSTRAP_INDIRECT_ENTRY}
  27. const
  28. { this constant only exists during bootstrapping of the RTL with FPC 3.0.x,
  29. so that the whole condition doesn't need to be repeated in si_intf }
  30. indirect_bootstrap = true;
  31. {$endif defined(VER3_0) and defined(CPUX86_64)}
  32. function get_cmdline:Pchar; deprecated 'use paramstr' ;
  33. property cmdline:Pchar read get_cmdline;
  34. {$if defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
  35. {$define FPC_LOAD_SOFTFPU}
  36. {$endif defined(CPURISCV32) or defined(CPURISCV64) or defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))}
  37. {$ifdef FPC_SOFT_FPUX80}
  38. {$define FPC_SOFTFLOAT_FLOATX80}
  39. {$define LOAD_SOFTFPU}
  40. {$endif}
  41. {$ifdef FPC_SOFT_FPU128}
  42. {$define FPC_SOFTFLOAT_FLOAT128}
  43. {$define FPC_LOAD_SOFTFPU}
  44. {$endif}
  45. {$ifdef FPC_LOAD_SOFTFPU}
  46. {$define fpc_softfpu_interface}
  47. {$i softfpu.pp}
  48. {$undef fpc_softfpu_interface}
  49. {$endif FPC_LOAD_SOFTFPU}
  50. {$ifdef android}
  51. {$I sysandroidh.inc}
  52. {$endif android}
  53. {*****************************************************************************}
  54. implementation
  55. {*****************************************************************************}
  56. {$if defined(CPUI386) and not defined(FPC_USE_LIBC)}
  57. var
  58. sysenter_supported: LongInt = 0;
  59. {$endif}
  60. const
  61. calculated_cmdline:Pchar=nil;
  62. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  63. {$define FPC_SYSTEM_HAS_OSSETUPENTRYINFORMATION}
  64. procedure OsSetupEntryInformation(constref info: TEntryInformation); forward;
  65. {$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  66. {$ifdef FPC_LOAD_SOFTFPU}
  67. {$define fpc_softfpu_implementation}
  68. {$if defined(CPUM68K)}
  69. {$define softfpu_compiler_mul32to64}
  70. {$define softfpu_inline}
  71. {$endif}
  72. {$i softfpu.pp}
  73. {$undef fpc_softfpu_implementation}
  74. { we get these functions and types from the softfpu code }
  75. {$define FPC_SYSTEM_HAS_float64}
  76. {$define FPC_SYSTEM_HAS_float32}
  77. {$define FPC_SYSTEM_HAS_flag}
  78. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  79. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  80. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  81. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  82. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  83. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  84. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  85. {$endif FPC_LOAD_SOFTFPU}
  86. {$I system.inc}
  87. {$ifdef android}
  88. {$I sysandroid.inc}
  89. {$endif android}
  90. {*****************************************************************************
  91. TLS handling
  92. *****************************************************************************}
  93. {$if defined(CPUARM)}
  94. {$define INITTLS}
  95. Function fpset_tls(p : pointer;size : SizeUInt):cint;
  96. begin
  97. Result:=do_syscall(syscall_nr___ARM_NR_set_tls,TSysParam(p));
  98. end;
  99. {$endif defined(CPUARM)}
  100. {$if defined(CPUI386)}
  101. {$define INITTLS}
  102. Function fpset_tls(p : pointer;size : SizeUInt):cint;
  103. var
  104. desc : record
  105. entry_number : dword;
  106. base_addr : dword;
  107. limit : dword;
  108. flags : dword;
  109. end;
  110. selector : word;
  111. begin
  112. // get descriptor from the kernel
  113. desc.entry_number:=$ffffffff;
  114. // TLS is accessed by negative offsets, only the TCB pointer is at offset 0
  115. desc.base_addr:=dword(p)+size-SizeOf(Pointer);
  116. // 4 GB, limit is given in pages
  117. desc.limit:=$fffff;
  118. // seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1
  119. desc.flags:=%1010001;
  120. Result:=do_syscall(syscall_nr_set_thread_area,TSysParam(@desc));
  121. if Result=0 then
  122. begin
  123. selector:=desc.entry_number*8+3;
  124. asm
  125. movw selector,%gs
  126. movl desc.base_addr,%eax
  127. movl %eax,%gs:0
  128. end;
  129. end;
  130. end;
  131. {$endif defined(CPUI386)}
  132. {$if defined(CPUX86_64)}
  133. {$define INITTLS}
  134. const
  135. ARCH_SET_FS = $1002;
  136. Function fpset_tls(p : pointer;size : SizeUInt):cint;
  137. begin
  138. p:=pointer(qword(p)+size-SizeOf(Pointer));
  139. Result:=do_syscall(syscall_nr_arch_prctl,TSysParam(ARCH_SET_FS),TSysParam(p));
  140. if Result=0 then
  141. begin
  142. asm
  143. movq p,%rax
  144. movq %rax,%fs:0
  145. end;
  146. end;
  147. end;
  148. {$endif defined(CPUX86_64)}
  149. {$ifdef INITTLS}
  150. { This code initialized the TLS segment for single threaded and static programs.
  151. In case of multithreaded and/or dynamically linked programs it is assumed that they
  152. dependent anyways on glibc which initializes tls properly.
  153. As soon as a purely FPC dynamic loading or multithreading is implemented, the code
  154. needs to be extended to handle these cases as well.
  155. }
  156. procedure InitTLS; [public,alias:'FPC_INITTLS'];
  157. const
  158. PT_TLS = 7;
  159. PT_DYNAMIC = 2;
  160. type
  161. {$ifdef CPU64}
  162. tphdr = record
  163. p_type,
  164. p_flags : dword;
  165. p_offset,
  166. p_vaddr,
  167. p_paddr,
  168. p_filesz,
  169. p_memsz,
  170. p_align : qword;
  171. end;
  172. {$else CPU64}
  173. tphdr = record
  174. p_type,
  175. p_offset,
  176. p_vaddr,
  177. p_paddr,
  178. p_filesz,
  179. p_memsz,
  180. p_flags,
  181. p_align : dword;
  182. end;
  183. {$endif CPU64}
  184. pphdr = ^tphdr;
  185. var
  186. phdr : pphdr;
  187. phnum : dword;
  188. i : integer;
  189. tls : pointer;
  190. auxp : ppointer;
  191. found : boolean;
  192. size : SizeUInt;
  193. begin
  194. auxp:=ppointer(envp);
  195. { skip environment }
  196. while assigned(auxp^) do
  197. inc(auxp);
  198. inc(auxp);
  199. phdr:=nil;
  200. phnum:=0;
  201. { now we are at the auxillary vector }
  202. while assigned(auxp^) do
  203. begin
  204. case plongint(auxp)^ of
  205. 3:
  206. phdr:=pphdr(ppointer(auxp+1)^);
  207. 5:
  208. phnum:=pdword(auxp+1)^;
  209. end;
  210. inc(auxp,2);
  211. end;
  212. found:=false;
  213. size:=0;
  214. for i:=1 to phnum do
  215. begin
  216. case phdr^.p_type of
  217. PT_TLS:
  218. begin
  219. found:=true;
  220. inc(size,phdr^.p_memsz);
  221. size:=Align(size,phdr^.p_align);
  222. end;
  223. PT_DYNAMIC:
  224. { if the program header contains a dynamic section, the program
  225. is linked dynamically so the dynamic linker takes care of the
  226. allocation of the TLS segment.
  227. We cannot allocate it by ourself anyways as PT_TLS provides only
  228. the size of TLS data of the executable itself
  229. }
  230. exit;
  231. end;
  232. inc(phdr);
  233. end;
  234. if found then
  235. begin
  236. {$ifdef CPUI386}
  237. { threadvars should start at a page boundary,
  238. add extra space for the TCB }
  239. size:=Align(size,4096)+sizeof(Pointer);
  240. {$endif CPUI386}
  241. {$ifdef CPUX86_64}
  242. { threadvars should start at a page boundary,
  243. add extra space for the TCB }
  244. size:=Align(size,4096)+sizeof(Pointer);
  245. {$endif CPUX86_64}
  246. tls:=Fpmmap(nil,size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0);
  247. fpset_tls(tls,size);
  248. end;
  249. end;
  250. {$endif INITTLS}
  251. {*****************************************************************************
  252. Indirect Entry Point
  253. *****************************************************************************}
  254. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  255. var
  256. initialstkptr : Pointer;
  257. procedure OsSetupEntryInformation(constref info: TEntryInformation);
  258. begin
  259. argc := info.OS.argc;
  260. argv := info.OS.argv;
  261. envp := info.OS.envp;
  262. initialstkptr := info.OS.stkptr;
  263. initialstklen := info.OS.stklen;
  264. end;
  265. { we need two variants here because TLS must be initialized by FPC only if no libc is linked however,
  266. InitTLS cannot be called from the start up files because when they are run, envp is not setup yet.}
  267. procedure SysEntry(constref info: TEntryInformation);[public,alias:'FPC_SysEntry'];
  268. begin
  269. SetupEntryInformation(info);
  270. {$ifdef cpui386}
  271. Set8087CW(Default8087CW);
  272. {$endif cpui386}
  273. info.PascalMain();
  274. end;
  275. procedure SysEntry_InitTLS(constref info: TEntryInformation);[public,alias:'FPC_SysEntry_InitTLS'];
  276. begin
  277. SetupEntryInformation(info);
  278. {$ifdef INITTLS}
  279. InitTLS;
  280. {$endif INITTLS}
  281. {$ifdef cpui386}
  282. Set8087CW(Default8087CW);
  283. {$endif cpui386}
  284. info.PascalMain();
  285. end;
  286. {$else}
  287. var
  288. {$ifndef FPC_BOOTSTRAP_INDIRECT_ENTRY}
  289. initialstkptr : Pointer;external name '__stkptr';
  290. {$else FPC_BOOTSTRAP_INDIRECT_ENTRY}
  291. initialstkptr : Pointer; public name '__stkptr';
  292. operatingsystem_parameter_envp : Pointer; public name 'operatingsystem_parameter_envp';
  293. operatingsystem_parameter_argc : LongInt; public name 'operatingsystem_parameter_argc';
  294. operatingsystem_parameter_argv : Pointer; public name 'operatingsystem_parameter_argv';
  295. { we need two variants here because TLS must be initialized by FPC only if no libc is linked however,
  296. InitTLS cannot be called from the start up files because when they are run, envp is not setup yet.}
  297. procedure SysEntry(constref info: TEntryInformation);[public,alias:'FPC_SysEntry'];
  298. begin
  299. initialstkptr := info.OS.stkptr;
  300. operatingsystem_parameter_envp := info.OS.envp;
  301. operatingsystem_parameter_argc := info.OS.argc;
  302. operatingsystem_parameter_argv := info.OS.argv;
  303. {$ifdef cpui386}
  304. Set8087CW(Default8087CW);
  305. {$endif cpui386}
  306. info.PascalMain();
  307. end;
  308. procedure SysEntry_InitTLS(constref info: TEntryInformation);[public,alias:'FPC_SysEntry_InitTLS'];
  309. begin
  310. initialstkptr := info.OS.stkptr;
  311. operatingsystem_parameter_envp := info.OS.envp;
  312. operatingsystem_parameter_argc := info.OS.argc;
  313. operatingsystem_parameter_argv := info.OS.argv;
  314. {$ifdef INITTLS}
  315. InitTLS;
  316. {$endif INITTLS}
  317. {$ifdef cpui386}
  318. Set8087CW(Default8087CW);
  319. {$endif cpui386}
  320. info.PascalMain();
  321. end;
  322. {$endif FPC_BOOTSTRAP_INDIRECT_ENTRY}
  323. {$if defined(CPUARM) and defined(FPC_ABI_EABI)}
  324. procedure haltproc(e:longint);cdecl;external name '_haltproc_eabi';
  325. {$else}
  326. procedure haltproc(e:longint);cdecl;external name '_haltproc';
  327. {$endif}
  328. {$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  329. {*****************************************************************************
  330. Misc. System Dependent Functions
  331. *****************************************************************************}
  332. {$ifdef FPC_USE_LIBC}
  333. function FpPrCtl(options : cInt; const args : ptruint) : cint; cdecl; external clib name 'prctl';
  334. {$endif}
  335. procedure System_exit;
  336. begin
  337. {$ifdef FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  338. EntryInformation.OS.haltproc(ExitCode);
  339. {$else FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  340. haltproc(ExitCode);
  341. {$endif FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  342. End;
  343. Function ParamCount: Longint;
  344. Begin
  345. Paramcount:=argc-1
  346. End;
  347. {function BackPos(c:char; const s: shortstring): integer;
  348. var
  349. i: integer;
  350. Begin
  351. for i:=length(s) downto 0 do
  352. if s[i] = c then break;
  353. if i=0 then
  354. BackPos := 0
  355. else
  356. BackPos := i;
  357. end;}
  358. { variable where full path and filename and executable is stored }
  359. { is setup by the startup of the system unit. }
  360. var
  361. execpathstr : shortstring;
  362. function paramstr(l: longint) : string;
  363. begin
  364. { stricly conforming POSIX applications }
  365. { have the executing filename as argv[0] }
  366. if l=0 then
  367. begin
  368. paramstr := execpathstr;
  369. end
  370. else if (l < argc) then
  371. paramstr:=strpas(argv[l])
  372. else
  373. paramstr:='';
  374. end;
  375. Procedure Randomize;
  376. Begin
  377. randseed:=longint(Fptime(nil));
  378. End;
  379. {*****************************************************************************
  380. cmdline
  381. *****************************************************************************}
  382. procedure SetupCmdLine;
  383. var
  384. bufsize,
  385. len,j,
  386. size,i : longint;
  387. found : boolean;
  388. buf : pchar;
  389. procedure AddBuf;
  390. var
  391. p : Pchar;
  392. begin
  393. p:=SysGetmem(size+bufsize);
  394. move(calculated_cmdline^,p^,size);
  395. move(buf^,p[size],bufsize);
  396. inc(size,bufsize);
  397. sysfreemem(calculated_cmdline);
  398. calculated_cmdline:=p;
  399. bufsize:=0;
  400. end;
  401. begin
  402. if argc<=0 then
  403. exit;
  404. Buf:=SysGetMem(ARG_MAX);
  405. size:=0;
  406. bufsize:=0;
  407. i:=0;
  408. while (i<argc) do
  409. begin
  410. len:=strlen(argv[i]);
  411. if len>ARG_MAX-2 then
  412. len:=ARG_MAX-2;
  413. found:=false;
  414. for j:=1 to len do
  415. if argv[i][j]=' ' then
  416. begin
  417. found:=true;
  418. break;
  419. end;
  420. found:=found or (len=0); // also quote if len=0, bug 19114
  421. if bufsize+len>=ARG_MAX-2 then
  422. AddBuf;
  423. if found then
  424. begin
  425. buf[bufsize]:='"';
  426. inc(bufsize);
  427. end;
  428. if len>0 then
  429. begin
  430. move(argv[i]^,buf[bufsize],len);
  431. inc(bufsize,len);
  432. end;
  433. if found then
  434. begin
  435. buf[bufsize]:='"';
  436. inc(bufsize);
  437. end;
  438. if i<argc-1 then
  439. buf[bufsize]:=' '
  440. else
  441. buf[bufsize]:=#0;
  442. inc(bufsize);
  443. inc(i);
  444. end;
  445. AddBuf;
  446. SysFreeMem(buf);
  447. end;
  448. function get_cmdline:Pchar;
  449. begin
  450. if calculated_cmdline=nil then
  451. setupcmdline;
  452. get_cmdline:=calculated_cmdline;
  453. end;
  454. {*****************************************************************************
  455. SystemUnit Initialization
  456. *****************************************************************************}
  457. function reenable_signal(sig : longint) : boolean;
  458. var
  459. e : TSigSet;
  460. i,j : byte;
  461. olderrno: cint;
  462. begin
  463. fillchar(e,sizeof(e),#0);
  464. { set is 1 based PM }
  465. dec(sig);
  466. i:=sig mod (sizeof(cuLong) * 8);
  467. j:=sig div (sizeof(cuLong) * 8);
  468. e[j]:=1 shl i;
  469. { this routine is called from a signal handler, so must not change errno }
  470. olderrno:=geterrno;
  471. fpsigprocmask(SIG_UNBLOCK,@e,nil);
  472. reenable_signal:=geterrno=0;
  473. seterrno(olderrno);
  474. end;
  475. // signal handler is arch dependant due to processorexception to language
  476. // exception translation
  477. {$i sighnd.inc}
  478. procedure InstallDefaultSignalHandler(signum: longint; out oldact: SigActionRec); public name '_FPC_INSTALLDEFAULTSIGHANDLER';
  479. var
  480. act: SigActionRec;
  481. begin
  482. { Initialize the sigaction structure }
  483. { all flags and information set to zero }
  484. FillChar(act, sizeof(SigActionRec),0);
  485. { initialize handler }
  486. act.sa_handler := SigActionHandler(@SignalToRunError);
  487. act.sa_flags:=SA_SIGINFO;
  488. FpSigAction(signum,@act,@oldact);
  489. end;
  490. var
  491. oldsigfpe: SigActionRec; public name '_FPC_OLDSIGFPE';
  492. oldsigsegv: SigActionRec; public name '_FPC_OLDSIGSEGV';
  493. oldsigbus: SigActionRec; public name '_FPC_OLDSIGBUS';
  494. oldsigill: SigActionRec; public name '_FPC_OLDSIGILL';
  495. Procedure InstallSignals;
  496. begin
  497. InstallDefaultSignalHandler(SIGFPE,oldsigfpe);
  498. InstallDefaultSignalHandler(SIGSEGV,oldsigsegv);
  499. InstallDefaultSignalHandler(SIGBUS,oldsigbus);
  500. InstallDefaultSignalHandler(SIGILL,oldsigill);
  501. end;
  502. procedure SysInitStdIO;
  503. begin
  504. OpenStdIO(Input,fmInput,StdInputHandle);
  505. OpenStdIO(Output,fmOutput,StdOutputHandle);
  506. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  507. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  508. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  509. {$ifdef android}
  510. InitStdIOAndroid;
  511. {$endif android}
  512. end;
  513. Procedure RestoreOldSignalHandlers;
  514. begin
  515. FpSigAction(SIGFPE,@oldsigfpe,nil);
  516. FpSigAction(SIGSEGV,@oldsigsegv,nil);
  517. FpSigAction(SIGBUS,@oldsigbus,nil);
  518. FpSigAction(SIGILL,@oldsigill,nil);
  519. end;
  520. procedure SysInitExecPath;
  521. var
  522. i : longint;
  523. begin
  524. execpathstr[0]:=#0;
  525. i:=Fpreadlink('/proc/self/exe',@execpathstr[1],high(execpathstr));
  526. { it must also be an absolute filename, linux 2.0 points to a memory
  527. location so this will skip that }
  528. if (i>0) and (execpathstr[1]='/') then
  529. execpathstr[0]:=char(i);
  530. end;
  531. function GetProcessID: SizeUInt;
  532. begin
  533. GetProcessID := SizeUInt (fpGetPID);
  534. end;
  535. {$ifdef FPC_USE_LIBC}
  536. {$ifdef HAS_UGETRLIMIT}
  537. { there is no ugetrlimit libc call, just map it to the getrlimit call in these cases }
  538. function FpUGetRLimit(resource : cInt; rlim : PRLimit) : cInt; cdecl; external clib name 'getrlimit';
  539. {$endif}
  540. {$endif}
  541. {$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
  542. const
  543. page_size = $10000;
  544. {$define LAST_PAGE_GENERATES_SIGNAL}
  545. {$else}
  546. const
  547. page_size = $1000;
  548. {$endif}
  549. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  550. var
  551. limits : TRLimit;
  552. success : boolean;
  553. begin
  554. success := false;
  555. fillchar(limits, sizeof(limits), 0);
  556. {$ifdef has_ugetrlimit}
  557. success := fpugetrlimit(RLIMIT_STACK, @limits)=0;
  558. {$endif}
  559. {$ifndef NO_SYSCALL_GETRLIMIT}
  560. if (not success) then
  561. success := fpgetrlimit(RLIMIT_STACK, @limits)=0;
  562. {$endif}
  563. if (success) and (limits.rlim_cur < stklen) then
  564. result := limits.rlim_cur
  565. else
  566. result := stklen;
  567. end;
  568. {$if FPC_FULLVERSION>30200}
  569. {$if defined(CPUI386) or defined(CPUARM)}
  570. {$I abitag.inc}
  571. {$endif defined(CPUI386) or defined(CPUARM)}
  572. {$endif FPC_FULLVERSION>30200}
  573. begin
  574. {$if defined(i386) and not defined(FPC_USE_LIBC)}
  575. InitSyscallIntf;
  576. {$endif}
  577. {$ifndef FPUNONE}
  578. {$if defined(cpupowerpc)}
  579. // some PPC kernels set the exception bits FE0/FE1 in the MSR to zero,
  580. // disabling all FPU exceptions. Enable them again.
  581. fpprctl(PR_SET_FPEXC, PR_FP_EXC_PRECISE);
  582. {$endif}
  583. {$endif}
  584. IsConsole := TRUE;
  585. StackLength := CheckInitialStkLen(initialStkLen);
  586. StackBottom := pointer(ptruint((ptruint(initialstkptr) or (page_size - 1)) + 1 - StackLength));
  587. {$ifdef LAST_PAGE_GENERATES_SIGNAL}
  588. StackBottom:=StackBottom + page_size;
  589. {$endif}
  590. { Set up signals handlers (may be needed by init code to test cpu features) }
  591. InstallSignals;
  592. {$if defined(cpui386) or defined(cpuarm)}
  593. fpc_cpucodeinit;
  594. {$endif cpui386}
  595. { Setup heap }
  596. InitHeap;
  597. SysInitExceptions;
  598. initunicodestringmanager;
  599. { Setup stdin, stdout and stderr }
  600. SysInitStdIO;
  601. { Arguments }
  602. SysInitExecPath;
  603. { Reset IO Error }
  604. InOutRes:=0;
  605. { threading }
  606. InitSystemThreads;
  607. { dynamic libraries }
  608. InitSystemDynLibs;
  609. {$ifdef android}
  610. InitAndroid;
  611. {$endif android}
  612. { restore original signal handlers in case this is a library }
  613. if IsLibrary then
  614. RestoreOldSignalHandlers;
  615. end.