crt0.S 1.5 KB

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