si_c.pp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2019 by the Free Pascal development team
  4. System Entry point for Haiku, linked-against-libc version
  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 si_c;
  12. interface
  13. implementation
  14. { Bindings to RTL }
  15. var
  16. initialstkptr: pointer; public name '__stkptr';
  17. argc: longint; public name 'operatingsystem_parameter_argc';
  18. argv: pointer; public name 'operatingsystem_parameter_argv';
  19. envp: pointer; public name 'operatingsystem_parameter_envp';
  20. procedure PascalMain; external name 'PASCALMAIN';
  21. { Bindings to libroot/libc }
  22. const
  23. libc = 'root';
  24. var
  25. argv_save: pointer; external name 'argv_save';
  26. main_thread_id: ptruint; external name '__main_thread_id';
  27. function find_thread(name: pchar): ptruint; cdecl; external libc name 'find_thread';
  28. procedure _init_c_library_(argc: longint; argv: ppchar; env: ppchar); cdecl; external libc name '_init_c_library_';
  29. procedure _call_init_routines_; cdecl; external libc name '_call_init_routines_';
  30. procedure __exit(status: longint); cdecl; external libc name 'exit';
  31. function _FPC_proc_start(_argc: longint; _argv: pointer; _envp: pointer): longint; cdecl; public name '_start';
  32. begin
  33. initialstkptr:=get_frame;
  34. argc:=_argc;
  35. argv:=_argv;
  36. envp:=_envp;
  37. argv_save:=_argv;
  38. main_thread_id:=find_thread(nil);
  39. { This is actually only needed for BeOS R5 compatibility,
  40. they're empty stubs in Haiku, according to the C code (KB) }
  41. _init_c_library_(_argc,_argv,_envp);
  42. _call_init_routines_;
  43. PascalMain;
  44. end;
  45. procedure _FPC_proc_halt(_ExitCode: longint); cdecl; public name '_haltproc';
  46. begin
  47. { call C exit code }
  48. __exit(_ExitCode);
  49. end;
  50. end.