crt0.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * This is implemented completely in assembler to avoid that the
  9. * compiler pushes stuff on the stack (e.g. the frame pointer when
  10. * debuging).
  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__ ( \
  21. ".text\n\t" \
  22. ".global _start\n\t" \
  23. "_start:\n\t" \
  24. "pop $r10\n\t" \
  25. "move.d $sp, $r11\n\t" \
  26. "jump start1\n\t");
  27. #include <features.h>
  28. extern void __uClibc_main(int argc, char **argv, char **envp)
  29. __attribute__ ((__noreturn__));
  30. extern void __uClibc_start_main(int argc, char **argv, char **envp,
  31. void (*app_init)(void), void (*app_fini)(void))
  32. __attribute__ ((__noreturn__));
  33. extern void weak_function _init(void);
  34. extern void weak_function _fini(void);
  35. /* Stick in a dummy reference to main(), so that if an application
  36. * is linking when the main() function is in a static library (.a)
  37. * we can be sure that main() actually gets linked in */
  38. extern void main(int argc,void *argv,void *envp);
  39. void (*__mainp)(int argc,void *argv,void *envp) = main;
  40. static void
  41. start1 (int argc, char **argv)
  42. {
  43. char** environ;
  44. /* The environment starts just after ARGV. */
  45. environ = &argv[argc + 1];
  46. /*
  47. * If the first thing after ARGV is the arguments
  48. * themselves, there is no environment.
  49. */
  50. if ((char *) environ == *argv)
  51. /*
  52. * The environment is empty. Make environ
  53. * point at ARGV[ARGC], which is NULL.
  54. */
  55. --environ;
  56. #if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
  57. /* Leave control to the libc */
  58. __uClibc_main(argc, argv, environ);
  59. #else
  60. __uClibc_start_main(argc, argv, environ, _init, _fini);
  61. #endif
  62. }