dllprt0.as 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # movq %rdx,%r9 /* Address of the shared library termination
  44. # function. */
  45. pushq %rbx
  46. movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rbx
  47. movq %rdi,(%rbx)
  48. movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rbx
  49. movq %rsi,(%rbx) /* argv starts just at the current stack top. */
  50. movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rbx
  51. movq %rdx,(%rbx)
  52. movq TC_SYSTEM_ISLIBRARY@GOTPCREL(%rip),%rbx
  53. movb $1,(%rbx)
  54. /* Save initial stackpointer */
  55. movq __stkptr@GOTPCREL(%rip),%rbx
  56. movq %rsp,(%rbx)
  57. call PASCALMAIN@PLT
  58. popq %rbx
  59. ret
  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. call FPC_LIB_EXIT@PLT
  67. movl $231,%eax /* exit_group call */
  68. movq operatingsystem_result@GOTPCREL(%rip),%rbx
  69. movzwl (%rbx),%edi
  70. syscall
  71. jmp _haltproc@PLT
  72. /* Define a symbol for the first piece of initialized data. */
  73. .data
  74. .globl __data_start
  75. __data_start:
  76. .long 0
  77. .weak data_start
  78. data_start = __data_start
  79. .bss
  80. .comm __stkptr,8
  81. .comm operatingsystem_parameter_envp,8
  82. .comm operatingsystem_parameter_argc,8
  83. .comm operatingsystem_parameter_argv,8
  84. /* We need this stuff to make gdb behave itself, otherwise
  85. gdb will chokes with SIGILL when trying to debug apps.
  86. Makes ld choke:
  87. .section ".note.ABI-tag", "a"
  88. .align 4
  89. .long 1f - 0f
  90. .long 3f - 2f
  91. .long 1
  92. 0: .asciz "GNU"
  93. 1: .align 4
  94. 2: .long 0
  95. .long 2,4,0
  96. 3: .align 4
  97. */
  98. .section .note.GNU-stack,"",@progbits