si_dll.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. shared object (.so) libraries.
  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. {$ifdef VER3_0}
  14. procedure _init; external name '_init';
  15. {$else VER3_0}
  16. procedure _init; weakexternal name '_init';
  17. {$endif VER3_0}
  18. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord); forward;
  19. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  20. asm
  21. movq %rbx,%r9
  22. movq %rcx,%r8
  23. movq %rdx,%rcx
  24. movq (%rsp),%rdi
  25. leaq 16(%rsp,%rdi,8),%rdx
  26. leaq 8(%rsp),%rsi
  27. subq $8,%rsp
  28. andq $0xFFFFFFFFFFFFFFF0,%rsp
  29. addq $8,%rsp
  30. jmp _FPC_proc___start
  31. end;
  32. procedure _FPC_proc_haltproc; forward;
  33. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  34. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; para1, para2, para3: QWord);
  35. var
  36. I: SizeUInt;
  37. begin
  38. environ:=envp;
  39. operatingsystem_parameter_envp:=envp;
  40. operatingsystem_parameter_argc:=argc;
  41. operatingsystem_parameter_argv:=argv;
  42. if argv[0]<>nil then
  43. begin
  44. __progname:=_strrchr(argv[0], Ord('/'));
  45. if __progname<>nil then
  46. Inc(__progname)
  47. else
  48. __progname:=argv[0];
  49. I:=Low(__progname_storage);
  50. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  51. begin
  52. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  53. Inc(I);
  54. end;
  55. __progname_storage[I]:=#0;
  56. __progname:=@__progname_storage;
  57. end;
  58. if Assigned(@_init) then
  59. _init;
  60. PascalMain;
  61. asm
  62. jmp _FPC_proc_haltproc@PLT
  63. end;
  64. end;
  65. procedure _FPC_proc_haltproc; assembler; nostackframe; public name '_haltproc';
  66. asm
  67. movq $1,%rax
  68. movl operatingsystem_result(%rip),%ebx
  69. pushq %rbx
  70. call .Lactualsyscall
  71. addq $8,%rsp
  72. jmp _FPC_proc_haltproc
  73. .Lactualsyscall:
  74. int $0x80
  75. jb .LErrorcode
  76. xor %rbx,%rbx
  77. ret
  78. .LErrorcode:
  79. movq %rax,%rbx
  80. movq $-1,%rax
  81. end;
  82. function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
  83. begin
  84. _strrchr:=nil;
  85. repeat
  86. if str^=Chr(character) then
  87. _strrchr:=str;
  88. if str^<>#0 then
  89. Inc(str);
  90. until str^=#0;
  91. end;