si_prc.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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; cleanup: TCdeclProcedure); forward;
  14. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  15. asm
  16. movq %rdx,%rcx
  17. movq (%rsp),%rdi
  18. leaq 16(%rsp,%rdi,8),%rdx
  19. leaq 8(%rsp),%rsi
  20. subq $8,%rsp
  21. andq $0xFFFFFFFFFFFFFFF0,%rsp
  22. addq $8,%rsp
  23. jmp _FPC_proc___start
  24. end;
  25. procedure _FPC_proc_haltproc; cdecl; forward;
  26. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  27. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure);
  28. var
  29. I: SizeUInt;
  30. begin
  31. environ:=envp;
  32. operatingsystem_parameter_envp:=envp;
  33. operatingsystem_parameter_argc:=argc;
  34. operatingsystem_parameter_argv:=argv;
  35. if argv[0]<>nil then
  36. begin
  37. __progname:=_strrchr(argv[0], Ord('/'));
  38. if __progname<>nil then
  39. Inc(__progname)
  40. else
  41. __progname:=argv[0];
  42. I:=Low(__progname_storage);
  43. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  44. begin
  45. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  46. Inc(I);
  47. end;
  48. __progname_storage[I]:=#0;
  49. __progname:=@__progname_storage;
  50. end;
  51. PascalMain;
  52. asm
  53. jmp _FPC_proc_haltproc
  54. end;
  55. end;
  56. procedure _FPC_proc_haltproc; cdecl; assembler; nostackframe; public name '_haltproc';
  57. asm
  58. movq $1,%rax
  59. movl operatingsystem_result(%rip),%edi
  60. syscall
  61. jmp _FPC_proc_haltproc
  62. end;
  63. function _strrchr(str: PChar; character: LongInt): PChar; public name '_strrchr';
  64. begin
  65. _strrchr:=nil;
  66. repeat
  67. if str^=Chr(character) then
  68. _strrchr:=str;
  69. if str^<>#0 then
  70. Inc(str);
  71. until str^=#0;
  72. end;