prt0.as 2.8 KB

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