crt0.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  24. lw a0, 0($29) /* argc */
  25. addu a1, $29, 4 /* argv */
  26. addu a2, a0, 1 /* load envp */
  27. sll a2, a2, 2
  28. add a2, a2, a1
  29. /* Store the address of _init in a3 as an argument to __uClibc_start_main() */
  30. la a3, _init
  31. /* Push _fini onto the stack as the final argument to __uClibc_start_main()
  32. I don't think I am doing this properly but it at least compiles...
  33. */
  34. la t0, _fini
  35. sw t0,16(sp)
  36. /* Ok, now run uClibc's main() -- shouldn't return */
  37. jal __uClibc_start_main
  38. /* Crash if somehow `exit' returns anyways. */
  39. hlt:
  40. b hlt
  41. /* Stick in a dummy reference to main(), so that if an application
  42. * is linking when the main() function is in a static library (.a)
  43. * we can be sure that main() actually gets linked in */
  44. L_dummy_main_reference:
  45. .long main