user_start.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. popq %rdi /* Pop the argument count. */
  22. /* argv starts just at the current stack top. */
  23. mov %rsp, %rsi
  24. /* Align the stack to a 16 byte boundary to follow the ABI. */
  25. and $~0xF, %rsp
  26. /* push the exit address on the stack and preserve %rsp alignment */
  27. pushq %rdx
  28. /* Clear the frame pointer. The ABI suggests this be done, to mark
  29. the outermost frame obviously. */
  30. pushq %rbp /* %rbp is callee save. */
  31. xorl %ebp, %ebp
  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. popq %rbp
  42. retq