prt0.as 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #
  2. # This file is part of the Free Pascal run time library.
  3. # Copyright (c) 2002 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 document "System V Application Binary Interface AMD64
  19. Architecture Processor Supplement Version 0.99.5" pg. 30 defines that
  20. the entry point runs, most registers' values are unspecified, except
  21. for:
  22. %rdx Contains a function pointer to be registered with `atexit'.
  23. This is how the dynamic linker arranges to have DT_FINI
  24. functions called for shared libraries that have been loaded
  25. before this code runs.
  26. %rsp The stack contains the arguments and environment:
  27. 0(%rsp) argc
  28. 8(%rsp) argv[0]
  29. ...
  30. (8*argc)(%rsp) NULL
  31. (8*(argc+1))(%rsp) envp[0]
  32. ...
  33. NULL
  34. */
  35. .text
  36. .globl _dynamic_start
  37. .type _dynamic_start,@function
  38. _dynamic_start:
  39. movq __dl_fini@GOTPCREL(%rip),%rax
  40. movq %rdx,(%rax)
  41. jmp _start
  42. .text
  43. .globl _start
  44. .type _start,@function
  45. _start:
  46. popq %rsi /* Pop the argument count. */
  47. movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
  48. movq %rsi,(%rax)
  49. movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
  50. movq %rsp,(%rax) /* argv starts just at the current stack top. */
  51. leaq 8(,%rsi,8),%rax
  52. addq %rsp,%rax
  53. movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rcx
  54. movq %rax,(%rcx)
  55. andq $~15,%rsp /* Align the stack to a 16 byte boundary to follow the ABI. */
  56. /* Save initial stackpointer */
  57. movq __stkptr@GOTPCREL(%rip),%rax
  58. movq %rsp,(%rax)
  59. xorq %rbp, %rbp
  60. call PASCALMAIN
  61. jmp _haltproc
  62. .globl _haltproc
  63. .type _haltproc,@function
  64. _haltproc:
  65. movq __dl_fini@GOTPCREL(%rip),%rax
  66. movq (%rax),%rax
  67. testq %rax,%rax
  68. jz .LNoDlFiniCall
  69. call *%rax
  70. .LNoDlFiniCall:
  71. movq operatingsystem_result@GOTPCREL(%rip),%rax
  72. movzwl (%rax),%edi
  73. movl $231,%eax /* exit_group call */
  74. syscall
  75. jmp _haltproc
  76. /* Define a symbol for the first piece of initialized data. */
  77. .data
  78. .globl __data_start
  79. __data_start:
  80. .long 0
  81. .weak data_start
  82. data_start = __data_start
  83. .bss
  84. .comm __stkptr,8
  85. .comm __dl_fini,8
  86. .comm operatingsystem_parameter_envp,8
  87. .comm operatingsystem_parameter_argc,8
  88. .comm operatingsystem_parameter_argv,8
  89. /* We need this stuff to make gdb behave itself, otherwise
  90. gdb will chokes with SIGILL when trying to debug apps.
  91. */
  92. .section ".note.ABI-tag", "a"
  93. .align 4
  94. .long 1f - 0f
  95. .long 3f - 2f
  96. .long 1
  97. 0: .asciz "GNU"
  98. 1: .align 4
  99. 2: .long 0
  100. .long 2,4,0
  101. 3: .align 4
  102. .section .note.GNU-stack,"",@progbits