crt0.S 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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