si_dll.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. {******************************************************************************
  31. Shared library start/halt
  32. ******************************************************************************}
  33. {$asmmode ATT}
  34. procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name '_FPC_SHARED_LIB_START_LOCAL'; public name '_start';
  35. begin
  36. { we've to discuss about the use of this ;) }
  37. asm
  38. { Save initial stackpointer }
  39. movl %esp,initialstkptr
  40. end;
  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. PASCALMAIN;
  46. end;
  47. {$ifndef VER2_0}
  48. { this hack is needed so we can make the reference below to _FPC_shared_lib_start }
  49. { local in compiler/systems/t_linux.pas }
  50. procedure _FPC_SHARED_LIB_START_LOCAL(argc : dword;argv,envp : pointer); cdecl; external;
  51. procedure initdummy; assembler; nostackframe;
  52. label
  53. FPC_LIB_START;
  54. asm
  55. .init
  56. .align 16
  57. .globl FPC_LIB_START
  58. // .type FPC_LIB_START,@function
  59. FPC_LIB_START:
  60. {$ifdef FPC_PIC}
  61. jmp _FPC_SHARED_LIB_START_LOCAL@PLT
  62. {$else FPC_PIC}
  63. jmp _FPC_SHARED_LIB_START_LOCAL
  64. {$endif FPC_PIC}
  65. .text
  66. end;
  67. {$endif VER_2_0}
  68. procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name '_haltproc';
  69. asm
  70. {$ifdef FPC_PIC}
  71. call fpc_geteipasebx
  72. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  73. {$endif}
  74. .Lhaltproc:
  75. xorl %eax,%eax
  76. incl %eax { eax=1, exit call }
  77. {$ifdef FPC_PIC}
  78. pushl %ebx
  79. movl ExitCode@GOT(%ebx),%ebx
  80. {$if sizeof(ExitCode)=2}
  81. movzwl (%ebx),%ebx
  82. {$else}
  83. mov (%ebx),%ebx
  84. {$endif}
  85. {$endif}
  86. int $0x80
  87. jmp .Lhaltproc
  88. popl %ebx
  89. end;