prt0.as 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #
  2. # $Id$
  3. # This file is part of the Free Pascal run time library.
  4. # Copyright (c) 2002 by Florian Klaempfl
  5. # members of the Free Pascal development team.
  6. #
  7. # See the file COPYING.FPC, included in this distribution,
  8. # for details about the copyright.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY;without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. #**********************************************************************}
  15. #
  16. # Linux ELF startup code for Free Pascal
  17. #
  18. /* This is the canonical entry point, usually the first thing in the text
  19. segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
  20. point runs, most registers' values are unspecified, except for:
  21. %rdx Contains a function pointer to be registered with `atexit'.
  22. This is how the dynamic linker arranges to have DT_FINI
  23. functions called for shared libraries that have been loaded
  24. before this code runs.
  25. %rsp The stack contains the arguments and environment:
  26. 0(%rsp) argc
  27. 8(%rsp) argv[0]
  28. ...
  29. (8*argc)(%rsp) NULL
  30. (8*(argc+1))(%rsp) envp[0]
  31. ...
  32. NULL
  33. */
  34. .text
  35. .globl _start
  36. .type _start,@function
  37. _start:
  38. # movq %rdx,%r9 /* Address of the shared library termination
  39. # function. */
  40. popq %rsi /* Pop the argument count. */
  41. movq %rsi,operatingsystem_parameter_argc
  42. movq %rsp,operatingsystem_parameter_argv /* argv starts just at the current stack top. */
  43. leaq 8(,%rsi,8),%rax
  44. addq %rsp,%rax
  45. movq %rax,operatingsystem_parameter_envp
  46. andq $~15,%rsp /* Align the stack to a 16 byte boundary to follow the ABI. */
  47. /* !!!! CPU initialization? */
  48. xorq %rbp, %rbp
  49. call PASCALMAIN
  50. jmp _haltproc
  51. .globl _haltproc
  52. .type _haltproc,@function
  53. _haltproc:
  54. movl $60,%eax /* exit 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 operatingsystem_parameter_envp,8
  67. .comm operatingsystem_parameter_argc,8
  68. .comm operatingsystem_parameter_argv,8
  69. /* We need this stuff to make gdb behave itself, otherwise
  70. gdb will chokes with SIGILL when trying to debug apps.
  71. */
  72. .section ".note.ABI-tag", "a"
  73. .align 4
  74. .long 1f - 0f
  75. .long 3f - 2f
  76. .long 1
  77. 0: .asciz "GNU"
  78. 1: .align 4
  79. 2: .long 0
  80. .long 2,4,0
  81. 3: .align 4
  82. .section .note.GNU-stack,"",@progbits
  83. #
  84. # $Log$
  85. # Revision 1.8 2004-07-03 21:50:31 daniel
  86. # * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  87. # longer necessary
  88. #
  89. # Revision 1.7 2004/04/24 17:14:09 florian
  90. # * prt0.as exit code handling fixed
  91. # * int64 mod int64 for negative numbers fixed
  92. #
  93. # Revision 1.6 2004/04/20 20:30:11 florian
  94. # * fixed halt code
  95. #
  96. # Revision 1.5 2004/04/12 19:05:55 florian
  97. # + haltproc added
  98. #
  99. # Revision 1.4 2004/02/20 23:48:27 peter
  100. # * c stub implemented
  101. #
  102. # Revision 1.3 2004/02/08 15:33:50 florian
  103. # * linking problems fixed
  104. # + abi tag added
  105. #
  106. # Revision 1.2 2004/02/02 21:02:38 peter
  107. # * fixed syntax errors
  108. #
  109. # Revision 1.1 2003/01/06 19:33:10 florian
  110. # + initial revision
  111. #
  112. #