cprt21.as 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #
  2. # $Id$
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman
  5. # members of the Free Pascal development team.
  6. #
  7. # See the file COPYING.FPC, included in this distribution,
  8. # for details about the copyright.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. #**********************************************************************}
  15. #
  16. # Linux ELF startup code for Free Pascal
  17. #
  18. .file "prt1.as"
  19. .text
  20. .globl _start
  21. .type _start,@function
  22. _start:
  23. /* First locate the start of the environment variables */
  24. popl %esi
  25. movl %eax,%edi
  26. movl %esp,%ebx /* Points to the arguments */
  27. movl %esi,%eax
  28. incl %eax
  29. shll $2,%eax
  30. addl %esp,%eax
  31. andl $0xfffffff8,%esp /* Align stack */
  32. movl %eax,U_SYSTEM_ENVP /* Move the environment pointer */
  33. movl %esi,U_SYSTEM_ARGC /* Move the argument counter */
  34. movl %ebx,U_SYSTEM_ARGV /* Move the argument pointer */
  35. xorl %ebp,%ebp
  36. pushl %edi
  37. pushl %esp
  38. pushl %edx
  39. pushl $_fini_dummy
  40. pushl $_init_dummy
  41. pushl %ebx
  42. pushl %esi
  43. pushl $main
  44. call __libc_start_main
  45. hlt
  46. /* fake main routine which will be run from libc */
  47. main:
  48. /* save return address */
  49. popl %eax
  50. movl %eax,___fpc_ret
  51. movl %ebx,___fpc_ret_ebx
  52. movl %ebp,___fpc_ret_ebp
  53. pushl %eax
  54. /* start the program */
  55. xorl %ebp,%ebp
  56. call PASCALMAIN
  57. hlt
  58. .globl _haltproc
  59. .type _haltproc,@function
  60. _haltproc:
  61. xorl %eax,%eax /* load and save exitcode */
  62. movw U_SYSTEM_EXITCODE,%ax
  63. movl ___fpc_ret,%edx /* return to libc */
  64. movl ___fpc_ret_ebp,%ebp
  65. movl ___fpc_ret_ebx,%ebx
  66. push %edx
  67. _init_dummy:
  68. _fini_dummy:
  69. ret
  70. .data
  71. .align 4
  72. .globl ___fpc_brk_addr /* heap management */
  73. .type ___fpc_brk_addr,@object
  74. .size ___fpc_brk_addr,4
  75. ___fpc_brk_addr:
  76. .long 0
  77. ___fpc_ret: /* return address to libc */
  78. .long 0
  79. ___fpc_ret_ebx:
  80. .long 0
  81. ___fpc_ret_ebp:
  82. .long 0
  83. #
  84. # $Log$
  85. # Revision 1.5 2002-09-07 16:01:20 peter
  86. # * old logs removed and tabs fixed
  87. #