si_c21.inc 2.9 KB

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