gprt21.as 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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,operatingsystem_parameter_envp /* Move the environment pointer */
  33. movl %esi,operatingsystem_parameter_argc /* Move the argument counter */
  34. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  35. movl %edi,%eax
  36. xorl %ebp,%ebp
  37. pushl %eax
  38. pushl %esp
  39. pushl %edx
  40. pushl $_fini_dummy
  41. pushl $_init_dummy
  42. pushl %ebx
  43. pushl %esi
  44. pushl $cmain
  45. call __libc_start_main
  46. hlt
  47. /* fake main routine which will be run from libc */
  48. cmain:
  49. /* save return address */
  50. popl %eax
  51. movl %eax,___fpc_ret
  52. movl %ebx,___fpc_ret_ebx
  53. movl %esi,___fpc_ret_esi
  54. movl %edi,___fpc_ret_edi
  55. pushl %eax
  56. call __gmon_start__
  57. /* start the program */
  58. call PASCALMAIN
  59. hlt
  60. .globl _haltproc
  61. .type _haltproc,@function
  62. _haltproc:
  63. movzwl operatingsystem_result,%eax
  64. movl ___fpc_ret,%edx /* return to libc */
  65. movl ___fpc_ret_ebx,%ebx
  66. movl ___fpc_ret_esi,%esi
  67. movl ___fpc_ret_edi,%edi
  68. push %edx
  69. _init_dummy:
  70. _fini_dummy:
  71. ret
  72. .globl __gmon_start__
  73. .type __gmon_start__,@function
  74. __gmon_start__:
  75. pushl %ebp
  76. movl __monstarted,%eax
  77. leal 0x1(%eax),%edx
  78. movl %esp,%ebp
  79. movl %edx,__monstarted
  80. testl %eax,%eax
  81. jnz .Lnomonstart
  82. pushl $etext /* Initialize gmon */
  83. pushl $_start
  84. call monstartup
  85. addl $8,%esp
  86. pushl $_mcleanup
  87. call atexit
  88. addl $4,%esp
  89. .Lnomonstart:
  90. movl %ebp,%esp
  91. popl %ebp
  92. ret
  93. .data
  94. .align 4
  95. ___fpc_ret: /* return address to libc */
  96. .long 0
  97. ___fpc_ret_ebx:
  98. .long 0
  99. ___fpc_ret_esi:
  100. .long 0
  101. ___fpc_ret_edi:
  102. .long 0
  103. .bss
  104. .lcomm __monstarted,4
  105. .type ___fpc_brk_addr,@object
  106. .comm ___fpc_brk_addr,4 /* heap management */
  107. .comm operatingsystem_parameter_envp,4
  108. .comm operatingsystem_parameter_argc,4
  109. .comm operatingsystem_parameter_argv,4
  110. #
  111. # $Log$
  112. # Revision 1.6 2004-07-03 21:50:31 daniel
  113. # * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  114. # longer necessary
  115. #
  116. # Revision 1.5 2004/03/10 20:38:59 peter
  117. # * only i386 needs cprt21 to link with glibc 2.1+
  118. #
  119. # Revision 1.4 2002/09/07 16:01:20 peter
  120. # * old logs removed and tabs fixed
  121. #