crt1.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Initial C runtime code for Blackfin
  2. *
  3. * Copyright (C) 2004-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. /* When we enter this piece of code, the user stack looks like this:
  8. * argc argument counter (integer)
  9. * argv[0] program name (pointer)
  10. * argv[1...N] program args (pointers)
  11. * NULL
  12. * env[0...N] environment variables (pointers)
  13. * NULL
  14. * When we are done here, we want
  15. * R0=argc
  16. * R1=*argv[0]
  17. * R2=*envp[0]
  18. */
  19. #include <features.h>
  20. .text
  21. .align 2
  22. .global __start;
  23. .type __start,STT_FUNC;
  24. .global ___uClibc_main;
  25. .type ___uClibc_main,STT_FUNC;
  26. #if defined(__UCLIBC_CTOR_DTOR__)
  27. .type __init,%function
  28. .type __fini,%function
  29. #else
  30. .weak __init
  31. .weak __fini
  32. #endif
  33. /*
  34. When we enter, our stack looks like:
  35. [ SP ]
  36. [argc][argv]...
  37. Call ___uClibc_main(argc, argv, __init, __fini)
  38. R0 R1 R2 stack
  39. Before we call main, we want:
  40. [ SP ]
  41. [fini][argc][argv]
  42. */
  43. __start:
  44. /* clear the frame pointer */
  45. FP = 0;
  46. /* Load register R0 (argc) from the stack to its final resting place */
  47. P0 = SP;
  48. R0 = [P0++];
  49. /* Copy argv pointer into R1 */
  50. R1 = P0;
  51. /* Load __init into R2 */
  52. R2 = __init;
  53. /* Load __fini onto the stack */
  54. P0 = __fini;
  55. [SP--] = P0;
  56. /* Ok, now run uClibc's main() -- shouldn't return */
  57. sp += -8;
  58. jump.l ___uClibc_main;
  59. .size __start,.-__start