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