cprt0.as 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #
  18. # Stack layout at program start:
  19. #
  20. # nil
  21. # envn
  22. # ....
  23. # .... ENVIRONMENT VARIABLES
  24. # env1
  25. # env0
  26. # nil
  27. # argn
  28. # ....
  29. # .... COMMAND LINE OPTIONS
  30. # arg1
  31. # arg0
  32. # argc <--- esp
  33. #
  34. .file "cprt0.as"
  35. .text
  36. .globl _start
  37. .type _start,@function
  38. _start:
  39. /* First locate the start of the environment variables */
  40. popl %ecx /* Get argc in ecx */
  41. movl %esp,%ebx /* Esp now points to the arguments */
  42. leal 4(%esp,%ecx,4),%eax /* The start of the environment is: esp+4*eax+8 */
  43. andl $0xfffffff8,%esp /* Align stack */
  44. movl %eax,operatingsystem_parameter_envp /* Move the environment pointer */
  45. movl %ecx,operatingsystem_parameter_argc /* Move the argument counter */
  46. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  47. movl %eax,__environ /* libc environ */
  48. pushl %eax
  49. pushl %ebx
  50. pushl %ecx
  51. call __libc_init /* init libc */
  52. movzwl __fpu_control,%eax
  53. pushl %eax
  54. call __setfpucw
  55. popl %eax
  56. pushl $_fini
  57. call atexit
  58. popl %eax
  59. call _init
  60. popl %eax
  61. popl %eax
  62. /* Save initial stackpointer */
  63. movl %esp,__stkptr
  64. xorl %ebp,%ebp
  65. call PASCALMAIN /* start the program */
  66. .globl _haltproc
  67. .type _haltproc,@function
  68. _haltproc:
  69. _haltproc2: # GAS <= 2.15 bug: generates larger jump if a label is exported
  70. movzwl operatingsystem_result,%ebx
  71. pushl %ebx
  72. call exit
  73. xorl %eax,%eax
  74. incl %eax /* eax=1, exit call */
  75. popl %ebx
  76. int $0x80
  77. jmp _haltproc2
  78. .data
  79. .bss
  80. .type __stkptr,@object
  81. .size __stkptr,4
  82. .global __stkptr
  83. __stkptr:
  84. .skip 4
  85. .type operatingsystem_parameters,@object
  86. .size operatingsystem_parameters,12
  87. operatingsystem_parameters:
  88. .skip 3*4
  89. .global operatingsystem_parameter_envp
  90. .global operatingsystem_parameter_argc
  91. .global operatingsystem_parameter_argv
  92. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  93. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  94. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  95. .section .note.GNU-stack,"",%progbits