si_c21.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. var
  29. libc21_fpc_ret, libc21_fpc_ret_ebx, libc21_fpc_ret_ebp: ptrint; { return address to libc }
  30. procedure libc_exit; external name '__libc_exit';
  31. procedure libc_init; external name '__libc_init';
  32. procedure libc_setfpucw; external name '__setfpucw';
  33. procedure libc_start_main; external name '__libc_start_main';
  34. procedure PASCALMAIN; external name 'PASCALMAIN';
  35. {******************************************************************************
  36. glibc 2.1 library start/halt
  37. ******************************************************************************}
  38. {$asmmode ATT}
  39. procedure _FPC_libc21_start; assembler; nostackframe; public name '_start';
  40. asm
  41. { First locate the start of the environment variables }
  42. popl %esi
  43. movl %eax,%edi
  44. movl %esp,%ebx { Points to the arguments }
  45. movl %esi,%eax
  46. incl %eax
  47. shll $2,%eax
  48. addl %esp,%eax
  49. andl $0xfffffff8,%esp { Align stack }
  50. movl %eax,operatingsystem_parameter_envp { Move the environment pointer }
  51. movl %esi,operatingsystem_parameter_argc { Move the argument counter }
  52. movl %ebx,operatingsystem_parameter_argv { Move the argument pointer }
  53. xorl %ebp,%ebp
  54. pushl %edi
  55. pushl %esp
  56. pushl %edx
  57. pushl $.Lfini_dummy
  58. pushl $.Linit_dummy
  59. pushl %ebx
  60. pushl %esi
  61. pushl $.Lmain
  62. call libc_start_main
  63. .Linit_dummy:
  64. .Lfini_dummy:
  65. ret
  66. { fake main routine which will be run from libc }
  67. .Lmain:
  68. { save return address }
  69. popl %eax
  70. movl %eax,libc21_fpc_ret
  71. movl %ebx,libc21_fpc_ret_ebx
  72. movl %ebp,libc21_fpc_ret_ebp
  73. pushl %eax
  74. { Save initial stackpointer }
  75. movl %esp,initialstkptr
  76. { start the program }
  77. xorl %ebp,%ebp
  78. call PASCALMAIN
  79. hlt
  80. end;
  81. procedure _FPC_libc21_haltproc; assembler; nostackframe; public name '_haltproc';
  82. asm
  83. {$if sizeof(ExitCode)=2}
  84. movzwl ExitCode,%eax
  85. {$else}
  86. mov ExitCode,%eax
  87. {$endif}
  88. movl libc21_fpc_ret,%edx { return to libc }
  89. movl libc21_fpc_ret_ebp,%ebp
  90. movl libc21_fpc_ret_ebx,%ebx
  91. push %edx
  92. ret
  93. end;