user_start.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 $~0xF, %rsp
  29. /* push the exit address on the stack and preserve %rsp alignment */
  30. subq $8, %rsp
  31. pushq %rdx
  32. /* find the environs */
  33. lea (%rsi,%rdi,8), %rdx
  34. add $8, %rdx
  35. #ifdef SHARED
  36. call main@PLT
  37. #else
  38. call main
  39. #endif
  40. /* return to the exit function */
  41. retq