gprt0.as 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 with profiling support for Free Pascal
  16. # Note: Needs linking with -lgmon and -lc
  17. #
  18. .file "gprt1.as"
  19. .text
  20. .globl _start
  21. .type _start,@function
  22. _start:
  23. /* First locate the start of the environment variables */
  24. popl %ecx
  25. movl %esp,%ebx /* Points to the arguments */
  26. movl %ecx,%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 %ecx,operatingsystem_parameter_argc /* Move the argument counter */
  33. movl %ebx,operatingsystem_parameter_argv /* Move the argument pointer */
  34. finit /* initialize fpu */
  35. fwait
  36. fldcw ___fpucw
  37. pushl $_etext /* Initialize gmon */
  38. pushl $_start
  39. call monstartup
  40. addl $8,%esp
  41. pushl $_mcleanup
  42. call atexit
  43. addl $4,%esp
  44. /* Save initial stackpointer */
  45. movl %esp,__stkptr
  46. xorl %ebp,%ebp
  47. call PASCALMAIN
  48. .globl _haltproc
  49. .type _haltproc,@function
  50. _haltproc:
  51. _haltproc2: # GAS <= 2.15 bug: generates larger jump if a label is exported
  52. movzwl operatingsystem_result,%ebx
  53. pushl %ebx
  54. call exit /* call libc exit, this will */
  55. /* write the gmon.out */
  56. movl $252,%eax /* exit_group */
  57. popl %ebx
  58. int $0x80
  59. jmp _haltproc2
  60. .data
  61. ___fpucw:
  62. .long 0x1332
  63. .bss
  64. .type __stkptr,@object
  65. .size __stkptr,4
  66. .global __stkptr
  67. __stkptr:
  68. .skip 4
  69. .type operatingsystem_parameters,@object
  70. .size operatingsystem_parameters,12
  71. operatingsystem_parameters:
  72. .skip 3*4
  73. .global operatingsystem_parameter_envp
  74. .global operatingsystem_parameter_argc
  75. .global operatingsystem_parameter_argv
  76. .set operatingsystem_parameter_envp,operatingsystem_parameters+0
  77. .set operatingsystem_parameter_argc,operatingsystem_parameters+4
  78. .set operatingsystem_parameter_argv,operatingsystem_parameters+8
  79. .section .note.GNU-stack,"",%progbits