si_dll.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Michael Van Canneyt, Peter Vreman,
  4. & Daniel Mantione, members of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$goto on}
  12. {
  13. Linux ELF startup code for Free Pascal
  14. Stack layout at program start:
  15. nil
  16. envn
  17. ....
  18. .... ENVIRONMENT VARIABLES
  19. env1
  20. env0
  21. nil
  22. argn
  23. ....
  24. .... COMMAND LINE OPTIONS
  25. arg1
  26. arg0
  27. argc <--- esp
  28. }
  29. procedure PASCALMAIN; external name 'PASCALMAIN';
  30. function get1eipasebx : pointer; compilerproc; nostackframe; assembler;
  31. asm
  32. movl (%esp),%ebx
  33. ret
  34. end;
  35. {******************************************************************************
  36. Shared library start/halt
  37. ******************************************************************************}
  38. {$asmmode ATT}
  39. procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name 'FPC_SHARED_LIB_START'; public name '_start';
  40. begin
  41. operatingsystem_parameter_argc:=argc; { Copy the argument count }
  42. operatingsystem_parameter_argv:=argv; { Copy the argument pointer }
  43. operatingsystem_parameter_envp:=envp; { Copy the environment pointer }
  44. IsLibrary:=true;
  45. asm
  46. { Save initial stackpointer }
  47. {$ifdef FPC_PIC}
  48. call get1eipasebx
  49. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  50. movl initialstkptr@GOT(%ebx),%ecx
  51. movl %esp,(%ecx)
  52. {$else FPC_PIC}
  53. movl %esp,initialstkptr
  54. {$endif FPC_PIC}
  55. end;
  56. PASCALMAIN;
  57. end;
  58. Procedure lib_exit; external name 'FPC_LIB_EXIT';
  59. procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name 'FPC_SHARED_LIB_EXIT'; public name '_haltproc';
  60. asm
  61. .Lhaltproc:
  62. call lib_exit
  63. {$ifdef FPC_PIC}
  64. call get1eipasebx
  65. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  66. movl ExitCode@GOT(%ebx),%ebx
  67. {$if sizeof(ExitCode)=2}
  68. movzwl (%ebx),%ebx
  69. {$else}
  70. mov (%ebx),%ebx
  71. {$endif}
  72. {$else FPC_PIC}
  73. {$if sizeof(ExitCode)=2}
  74. movzwl ExitCode,%ebx
  75. {$else}
  76. mov ExitCode,%ebx
  77. {$endif}
  78. {$endif FPC_PIC}
  79. xorl %eax,%eax
  80. incl %eax { eax=1, exit call }
  81. int $0x80
  82. jmp .Lhaltproc
  83. end;