crt0.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /* Stick in a dummy reference to main(), so that if an application
  33. * is linking when the main() function is in a static library (.a)
  34. * we can be sure that main() actually gets linked in */
  35. extern void main(int argc,void *argv,void *envp);
  36. void (*__mainp)(int argc,void *argv,void *envp) = main;
  37. static void
  38. start1 (int argc, char **argv)
  39. {
  40. char** environ;
  41. /* The environment starts just after ARGV. */
  42. environ = &argv[argc + 1];
  43. /*
  44. * If the first thing after ARGV is the arguments
  45. * themselves, there is no environment.
  46. */
  47. if ((char *) environ == *argv)
  48. /*
  49. * The environment is empty. Make environ
  50. * point at ARGV[ARGC], which is NULL.
  51. */
  52. --environ;
  53. #if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
  54. /* Leave control to the libc */
  55. __uClibc_main(argc, argv, environ);
  56. #else
  57. __uClibc_start_main(argc, argv, environ, _init, _fini);
  58. #endif
  59. }