gprt21.as 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman
  4. # members of the Free Pascal development team.
  5. #
  6. # See the file COPYING.FPC, included in this distribution,
  7. # for details about the copyright.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. #**********************************************************************}
  14. #
  15. # Linux ELF startup code for Free Pascal
  16. #
  17. .file "prt1.as"
  18. .text
  19. .globl _start
  20. .type _start,@function
  21. _start:
  22. /* First locate the start of the environment variables */
  23. popl %esi
  24. movl %eax,%edi
  25. movl %esp,%ebx /* Points to the arguments */
  26. movl %esi,%eax
  27. incl %eax
  28. shll $2,%eax
  29. addl %esp,%eax
  30. andl $0xfffffff8,%esp /* Align stack */
  31. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  32. movl %esi,operatingsystem_parameter_argc /* Move the argument counter */
  33. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  34. movl %edi,%eax
  35. xorl %ebp,%ebp
  36. pushl %eax
  37. pushl %esp
  38. pushl %edx
  39. pushl $_fini_dummy
  40. pushl $_init_dummy
  41. pushl %ebx
  42. pushl %esi
  43. pushl $cmain
  44. call __libc_start_main
  45. hlt
  46. /* fake main routine which will be run from libc */
  47. cmain:
  48. /* save return address */
  49. popl %eax
  50. movl %eax,___fpc_ret
  51. movl %ebx,___fpc_ret_ebx
  52. movl %esi,___fpc_ret_esi
  53. movl %edi,___fpc_ret_edi
  54. pushl %eax
  55. call __gmon_start__
  56. /* Save initial stackpointer */
  57. movl %esp,__stkptr
  58. /* start the program */
  59. call PASCALMAIN
  60. hlt
  61. .globl _haltproc
  62. .type _haltproc,@function
  63. _haltproc:
  64. movzwl operatingsystem_result,%eax
  65. movl ___fpc_ret,%edx /* return to libc */
  66. movl ___fpc_ret_ebx,%ebx
  67. movl ___fpc_ret_esi,%esi
  68. movl ___fpc_ret_edi,%edi
  69. push %edx
  70. _init_dummy:
  71. _fini_dummy:
  72. ret
  73. .globl __gmon_start__
  74. .type __gmon_start__,@function
  75. __gmon_start__:
  76. pushl %ebp
  77. movl __monstarted,%eax
  78. leal 0x1(%eax),%edx
  79. movl %esp,%ebp
  80. movl %edx,__monstarted
  81. testl %eax,%eax
  82. jnz .Lnomonstart
  83. pushl $etext /* Initialize gmon */
  84. pushl $_start
  85. call monstartup
  86. addl $8,%esp
  87. pushl $_mcleanup
  88. call atexit
  89. addl $4,%esp
  90. .Lnomonstart:
  91. movl %ebp,%esp
  92. popl %ebp
  93. ret
  94. .data
  95. .align 4
  96. ___fpc_ret: /* return address to libc */
  97. .long 0
  98. ___fpc_ret_ebx:
  99. .long 0
  100. ___fpc_ret_esi:
  101. .long 0
  102. ___fpc_ret_edi:
  103. .long 0
  104. .bss
  105. .lcomm __monstarted,4
  106. .type __stkptr,@object
  107. .size __stkptr,4
  108. .global __stkptr
  109. __stkptr:
  110. .skip 4
  111. .type operatingsystem_parameters,@object
  112. .size operatingsystem_parameters,12
  113. operatingsystem_parameters:
  114. .skip 3*4
  115. .global operatingsystem_parameter_envp
  116. .global operatingsystem_parameter_argc
  117. .global operatingsystem_parameter_argv
  118. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  119. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  120. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  121. .section .note.GNU-stack,"",%progbits