si_c.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 att}
  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. movl %esp,%ebp
  20. andl $0xFFFFFFF0,%esp
  21. pushl %edx
  22. movl 0(%ebp),%eax
  23. leal 8(%ebp,%eax,4),%ecx
  24. leal 4(%ebp),%edx
  25. pushl %ecx
  26. pushl %edx
  27. pushl %eax
  28. xorl %ebp,%ebp
  29. call _FPC_proc___start
  30. end;
  31. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; forward;
  32. procedure _FPC_proc___start(argc: LongInt; argv: PPAnsiChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
  33. var
  34. I: SizeUInt;
  35. environp: PPPChar;
  36. begin
  37. environp:=_csu_finish(argv, envp, cleanup);
  38. environ:=environp^;
  39. operatingsystem_parameter_envp:=environ;
  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. __init;
  59. PascalMain;
  60. c_exit(operatingsystem_result);
  61. end;
  62. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  63. begin
  64. c_exit(operatingsystem_result);
  65. end;
  66. function _strrchr(str: PAnsiChar; character: LongInt): PAnsiChar; public name '_strrchr';
  67. begin
  68. _strrchr:=nil;
  69. repeat
  70. if str^=Chr(character) then
  71. _strrchr:=str;
  72. if str^<>#0 then
  73. Inc(str);
  74. until str^=#0;
  75. end;