cprt21.as 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. # Stack layout at program start:
  18. #
  19. # nil
  20. # envn
  21. # ....
  22. # .... ENVIRONMENT VARIABLES
  23. # env1
  24. # env0
  25. # nil
  26. # argn
  27. # ....
  28. # .... COMMAND LINE OPTIONS
  29. # arg1
  30. # arg0
  31. # argc <--- esp
  32. #
  33. .file "prt1.as"
  34. .text
  35. .globl _start
  36. .type _start,@function
  37. _start:
  38. /* First locate the start of the environment variables */
  39. popl %esi
  40. movl %esp,%ebx /* Points to the arguments */
  41. movl %esi,%eax
  42. incl %eax
  43. shll $2,%eax
  44. addl %esp,%eax
  45. andl $0xfffffff0,%esp /* Align stack to 16 bytes */
  46. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  47. movl %esi,operatingsystem_parameter_argc /* Move the argument counter */
  48. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  49. xorl %ebp,%ebp
  50. pushl %edi /* __libc_start_main takes 7 arguments -> push 1 extra to keep 16 byte stack alignment */
  51. pushl %esp
  52. pushl %edx
  53. pushl $_fini_dummy
  54. pushl $_init_dummy
  55. pushl %ebx
  56. pushl %esi
  57. pushl $main
  58. call __libc_start_main
  59. hlt
  60. /* fake main routine which will be run from libc */
  61. main:
  62. /* save return address */
  63. popl %eax
  64. movl %eax,___fpc_ret
  65. movl %ebx,___fpc_ret_ebx
  66. movl %ebp,___fpc_ret_ebp
  67. pushl %eax
  68. /* Save initial stackpointer */
  69. movl %esp,__stkptr
  70. /* start the program */
  71. xorl %ebp,%ebp
  72. /* jmp to keep stack alignment */
  73. jmp PASCALMAIN
  74. .globl _haltproc
  75. .type _haltproc,@function
  76. _haltproc:
  77. movzwl operatingsystem_result,%eax
  78. movl ___fpc_ret,%edx /* return to libc */
  79. movl ___fpc_ret_ebp,%ebp
  80. movl ___fpc_ret_ebx,%ebx
  81. push %edx
  82. _init_dummy:
  83. _fini_dummy:
  84. ret
  85. .data
  86. .align 4
  87. ___fpc_ret: /* return address to libc */
  88. .long 0
  89. ___fpc_ret_ebx:
  90. .long 0
  91. ___fpc_ret_ebp:
  92. .long 0
  93. .bss
  94. .type __stkptr,@object
  95. .size __stkptr,4
  96. .global __stkptr
  97. __stkptr:
  98. .skip 4
  99. .type operatingsystem_parameters,@object
  100. .size operatingsystem_parameters,12
  101. operatingsystem_parameters:
  102. .skip 3*4
  103. .global operatingsystem_parameter_envp
  104. .global operatingsystem_parameter_argc
  105. .global operatingsystem_parameter_argv
  106. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  107. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  108. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  109. .section .note.GNU-stack,"",%progbits