gprt0.as 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. $Id$
  3. Dummy implementation
  4. */
  5. /* This is the canonical entry point, usually the first thing in the text
  6. segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
  7. point runs, most registers' values are unspecified, except for:
  8. %rdx Contains a function pointer to be registered with `atexit'.
  9. This is how the dynamic linker arranges to have DT_FINI
  10. functions called for shared libraries that have been loaded
  11. before this code runs.
  12. %rsp The stack contains the arguments and environment:
  13. 0(%rsp) argc
  14. 8(%rsp) argv[0]
  15. ...
  16. (8*argc)(%rsp) NULL
  17. (8*(argc+1))(%rsp) envp[0]
  18. ...
  19. NULL
  20. */
  21. .text
  22. .globl _start
  23. .type _start,@function
  24. _start:
  25. /* Clear the frame pointer. The ABI suggests this be done, to mark
  26. the outermost frame obviously. */
  27. xorq %rbp, %rbp
  28. /* Extract the arguments as encoded on the stack and set up
  29. the arguments for __libc_start_main (int (*main) (int, char **, char **),
  30. int argc, char *argv,
  31. void (*init) (void), void (*fini) (void),
  32. void (*rtld_fini) (void), void *stack_end).
  33. The arguments are passed via registers and on the stack:
  34. main: %rdi
  35. argc: %rsi
  36. argv: %rdx
  37. init: %rcx
  38. fini: %r8
  39. rtld_fini: %r9
  40. stack_end: stack. */
  41. movq %rdx, %r9 /* Address of the shared library termination
  42. function. */
  43. popq %rsi /* Pop the argument count. */
  44. movq %rsp, %rdx /* argv starts just at the current stack top. */
  45. movq %rsi,operatingsystem_parameter_argc
  46. movq %rsp,operatingsystem_parameter_argv /* argv starts just at the current stack top. */
  47. leaq 8(,%rsi,8),%rax
  48. addq %rsp,%rax
  49. movq %rax,operatingsystem_parameter_envp
  50. /* Align the stack to a 16 byte boundary to follow the ABI. */
  51. andq $~15, %rsp
  52. pushq %rax /* Push garbage because we push 8 more bytes. */
  53. /* Provide the highest stack address to the user code (for stacks
  54. which grow downwards). */
  55. pushq %rsp
  56. /* Pass address of our own entry points to .fini and .init. */
  57. movq $_init_dummy, %r8
  58. movq $_fini_dummy, %rcx
  59. movq $main_stub, %rdi
  60. /* Call the user's main function, and exit with its value.
  61. But let the libc call main. */
  62. call __libc_start_main
  63. hlt /* Crash if somehow `exit' does return. */
  64. /* fake main routine which will be run from libc */
  65. main_stub:
  66. /* save return address */
  67. popq %rax
  68. // stack alignment
  69. pushq %rax
  70. movq %rax,___fpc_ret
  71. movq %rbp,___fpc_ret_rbp
  72. pushq %rax
  73. /* Initialize gmon */
  74. movq $_etext,%rsi
  75. movq $_start,%rdi
  76. call monstartup
  77. movq $_mcleanup,%rdi
  78. call atexit
  79. /* start the program */
  80. xorq %rbp,%rbp
  81. call PASCALMAIN
  82. hlt
  83. .globl _haltproc
  84. .type _haltproc,@function
  85. _haltproc:
  86. movzwq operatingsystem_result,%rax /* load and save exitcode */
  87. movq ___fpc_ret,%rdx /* return to libc */
  88. movq ___fpc_ret_rbp,%rbp
  89. pushq %rdx
  90. _init_dummy:
  91. _fini_dummy:
  92. ret
  93. /* Define a symbol for the first piece of initialized data. */
  94. .data
  95. .globl __data_start
  96. __data_start:
  97. .long 0
  98. .weak data_start
  99. data_start = __data_start
  100. .globl ___fpc_brk_addr /* heap management */
  101. .type ___fpc_brk_addr,@object
  102. .size ___fpc_brk_addr,8
  103. ___fpc_brk_addr:
  104. .quad 0
  105. ___fpc_ret: /* return address to libc */
  106. .quad 0
  107. ___fpc_ret_rbp:
  108. .quad 0
  109. .bss
  110. .comm operatingsystem_parameter_envp,8
  111. .comm operatingsystem_parameter_argc,8
  112. .comm operatingsystem_parameter_argv,8
  113. /* We need this stuff to make gdb behave itself, otherwise
  114. gdb will chokes with SIGILL when trying to debug apps.
  115. */
  116. .section ".note.ABI-tag", "a"
  117. .align 4
  118. .long 1f - 0f
  119. .long 3f - 2f
  120. .long 1
  121. 0: .asciz "GNU"
  122. 1: .align 4
  123. 2: .long 0
  124. .long 2,4,0
  125. 3: .align 4
  126. .section .note.GNU-stack,"",@progbits
  127. /*
  128. $Log$
  129. Revision 1.3 2004-11-02 21:49:46 florian
  130. * x86_64 requires always 16 byte alignment of the stack
  131. Revision 1.2 2004/11/02 20:41:57 florian
  132. * initial implementation
  133. Revision 1.1 2003/01/06 19:39:17 florian
  134. + dummy implementations
  135. */