crt1.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /* Use the universal 32-bit add instruction as 16-bit add_s was excluded from
  37. ARCv3 ISA */
  38. add r2, sp, 4 ; argv
  39. #ifdef L_Scrt1
  40. ld r0, [pcl, @main@gotpc]
  41. ld r3, [pcl, @_init@gotpc]
  42. ld r4, [pcl, @_fini@gotpc]
  43. #else
  44. mov_s r0, main
  45. mov_s r3, _init
  46. mov r4, _fini
  47. #endif
  48. and sp, sp, -8
  49. mov r6, sp
  50. /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
  51. bl __uClibc_main
  52. /* Should never get here.... */
  53. flag 1
  54. .size __start,.-__start
  55. /* Implement a .note.ABI-tag section that is mandatory for Linux executables
  56. according to LSB. See:
  57. https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/noteabitag.html.
  58. Also: libc/sysdeps/linux/avr32/crt1.S. */
  59. .section ".note.ABI-tag", "a"
  60. .align 4
  61. .long 1f - 0f /* Name length */
  62. .long 3f - 2f /* Data length */
  63. .long 1 /* Note type */
  64. 0: .asciz "GNU" /* Vendor name */
  65. 1: .align 4
  66. 2: .long 0 /* Note data: Linux executable */
  67. #if (__GNUC__ > 4)
  68. .long 4,8,0 /* Earliest compatible kernel for ABI v4 */
  69. #else
  70. .long 3,9,0 /* Earliest compatible kernel for ABI v3 */
  71. #endif
  72. 3: .align 4 /* Pad out section */