crt1.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <features.h>
  7. .text
  8. #ifndef __UCLIBC_CTOR_DTOR__
  9. .weak _init
  10. .weak _fini
  11. #endif
  12. /* Stick in a dummy reference to main(), so that if an application
  13. * is linking when the main() function is in a static library (.a)
  14. * we can be sure that main() actually gets linked in
  15. */
  16. .type main,@function
  17. .type _main,@function
  18. /* When we enter this piece of code, the program stack looks like this:
  19. argc argument counter (integer)
  20. argv[0] program name (pointer)
  21. argv[1...N] program args (pointers)
  22. argv[argc-1] end of args (integer)
  23. NULL
  24. env[0...N] environment variables (pointers)
  25. NULL
  26. */
  27. .text
  28. .align 4
  29. .global __start
  30. .hidden __start
  31. .type __start,@function
  32. __start:
  33. mov fp, 0
  34. ld_s r1, [sp] ; argc
  35. mov_s r5, r0 ; rltd_fini
  36. add_s r2, sp, 4 ; argv
  37. #ifdef L_Scrt1
  38. ld r0, [pcl, @main@gotpc]
  39. ld r3, [pcl, @_init@gotpc]
  40. ld r4, [pcl, @_fini@gotpc]
  41. #else
  42. mov_s r0, main
  43. mov_s r3, _init
  44. mov r4, _fini
  45. #endif
  46. and sp, sp, -8
  47. mov r6, sp
  48. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  49. bl __uClibc_main
  50. /* Should never get here.... */
  51. flag 1
  52. .size __start,.-__start
  53. /* Implement a .note.ABI-tag section that is mandatory for Linux executables
  54. according to LSB. See:
  55. https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/noteabitag.html.
  56. Also: libc/sysdeps/linux/avr32/crt1.S. */
  57. .section ".note.ABI-tag", "a"
  58. .align 4
  59. .long 1f - 0f /* Name length */
  60. .long 3f - 2f /* Data length */
  61. .long 1 /* Note type */
  62. 0: .asciz "GNU" /* Vendor name */
  63. 1: .align 4
  64. 2: .long 0 /* Note data: Linux executable */
  65. .long 3,9,0 /* Earliest compatible kernel */
  66. 3: .align 4 /* Pad out section */