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 att}
  13. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl; forward;
  14. procedure _FPC_proc_start; assembler; nostackframe; public name '_start'; public name '__start';
  15. asm
  16. movl %esp,%ebp
  17. andl $0xFFFFFFF0,%esp
  18. pushl %edx
  19. movl 0(%ebp),%eax
  20. leal 8(%ebp,%eax,4),%ecx
  21. leal 4(%ebp),%edx
  22. pushl %ecx
  23. pushl %edx
  24. pushl %eax
  25. xorl %ebp,%ebp
  26. call _FPC_proc___start
  27. end;
  28. procedure _FPC_proc_haltproc; cdecl; noreturn; forward;
  29. function _strrchr(str: PChar; character: LongInt): PChar; forward;
  30. procedure _FPC_proc___start(argc: LongInt; argv: PPChar; envp: Pointer; cleanup: TCdeclProcedure); cdecl;
  31. var
  32. I: SizeUInt;
  33. begin
  34. environ:=envp;
  35. operatingsystem_parameter_envp:=envp;
  36. operatingsystem_parameter_argc:=argc;
  37. operatingsystem_parameter_argv:=argv;
  38. if argv[0]<>nil then
  39. begin
  40. __progname:=_strrchr(argv[0], Ord('/'));
  41. if __progname<>nil then
  42. Inc(__progname)
  43. else
  44. __progname:=argv[0];
  45. I:=Low(__progname_storage);
  46. while (I<High(__progname_storage)) and (__progname[I]<>#0) do
  47. begin
  48. __progname_storage[I]:=__progname[I-Low(__progname_storage)];
  49. Inc(I);
  50. end;
  51. __progname_storage[I]:=#0;
  52. __progname:=@__progname_storage;
  53. end;
  54. PascalMain;
  55. asm
  56. jmp _FPC_proc_haltproc
  57. end;
  58. end;
  59. procedure _FPC_proc_haltproc; cdecl; noreturn; public name '_haltproc';
  60. var
  61. ExitCode: LongInt;
  62. begin
  63. ExitCode:=operatingsystem_result;
  64. asm
  65. .Lendless:
  66. pushl ExitCode
  67. mov $1,%eax
  68. call .Lactualsyscall
  69. jmp .Lendless
  70. .Lactualsyscall:
  71. int $0x80
  72. ret
  73. end;
  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;