user_start.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* This is the canonical entry point, usually the first thing in the text
  2. segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
  3. point runs, most registers' values are unspecified, except for:
  4. %rdx Contains a function pointer to be registered with `atexit'.
  5. This is how the dynamic linker arranges to have DT_FINI
  6. functions called for shared libraries that have been loaded
  7. before this code runs.
  8. %rsp The stack contains the arguments and environment:
  9. 0(%rsp) argc
  10. LP_SIZE(%rsp) argv[0]
  11. ...
  12. (LP_SIZE*argc)(%rsp) NULL
  13. (LP_SIZE*(argc+1))(%rsp) envp[0]
  14. ...
  15. NULL
  16. */
  17. .text
  18. .globl _start
  19. .type _start,@function
  20. _start:
  21. /* Clear the frame pointer. The ABI suggests this be done, to mark
  22. the outermost frame obviously. */
  23. xorl %ebp, %ebp
  24. popq %rdi /* Pop the argument count. */
  25. /* argv starts just at the current stack top. */
  26. mov %rsp, %rsi
  27. /* Align the stack to a 16 byte boundary to follow the ABI. */
  28. and $~15, %rsp
  29. /* push the exit address on the stack */
  30. pushq %rdx
  31. /* find the environs */
  32. lea (%rsi,%rdi,8), %rdx
  33. add $8, %rdx
  34. #ifdef SHARED
  35. call main@PLT
  36. #else
  37. call main
  38. #endif
  39. /* return to the exit function */
  40. retq