gprt21.as 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 %esp,%ebx /* Points to the arguments */
  25. movl %esi,%eax
  26. incl %eax
  27. shll $2,%eax
  28. addl %esp,%eax
  29. andl $0xfffffff0,%esp /* Align stack to 16 bytes */
  30. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  31. movl %esi,operatingsystem_parameter_argc /* Move the argument counter */
  32. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  33. xorl %ebp,%ebp
  34. pushl %eax /* __libc_start_main takes 7 arguments -> push 1 extra to keep 16 byte stack alignment */
  35. pushl %esp
  36. pushl %edx
  37. pushl $_fini_dummy
  38. pushl $_init_dummy
  39. pushl %ebx
  40. pushl %esi
  41. pushl $cmain
  42. call __libc_start_main
  43. hlt
  44. /* fake main routine which will be run from libc */
  45. cmain:
  46. /* save return address */
  47. popl %eax
  48. movl %eax,___fpc_ret
  49. movl %ebx,___fpc_ret_ebx
  50. movl %esi,___fpc_ret_esi
  51. movl %edi,___fpc_ret_edi
  52. pushl %eax
  53. /* align stack to 16 bytes before call */
  54. subl $12, %esp
  55. call __gmon_start__
  56. /* restore stack */
  57. addl $12, %esp
  58. /* Save initial stackpointer */
  59. movl %esp,__stkptr
  60. /* start the program (jmp to keep stack alignment) */
  61. jmp PASCALMAIN
  62. hlt
  63. .globl _haltproc
  64. .type _haltproc,@function
  65. _haltproc:
  66. movzwl operatingsystem_result,%eax
  67. movl ___fpc_ret,%edx /* return to libc */
  68. movl ___fpc_ret_ebx,%ebx
  69. movl ___fpc_ret_esi,%esi
  70. movl ___fpc_ret_edi,%edi
  71. push %edx
  72. _init_dummy:
  73. _fini_dummy:
  74. ret
  75. .globl __gmon_start__
  76. .type __gmon_start__,@function
  77. __gmon_start__:
  78. pushl %ebp
  79. movl __monstarted,%eax
  80. leal 0x1(%eax),%edx
  81. movl %esp,%ebp
  82. movl %edx,__monstarted
  83. testl %eax,%eax
  84. jnz .Lnomonstart
  85. pushl $etext /* Initialize gmon */
  86. pushl $_start
  87. call monstartup
  88. addl $8,%esp
  89. pushl $_mcleanup
  90. call atexit
  91. addl $4,%esp
  92. .Lnomonstart:
  93. movl %ebp,%esp
  94. popl %ebp
  95. ret
  96. .data
  97. .align 4
  98. ___fpc_ret: /* return address to libc */
  99. .long 0
  100. ___fpc_ret_ebx:
  101. .long 0
  102. ___fpc_ret_esi:
  103. .long 0
  104. ___fpc_ret_edi:
  105. .long 0
  106. .bss
  107. .lcomm __monstarted,4
  108. .type __stkptr,@object
  109. .size __stkptr,4
  110. .global __stkptr
  111. __stkptr:
  112. .skip 4
  113. .type operatingsystem_parameters,@object
  114. .size operatingsystem_parameters,12
  115. operatingsystem_parameters:
  116. .skip 3*4
  117. .global operatingsystem_parameter_envp
  118. .global operatingsystem_parameter_argc
  119. .global operatingsystem_parameter_argv
  120. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  121. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  122. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  123. .section .note.GNU-stack,"",%progbits