crt0.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. */
  10. #include <features.h>
  11. #include <sys/regdef.h>
  12. .text
  13. .global __start
  14. .type __start,%function
  15. .type __uClibc_start_main,%function
  16. .weak _init
  17. .weak _fini
  18. .type __uClibc_start_main,%function
  19. /* Stick in a dummy reference to main(), so that if an application
  20. * is linking when the main() function is in a static library (.a)
  21. * we can be sure that main() actually gets linked in */
  22. .type main,%function
  23. __start:
  24. #ifdef __PIC__
  25. .set noreorder
  26. bltzal zero,0f
  27. nop
  28. 0: .cpload $31
  29. .set reorder
  30. #endif
  31. move $31, zero /* no return, but since the jal kills $31, skip this */
  32. lw a0, 0($29) /* argc */
  33. addu a1, $29, 4 /* get to start of argv */
  34. addu a2, a0, 1 /* argv[0] program name (ordinal->cardinal) */
  35. sll a2, a2, 2 /* multiple by 4 */
  36. add a2, a2, a1 /* a2 now points to start of envp */
  37. la a3, _init /* a3 is address of _init */
  38. addiu sp, sp, -24 /* 16 + 4 rounded up to multiple of 8 */
  39. /* multiple of 8 for longlong/double support */
  40. la v0, _fini
  41. sw v0, 16(sp) /* stack has 5th argument, address of _fini */
  42. /* Ok, now run uClibc's main() -- shouldn't return */
  43. jal __uClibc_start_main
  44. addiu sp, sp, 24 /* undo stack argument */
  45. /* Crash if somehow `exit' returns anyways. */
  46. hlt:
  47. b hlt
  48. /* Define a symbol for the first piece of initialized data. */
  49. .data
  50. .globl __data_start
  51. __data_start:
  52. .long 0
  53. .weak data_start
  54. data_start = __data_start