crt0.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* When we enter this piece of code, the program stack looks like this:
  2. argc argument counter (integer)
  3. argv[0] program name (pointer)
  4. argv[1...N] program args (pointers)
  5. argv[argc-1] end of args (integer)
  6. NULL
  7. env[0...N] environment variables (pointers)
  8. NULL
  9. When we are done here, we want
  10. a1=argc
  11. a2=argv[0]
  12. a3=argv[argc+1]
  13. ARM register quick reference:
  14. Name Number ARM Procedure Calling Standard Role
  15. a1 r0 argument 1 / integer result / scratch register / argc
  16. a2 r1 argument 2 / scratch register / argv
  17. a3 r2 argument 3 / scratch register / envp
  18. a4 r3 argument 4 / scratch register
  19. v1 r4 register variable
  20. v2 r5 register variable
  21. v3 r6 register variable
  22. v4 r7 register variable
  23. v5 r8 register variable
  24. sb/v6 r9 static base / register variable
  25. sl/v7 r10 stack limit / stack chunk handle / reg. variable
  26. fp r11 frame pointer
  27. ip r12 scratch register / new-sb in inter-link-unit calls
  28. sp r13 lower end of current stack frame
  29. lr r14 link address / scratch register
  30. pc r15 program counter
  31. */
  32. .text
  33. .global _start
  34. .global __uClibc_main
  35. .type _start,%function
  36. .type __uClibc_main,%function
  37. .text
  38. _start:
  39. /* clear the frame pointer */
  40. mov fp, #0
  41. /* Load register r0 (argc) from the stack to its final resting place */
  42. ldr r0, [sp], #4
  43. /* Copy argv pointer into r1 -- which its final resting place */
  44. mov r1, sp
  45. /* Skip to the end of argv and put a pointer to whatever
  46. we find there (hopefully the environment) in r2 */
  47. add r2, r1, r0, lsl #2
  48. add r2, r2, #4
  49. /* Ok, now run uClibc's main() -- shouldn't return */
  50. bl __uClibc_main
  51. #if 0 /* this is already provided by crtbegin/crtend in the arm-elf compiler */
  52. /* a little bit of stuff to support C++ */
  53. .section .ctors,"aw"
  54. .align 4
  55. .global __CTOR_LIST__
  56. __CTOR_LIST__:
  57. .long -1
  58. .section .dtors,"aw"
  59. .align 4
  60. .global __DTOR_LIST__
  61. __DTOR_LIST__:
  62. .long -1
  63. #endif