si_dll.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. {$asmmode att}
  12. {$goto on}
  13. {
  14. Linux ELF startup code for Free Pascal
  15. Stack layout at program start:
  16. nil
  17. envn
  18. ....
  19. .... ENVIRONMENT VARIABLES
  20. env1
  21. env0
  22. nil
  23. argn
  24. ....
  25. .... COMMAND LINE OPTIONS
  26. arg1
  27. arg0
  28. argc <--- esp
  29. }
  30. procedure PASCALMAIN; external name 'PASCALMAIN';
  31. function get1eipasebx : pointer; compilerproc; nostackframe; assembler;
  32. asm
  33. movl (%esp),%ebx
  34. ret
  35. end;
  36. {******************************************************************************
  37. Shared library start/halt
  38. ******************************************************************************}
  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. { this routine is only called when the halt() routine of the RTL embedded in
  59. the shared library is called }
  60. procedure _FPC_shared_lib_haltproc; assembler; nostackframe; public name 'FPC_SHARED_LIB_EXIT'; public name '_haltproc';
  61. asm
  62. .Lhaltproc:
  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;