crt0.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. env[0...N] environment variables (pointers)
  7. NULL
  8. This file now uses the register naming from the ARM Procedure Calling Standard
  9. Name Number APCS Role
  10. a1 0 argument 1 / integer result / scratch register / argc
  11. a2 1 argument 2 / scratch register / argv
  12. a3 2 argument 3 / scratch register / envp
  13. a4 3 argument 4 / scratch register
  14. v1 4 register variable
  15. v2 5 register variable
  16. v3 6 register variable
  17. v4 7 register variable
  18. v5 8 register variable
  19. sb/v6 9 static base / register variable
  20. sl/v7 10 stack limit / stack chunk handle / reg. variable
  21. fp 11 frame pointer
  22. ip 12 scratch register / new-sb in inter-link-unit calls
  23. sp 13 lower end of current stack frame
  24. lr 14 link address / scratch register
  25. pc 15 program counter
  26. */
  27. .text
  28. .align 2
  29. .global __environ
  30. .global _start
  31. .global exit
  32. .global main
  33. .global __libc_init
  34. .global __init_stdio
  35. .global __stdio_close_all
  36. .global _void_void_null_func
  37. .type _start,%function
  38. .type exit,%function
  39. .type main,%function
  40. .type __libc_init,%function
  41. .type __init_stdio,%function
  42. .type __stdio_close_all,%function
  43. .type _void_void_null_func,%function
  44. .text
  45. _start:
  46. /* clear the frame pointer */
  47. mov fp, #0
  48. /* Load argc into a1 -- its final resting place */
  49. ldr a1, [sp], #4
  50. /* Load argv into a2 -- which its final resting place */
  51. mov a2, sp
  52. /* Set up environ, skip to the end of argv, and put
  53. * a pointer to whatever we find there (hopefully the
  54. environment) in a3 */
  55. ldr a4, .L3
  56. add a3, a2, a1, lsl #2
  57. add a3, a3, #4
  58. str a3, [a4, #0]
  59. /* Tell libc to initialize whatever it needs */
  60. bl __libc_init
  61. bl __init_stdio
  62. bl main
  63. bl exit
  64. _void_void_null_func:
  65. nop
  66. .weak __libc_init
  67. __libc_init = _void_void_null_func
  68. .weak __init_stdio
  69. __init_stdio = _void_void_null_func
  70. .weak __stdio_close_all
  71. __stdio_close_all = _void_void_null_func
  72. .align 2
  73. .L3:
  74. .word environ
  75. .data
  76. .align 2
  77. .global __environ
  78. __environ:
  79. .long 0
  80. .weak environ
  81. environ = __environ