dllprt0.as 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 2006 by Florian Klaempfl
  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. /* This is the canonical entry point, usually the first thing in the text
  18. segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
  19. point runs, most registers' values are unspecified, except for:
  20. %rdx Contains a function pointer to be registered with `atexit'.
  21. This is how the dynamic linker arranges to have DT_FINI
  22. functions called for shared libraries that have been loaded
  23. before this code runs.
  24. %rsp The stack contains the arguments and environment:
  25. 0(%rsp) argc
  26. 8(%rsp) argv[0]
  27. ...
  28. (8*argc)(%rsp) NULL
  29. (8*(argc+1))(%rsp) envp[0]
  30. ...
  31. NULL
  32. */
  33. .section .init
  34. .align 16
  35. .globl FPC_SHARED_LIB_START
  36. .type FPC_SHARED_LIB_START,@function
  37. FPC_SHARED_LIB_START:
  38. jmp _startlib@PLT
  39. .text
  40. .globl _start
  41. .type _start,@function
  42. _startlib:
  43. pushq %rbx
  44. movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rbx
  45. movq %rdi,(%rbx)
  46. movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rbx
  47. movq %rsi,(%rbx) /* argv starts just at the current stack top. */
  48. movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rbx
  49. movq %rdx,(%rbx)
  50. movq operatingsystem_islibrary@GOTPCREL(%rip),%rbx
  51. movb $1,(%rbx)
  52. /* Save initial stackpointer */
  53. movq __stkptr@GOTPCREL(%rip),%rbx
  54. movq %rsp,(%rbx)
  55. call PASCALMAIN@PLT
  56. popq %rbx
  57. ret
  58. /* this routine is only called when the halt() routine of the RTL embedded in
  59. the shared library is called */
  60. .globl _haltproc
  61. .type _haltproc,@function
  62. _haltproc:
  63. .globl FPC_SHARED_LIB_EXIT
  64. .type FPC_SHARED_LIB_EXIT,@function
  65. FPC_SHARED_LIB_EXIT:
  66. movl $231,%eax /* exit_group call */
  67. movq operatingsystem_result@GOTPCREL(%rip),%rbx
  68. movzwl (%rbx),%edi
  69. syscall
  70. jmp _haltproc@PLT
  71. /* Define a symbol for the first piece of initialized data. */
  72. .data
  73. .globl __data_start
  74. __data_start:
  75. .long 0
  76. .weak data_start
  77. data_start = __data_start
  78. .bss
  79. .comm __stkptr,8
  80. .comm operatingsystem_parameter_envp,8
  81. .comm operatingsystem_parameter_argc,8
  82. .comm operatingsystem_parameter_argv,8
  83. /* We need this stuff to make gdb behave itself, otherwise
  84. gdb will chokes with SIGILL when trying to debug apps.
  85. Makes ld choke:
  86. .section ".note.ABI-tag", "a"
  87. .align 4
  88. .long 1f - 0f
  89. .long 3f - 2f
  90. .long 1
  91. 0: .asciz "GNU"
  92. 1: .align 4
  93. 2: .long 0
  94. .long 2,4,0
  95. 3: .align 4
  96. */
  97. .section .note.GNU-stack,"",@progbits