si_dll.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 '_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. procedure initdummy; assembler; nostackframe;
  49. label
  50. FPC_LIB_START;
  51. asm
  52. .init
  53. .align 16
  54. .globl FPC_LIB_START
  55. // .type FPC_LIB_START,@function
  56. FPC_LIB_START:
  57. {$ifdef FPC_PIC}
  58. jmp _FPC_shared_lib_start@PLT
  59. {$else FPC_PIC}
  60. jmp _FPC_shared_lib_start
  61. {$endif FPC_PIC}
  62. .text
  63. end;
  64. {$endif VER_2_0}
  65. procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name '_haltproc';
  66. asm
  67. {$ifdef FPC_PIC}
  68. call fpc_geteipasebx
  69. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  70. {$endif}
  71. .Lhaltproc:
  72. xorl %eax,%eax
  73. incl %eax { eax=1, exit call }
  74. {$ifdef FPC_PIC}
  75. pushl %ebx
  76. movl ExitCode@GOT(%ebx),%ebx
  77. {$if sizeof(ExitCode)=2}
  78. movzwl (%ebx),%ebx
  79. {$else}
  80. mov (%ebx),%ebx
  81. {$endif}
  82. {$endif}
  83. int $0x80
  84. jmp .Lhaltproc
  85. popl %ebx
  86. end;