si_dll.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name '_start';
  34. begin
  35. { we've to discuss about the use of this ;) }
  36. asm
  37. { Save initial stackpointer }
  38. movl %esp,initialstkptr
  39. end;
  40. operatingsystem_parameter_argc:=argc; { Copy the argument count }
  41. operatingsystem_parameter_argv:=argv; { Copy the argument pointer }
  42. operatingsystem_parameter_envp:=envp; { Copy the environment pointer }
  43. IsLibrary:=true;
  44. PASCALMAIN;
  45. end;
  46. {$ifndef VER2_0}
  47. procedure initdummy; assembler; nostackframe;
  48. label
  49. FPC_LIB_START;
  50. asm
  51. .init
  52. .align 16
  53. .globl FPC_LIB_START
  54. // .type FPC_LIB_START,@function
  55. FPC_LIB_START:
  56. {$ifdef FPC_PIC}
  57. jmp _FPC_shared_lib_start@PLT
  58. {$else FPC_PIC}
  59. jmp _FPC_shared_lib_start
  60. {$endif FPC_PIC}
  61. .text
  62. end;
  63. {$endif VER_2_0}
  64. procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name '_haltproc';
  65. asm
  66. {$ifdef FPC_PIC}
  67. call fpc_geteipasebx
  68. addl $_GLOBAL_OFFSET_TABLE_,%ebx
  69. {$endif}
  70. .Lhaltproc:
  71. xorl %eax,%eax
  72. incl %eax { eax=1, exit call }
  73. {$ifdef FPC_PIC}
  74. pushl %ebx
  75. movl ExitCode@GOT(%ebx),%ebx
  76. {$if sizeof(ExitCode)=2}
  77. movzwl (%ebx),%ebx
  78. {$else}
  79. mov (%ebx),%ebx
  80. {$endif}
  81. {$endif}
  82. int $0x80
  83. jmp .Lhaltproc
  84. popl %ebx
  85. end;