crt0pic.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. @ r0 = argc
  38. @ r1 = argv
  39. @ r2 = envp
  40. @ sl = data segment
  41. #define BASEREG r9
  42. .text
  43. _start:
  44. @ adjust the data segment base pointer
  45. ldr r3,=__data_start
  46. sub sl,sl,r3
  47. mov BASEREG,sl
  48. /* pull argc, argv and envp off the stack */
  49. ldr r0,[sp, #0]
  50. ldr r1,[sp, #4]
  51. ldr r2,[sp, #8]
  52. /* Ok, now run uClibc's main() -- shouldn't return */
  53. bl __uClibc_main