si_g.inc 2.9 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. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); 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. procedure _FPC_proc_haltproc; noreturn; forward;
  36. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  37. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord);
  38. var
  39. I: SizeUInt;
  40. begin
  41. environ:=envp;
  42. operatingsystem_parameter_envp:=envp;
  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; 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;