crt0.c 1.6 KB

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