si_c21.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. {
  12. Linux ELF startup code for Free Pascal
  13. Stack layout at program start:
  14. nil
  15. envn
  16. ....
  17. .... ENVIRONMENT VARIABLES
  18. env1
  19. env0
  20. nil
  21. argn
  22. ....
  23. .... COMMAND LINE OPTIONS
  24. arg1
  25. arg0
  26. argc <--- esp
  27. }
  28. {$asmmode att}
  29. procedure __libc_csu_init; cdecl; external;
  30. procedure __libc_csu_fini; cdecl; external;
  31. procedure libc_start_main; external name '__libc_start_main';
  32. procedure libc_exit(code: longint); cdecl; external name 'exit';
  33. {******************************************************************************
  34. glibc 2.1 lib + profiling start/halt
  35. ******************************************************************************}
  36. procedure _FPC_libc21_start; assembler; nostackframe; public name '_start';
  37. asm
  38. xorl %ebp,%ebp
  39. { First locate the start of the environment variables }
  40. popl %ecx { Get argc in ecx }
  41. movl %esp,%esi { Esp now points to the arguments }
  42. leal 4(%esp,%ecx,4),%eax { The start of the environment is: esp+4*eax+4 }
  43. andl $0xfffffff0,%esp { Align stack to 16 bytes }
  44. {$ifdef FPC_PIC}
  45. call .Lpiclab
  46. .Lpiclab:
  47. popl %ebx
  48. addl $_GLOBAL_OFFSET_TABLE_+1,%ebx
  49. movl operatingsystem_parameter_envp@GOT(%ebx),%edi
  50. movl %eax,(%edi)
  51. movl operatingsystem_parameter_argc@GOT(%ebx),%edi
  52. movl %ecx,(%edi)
  53. movl operatingsystem_parameter_argv@GOT(%ebx),%edi
  54. movl %esi,(%edi)
  55. movl initialstkptr@GOT(%ebx),%edi
  56. movl %esp,(%edi)
  57. {$else FPC_PIC}
  58. movl %eax,operatingsystem_parameter_envp
  59. movl %ecx,operatingsystem_parameter_argc
  60. movl %esi,operatingsystem_parameter_argv
  61. movl %esp,initialstkptr
  62. {$endif FPC_PIC}
  63. { int __libc_start_main(
  64. int *(main) (int, char * *, char * *),
  65. int argc,
  66. char * * ubp_av,
  67. void (*init) (void),
  68. void (*fini) (void),
  69. void (*rtld_fini) (void),
  70. void (* stack_end)); }
  71. pushl %ebp { padding }
  72. pushl %esp { stack_end }
  73. pushl %edx { function to be registered with
  74. atexit(), passed by loader }
  75. pushl $__libc_csu_fini
  76. pushl $__libc_csu_init
  77. pushl %esi { Push second argument: argv. }
  78. pushl %ecx { Push first argument: argc. }
  79. pushl $PASCALMAIN
  80. call libc_start_main
  81. hlt
  82. end;
  83. procedure _FPC_libc21_haltproc(e: longint); cdecl; assembler; public name '_haltproc';
  84. asm
  85. push e
  86. call libc_exit
  87. hlt
  88. end;