cprt21.as 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 %eax,%edi
  41. movl %esp,%ebx /* Points to the arguments */
  42. movl %esi,%eax
  43. incl %eax
  44. shll $2,%eax
  45. addl %esp,%eax
  46. andl $0xfffffff8,%esp /* Align stack */
  47. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  48. movl %esi,operatingsystem_parameter_argc /* Move the argument counter */
  49. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  50. xorl %ebp,%ebp
  51. pushl %edi
  52. pushl %esp
  53. pushl %edx
  54. pushl $_fini_dummy
  55. pushl $_init_dummy
  56. pushl %ebx
  57. pushl %esi
  58. pushl $main
  59. call __libc_start_main
  60. hlt
  61. /* fake main routine which will be run from libc */
  62. main:
  63. /* save return address */
  64. popl %eax
  65. movl %eax,___fpc_ret
  66. movl %ebx,___fpc_ret_ebx
  67. movl %ebp,___fpc_ret_ebp
  68. pushl %eax
  69. /* Save initial stackpointer */
  70. movl %esp,__stkptr
  71. /* start the program */
  72. xorl %ebp,%ebp
  73. call PASCALMAIN
  74. hlt
  75. .globl _haltproc
  76. .type _haltproc,@function
  77. _haltproc:
  78. movzwl operatingsystem_result,%eax
  79. movl ___fpc_ret,%edx /* return to libc */
  80. movl ___fpc_ret_ebp,%ebp
  81. movl ___fpc_ret_ebx,%ebx
  82. push %edx
  83. _init_dummy:
  84. _fini_dummy:
  85. ret
  86. .data
  87. .align 4
  88. ___fpc_ret: /* return address to libc */
  89. .long 0
  90. ___fpc_ret_ebx:
  91. .long 0
  92. ___fpc_ret_ebp:
  93. .long 0
  94. .bss
  95. .type __stkptr,@object
  96. .size __stkptr,4
  97. .global __stkptr
  98. __stkptr:
  99. .skip 4
  100. .type operatingsystem_parameters,@object
  101. .size operatingsystem_parameters,12
  102. operatingsystem_parameters:
  103. .skip 3*4
  104. .global operatingsystem_parameter_envp
  105. .global operatingsystem_parameter_argc
  106. .global operatingsystem_parameter_argv
  107. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  108. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  109. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  110. .section .note.GNU-stack,"",%progbits