si_g.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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, compiled with gprof support.
  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. var
  14. _etext: Byte; external name '_etext';
  15. _eprol: Byte; external name '_eprol';
  16. procedure _mcleanup; cdecl; external name '_mcleanup';
  17. function atexit(proc: TCdeclProcedure): cint; cdecl; external name 'atexit';
  18. procedure _monstartup(lowpc, highpc: u_long); cdecl; external name '_monstartup';
  19. procedure __init; cdecl; external name '__init';
  20. procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
  21. function _csu_finish(_argv: PPAnsiChar; _envp: PPAnsiChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
  22. procedure _FPC_proc___start(argc: LongInt; argv: PPAnsiChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
  23. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  24. asm
  25. movl %esp,%ebp
  26. andl $0xFFFFFFF0,%esp
  27. pushl %edx
  28. movl 0(%ebp),%eax
  29. leal 8(%ebp,%eax,4),%ecx
  30. leal 4(%ebp),%edx
  31. pushl %ecx
  32. pushl %edx
  33. pushl %eax
  34. xorl %ebp,%ebp
  35. call _FPC_proc___start
  36. end;
  37. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; forward;
  38. procedure _FPC_proc___start(argc: LongInt; argv: PPAnsiChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
  39. var
  40. I: SizeUInt;
  41. environp: PPPChar;
  42. begin
  43. environp:=_csu_finish(argv, envp, cleanup);
  44. environ:=environp^;
  45. operatingsystem_parameter_envp:=environ;
  46. operatingsystem_parameter_argc:=argc;
  47. operatingsystem_parameter_argv:=argv;
  48. if argv[0]<>nil then
  49. begin
  50. __progname:=_strrchr(argv[0], Ord('/'));
  51. if __progname<>nil then
  52. Inc(__progname)
  53. else
  54. __progname:=argv[0];
  55. I:=Low(__progname_storage);
  56. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  57. begin
  58. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  59. Inc(I);
  60. end;
  61. __progname_storage[I]:=#0;
  62. __progname:=@__progname_storage;
  63. end;
  64. atexit(@_mcleanup);
  65. _monstartup(u_long(@_eprol),u_long(@_etext));
  66. __init;
  67. PascalMain;
  68. c_exit(operatingsystem_result);
  69. end;
  70. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  71. begin
  72. c_exit(operatingsystem_result);
  73. end;
  74. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; public name '_strrchr';
  75. begin
  76. _strrchr:=nil;
  77. repeat
  78. if str^=Chr(character) then
  79. _strrchr:=str;
  80. if str^<>#0 then
  81. Inc(str);
  82. until str^=#0;
  83. end;
  84. procedure MD_EPROL_LABEL; assembler; nostackframe; public name '_eprol';
  85. asm
  86. end;