si_g.inc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 gas}
  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: PPChar; _envp: PPChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
  22. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
  23. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  24. asm
  25. movq %rdx,%rcx
  26. movq (%rsp),%rdi
  27. leaq 16(%rsp,%rdi,8),%rdx
  28. leaq 8(%rsp),%rsi
  29. subq $8,%rsp
  30. andq $0xFFFFFFFFFFFFFFF0,%rsp
  31. addq $8,%rsp
  32. jmp _FPC_proc___start
  33. end;
  34. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  35. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
  36. var
  37. I: SizeUInt;
  38. environp: PPPChar;
  39. begin
  40. environp:=_csu_finish(argv, envp, cleanup);
  41. environ:=environp^;
  42. operatingsystem_parameter_envp:=environ;
  43. operatingsystem_parameter_argc:=argc;
  44. operatingsystem_parameter_argv:=argv;
  45. if argv[0]<>nil then
  46. begin
  47. __progname:=_strrchr(argv[0], Ord('/'));
  48. if __progname<>nil then
  49. Inc(__progname)
  50. else
  51. __progname:=argv[0];
  52. I:=Low(__progname_storage);
  53. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  54. begin
  55. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  56. Inc(I);
  57. end;
  58. __progname_storage[I]:=#0;
  59. __progname:=@__progname_storage;
  60. end;
  61. atexit(@_mcleanup);
  62. _monstartup(u_long(@_eprol),u_long(@_etext));
  63. __init;
  64. PascalMain;
  65. c_exit(operatingsystem_result);
  66. end;
  67. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  68. begin
  69. c_exit(operatingsystem_result);
  70. end;
  71. function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
  72. begin
  73. _strrchr:=nil;
  74. repeat
  75. if str^=Chr(character) then
  76. _strrchr:=str;
  77. if str^<>#0 then
  78. Inc(str);
  79. until str^=#0;
  80. end;
  81. procedure MD_EPROL_LABEL; assembler; nostackframe; public name '_eprol';
  82. asm
  83. end;