si_g.inc 2.9 KB

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