si_c.inc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2019 by Free Pascal development team
  4. This file implements parts of the startup code for OpenBSD
  5. programs that link to the C library.
  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. {$asmmode att}
  13. procedure __init; cdecl; external name '__init';
  14. procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
  15. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl; forward;
  16. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  17. asm
  18. pushl %ebx { ps_strings }
  19. pushl %ecx { obj }
  20. pushl %edx { cleanup }
  21. movl 12(%esp),%eax
  22. leal 20(%esp,%eax,4),%ecx
  23. leal 16(%esp),%edx
  24. pushl %ecx
  25. pushl %edx
  26. pushl %eax
  27. call _FPC_proc___start
  28. end;
  29. procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
  30. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  31. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); cdecl;
  32. var
  33. I: SizeUInt;
  34. begin
  35. environ:=envp;
  36. operatingsystem_parameter_envp:=envp;
  37. operatingsystem_parameter_argc:=argc;
  38. operatingsystem_parameter_argv:=argv;
  39. if argv[0]<>nil then
  40. begin
  41. __progname:=_strrchr(argv[0], Ord('/'));
  42. if __progname<>nil then
  43. Inc(__progname)
  44. else
  45. __progname:=argv[0];
  46. I:=Low(__progname_storage);
  47. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  48. begin
  49. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  50. Inc(I);
  51. end;
  52. __progname_storage[I]:=#0;
  53. __progname:=@__progname_storage;
  54. end;
  55. __init;
  56. PascalMain;
  57. c_exit(operatingsystem_result);
  58. end;
  59. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  60. begin
  61. c_exit(operatingsystem_result);
  62. end;
  63. function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
  64. begin
  65. _strrchr:=nil;
  66. repeat
  67. if str^=Chr(character) then
  68. _strrchr:=str;
  69. if str^<>#0 then
  70. Inc(str);
  71. until str^=#0;
  72. end;