si_c.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 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 __init; cdecl; external name '__init';
  14. procedure c_exit(exit_code: cint); cdecl; noreturn; external name 'exit';
  15. function _csu_finish(_argv: PPAnsiChar; _envp: PPAnsiChar; _cleanup: TCdeclProcedure): PPPChar; cdecl; external name '_csu_finish';
  16. procedure _FPC_proc___start(argc: LongInt; argv: PPAnsiChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
  17. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  18. asm
  19. movq %rdx,%rcx
  20. movq (%rsp),%rdi
  21. leaq 16(%rsp,%rdi,8),%rdx
  22. leaq 8(%rsp),%rsi
  23. subq $8,%rsp
  24. andq $0xFFFFFFFFFFFFFFF0,%rsp
  25. addq $8,%rsp
  26. jmp _FPC_proc___start
  27. end;
  28. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; forward;
  29. procedure _csu_abort; cdecl; public name '_csu_abort';
  30. begin
  31. asm
  32. // endbr64
  33. // Not yet supported by our inline assembler reader
  34. int3
  35. end;
  36. end;
  37. procedure _FPC_proc___start(argc: LongInt; argv: PPAnsiChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
  38. var
  39. I: SizeUInt;
  40. environp: PPPChar;
  41. begin
  42. environp:=_csu_finish(argv, envp, cleanup);
  43. environ:=environp^;
  44. operatingsystem_parameter_envp:=environ;
  45. operatingsystem_parameter_argc:=argc;
  46. operatingsystem_parameter_argv:=argv;
  47. if argv[0]<>nil then
  48. begin
  49. __progname:=_strrchr(argv[0], Ord('/'));
  50. if __progname<>nil then
  51. Inc(__progname)
  52. else
  53. __progname:=argv[0];
  54. I:=Low(__progname_storage);
  55. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  56. begin
  57. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  58. Inc(I);
  59. end;
  60. __progname_storage[I]:=#0;
  61. __progname:=@__progname_storage;
  62. end;
  63. __init;
  64. PascalMain;
  65. c_exit(operatingsystem_result);
  66. end;
  67. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  68. begin
  69. c_exit(operatingsystem_result);
  70. end;
  71. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; 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;