crt0.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Startup code compliant to the ELF CRIS ABI */
  2. /* The first piece of initialized data. */
  3. int __data_start = 0;
  4. /*
  5. * It is important that this be the first function.
  6. * This file is the first thing in the text section.
  7. */
  8. void
  9. _start ()
  10. {
  11. /*
  12. * On the stack we have argc. We can calculate argv/envp
  13. * from that and the succeeding stack location, but fix so
  14. * we get the right calling convention (regs in r10/r11).
  15. *
  16. * Please view linux/fs/binfmt_elf.c for a complete
  17. * understanding of this.
  18. */
  19. __asm__ volatile("pop $r10");
  20. __asm__ volatile("move.d $sp, $r11");
  21. __asm__ volatile("jump start1");
  22. }
  23. #include <features.h>
  24. extern void __uClibc_main(int argc, char **argv, char **envp)
  25. __attribute__ ((__noreturn__));
  26. extern void __uClibc_start_main(int argc, char **argv, char **envp,
  27. void (*app_init)(void), void (*app_fini)(void))
  28. __attribute__ ((__noreturn__));
  29. extern void weak_function _init(void);
  30. extern void weak_function _fini(void);
  31. static void
  32. start1 (int argc, char **argv)
  33. {
  34. char** environ;
  35. /* The environment starts just after ARGV. */
  36. environ = &argv[argc + 1];
  37. /*
  38. * If the first thing after ARGV is the arguments
  39. * themselves, there is no environment.
  40. */
  41. if ((char *) environ == *argv)
  42. /*
  43. * The environment is empty. Make environ
  44. * point at ARGV[ARGC], which is NULL.
  45. */
  46. --environ;
  47. #if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
  48. /* Leave control to the libc */
  49. __uClibc_main(argc, argv, environ);
  50. #else
  51. __uClibc_start_main(argc, argv, environ, _init, _fini);
  52. #endif
  53. }