crt0.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA. */
  15. /* When we enter this piece of code, the user stack looks like this:
  16. * argc argument counter (integer)
  17. * argv[0] program name (pointer)
  18. * argv[1...N] program args (pointers)
  19. * NULL
  20. * env[0...N] environment variables (pointers)
  21. * NULL
  22. * When we are done here, we want
  23. * R0=argc
  24. * R1=*argv[0]
  25. * R2=*envp[0]
  26. */
  27. .text
  28. .align 2
  29. .global _start;
  30. .type _start,STT_FUNC;
  31. .global ___uClibc_main;
  32. .type ___uClibc_main,STT_FUNC;
  33. /* Stick in a dummy reference to main(), so that if an application
  34. * is linking when the main() function is in a static library (.a)
  35. * we can be sure that main() actually gets linked in */
  36. .type _main,STT_FUNC;
  37. _start:
  38. /* clear the frame pointer */
  39. FP = 0;
  40. /* Load register R0 (argc) from the stack to its final resting place */
  41. P0 = SP;
  42. R0 = [P0++];
  43. /* Copy argv pointer into R1 -- which its final resting place */
  44. R1 = P0;
  45. /* Skip to the end of argv and put a pointer to the environment in R2 */
  46. R2 = R0;
  47. R2 <<= 2;
  48. R2 += 4;
  49. R2 = R1+R2;
  50. /* Ok, now run uClibc's main() -- shouldn't return */
  51. sp += -12;
  52. jump.l ___uClibc_main;