prt0.as 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 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. .text
  34. .globl _start
  35. .type _start,@function
  36. _start:
  37. # movq %rdx,%r9 /* Address of the shared library termination
  38. # function. */
  39. popq %rsi /* Pop the argument count. */
  40. movq operatingsystem_parameter_argc@GOTPCREL(%rip),%rax
  41. movq %rsi,(%rax)
  42. movq operatingsystem_parameter_argv@GOTPCREL(%rip),%rax
  43. movq %rsp,(%rax) /* argv starts just at the current stack top. */
  44. leaq 8(,%rsi,8),%rax
  45. addq %rsp,%rax
  46. movq operatingsystem_parameter_envp@GOTPCREL(%rip),%rcx
  47. movq %rax,(%rcx)
  48. andq $~15,%rsp /* Align the stack to a 16 byte boundary to follow the ABI. */
  49. /* Save initial stackpointer */
  50. movq __stkptr@GOTPCREL(%rip),%rax
  51. movq %rsp,(%rax)
  52. xorq %rbp, %rbp
  53. call PASCALMAIN
  54. jmp _haltproc
  55. .globl _haltproc
  56. .type _haltproc,@function
  57. _haltproc:
  58. movq operatingsystem_result@GOTPCREL(%rip),%rax
  59. movzwl (%rax),%edi
  60. movl $231,%eax /* exit_group call */
  61. syscall
  62. jmp _haltproc
  63. /* Define a symbol for the first piece of initialized data. */
  64. .data
  65. .globl __data_start
  66. __data_start:
  67. .long 0
  68. .weak data_start
  69. data_start = __data_start
  70. .bss
  71. .comm __stkptr,8
  72. .comm operatingsystem_parameter_envp,8
  73. .comm operatingsystem_parameter_argc,8
  74. .comm operatingsystem_parameter_argv,8
  75. /* We need this stuff to make gdb behave itself, otherwise
  76. gdb will chokes with SIGILL when trying to debug apps.
  77. */
  78. .section ".note.ABI-tag", "a"
  79. .align 4
  80. .long 1f - 0f
  81. .long 3f - 2f
  82. .long 1
  83. 0: .asciz "GNU"
  84. 1: .align 4
  85. 2: .long 0
  86. .long 2,4,0
  87. 3: .align 4
  88. .section .note.GNU-stack,"",@progbits