crt0.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. For uClinux it looks like this:
  10. argc argument counter (integer)
  11. argv char *argv[]
  12. envp char *envp[]
  13. argv[0] program name (pointer)
  14. argv[1...N] program args (pointers)
  15. argv[argc-1] end of args (integer)
  16. NULL
  17. env[0...N] environment variables (pointers)
  18. NULL
  19. When we are done here, we want
  20. a1=argc
  21. a2=argv[0]
  22. a3=argv[argc+1]
  23. ARM register quick reference:
  24. Name Number ARM Procedure Calling Standard Role
  25. a1 r0 argument 1 / integer result / scratch register / argc
  26. a2 r1 argument 2 / scratch register / argv
  27. a3 r2 argument 3 / scratch register / envp
  28. a4 r3 argument 4 / scratch register
  29. v1 r4 register variable
  30. v2 r5 register variable
  31. v3 r6 register variable
  32. v4 r7 register variable
  33. v5 r8 register variable
  34. sb/v6 r9 static base / register variable
  35. sl/v7 r10 stack limit / stack chunk handle / reg. variable
  36. fp r11 frame pointer
  37. ip r12 scratch register / new-sb in inter-link-unit calls
  38. sp r13 lower end of current stack frame
  39. lr r14 link address / scratch register
  40. pc r15 program counter
  41. */
  42. #include <features.h>
  43. .text
  44. .global _start
  45. .global __uClibc_main
  46. .type _start,%function
  47. .type __uClibc_main,%function
  48. .text
  49. _start:
  50. #if 0 /* some old code the I feel should not be here - davidm */
  51. @ adjust the data segment base pointer
  52. ldr r3,=__data_start
  53. sub sl,sl,r3
  54. mov BASEREG,sl
  55. #endif
  56. /* clear the frame pointer */
  57. mov fp, #0
  58. #ifdef __UCLIBC_HAS_MMU__
  59. /* Load register r0 (argc) from the stack to its final resting place */
  60. ldr r0, [sp], #4
  61. /* Copy argv pointer into r1 -- which its final resting place */
  62. mov r1, sp
  63. /* Skip to the end of argv and put a pointer to whatever
  64. we find there (hopefully the environment) in r2 */
  65. add r2, r1, r0, lsl #2
  66. add r2, r2, #4
  67. #else
  68. /*
  69. * uClinux stacks look a little different to MMU stacks
  70. * for no good reason
  71. */
  72. /* pull argc, argv and envp off the stack */
  73. ldr r0,[sp, #0]
  74. ldr r1,[sp, #4]
  75. ldr r2,[sp, #8]
  76. #endif
  77. /* Ok, now run uClibc's main() -- shouldn't return */
  78. bl __uClibc_main
  79. #if 0 /* this is already provided by crtbegin/crtend in the arm-elf compiler */
  80. /* a little bit of stuff to support C++ */
  81. .section .ctors,"aw"
  82. .align 4
  83. .global __CTOR_LIST__
  84. __CTOR_LIST__:
  85. .long -1
  86. .section .dtors,"aw"
  87. .align 4
  88. .global __DTOR_LIST__
  89. __DTOR_LIST__:
  90. .long -1
  91. #endif