crt1.S 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * [SP] 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
  17. * R2=__init
  18. * SP=__fini
  19. */
  20. #include <features.h>
  21. .text
  22. .align 2
  23. .global __start;
  24. .type __start,STT_FUNC;
  25. .global ___uClibc_main;
  26. .type ___uClibc_main,STT_FUNC;
  27. #define __UCLIBC_CTOR_DTOR__
  28. #if defined(__UCLIBC_CTOR_DTOR__)
  29. .weak __init;
  30. .weak __fini;
  31. #endif
  32. __start:
  33. /* clear the frame pointer and the L registers. */
  34. FP = 0;
  35. L0 = 0;
  36. L1 = 0;
  37. L2 = 0;
  38. L3 = 0;
  39. /* Load register R0 (argc) from the stack to its final resting place */
  40. P0 = SP;
  41. R0 = [P0++];
  42. /* Copy argv pointer into R1 */
  43. R1 = P0;
  44. #if defined(__UCLIBC_CTOR_DTOR__)
  45. /* Load __init into R2 */
  46. R2.H = __init;
  47. R2.L = __init;
  48. /* Load __fini onto the stack */
  49. SP += -16;
  50. R3.H = __fini;
  51. R3.L = __fini;
  52. [SP+12] = R3;
  53. #else
  54. /* Just fixup the stack */
  55. sp += -12;
  56. #endif
  57. /* Ok, now run uClibc's main() -- shouldn't return */
  58. jump.l ___uClibc_main;
  59. .size __start,.-__start