crt1.S 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Startup code compliant to the ELF RISC-V ABI.
  2. Copyright (C) 1995-2018 Free Software Foundation, Inc.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. In addition to the permissions in the GNU Lesser General Public
  8. License, the Free Software Foundation gives you unlimited
  9. permission to link the compiled version of this file with other
  10. programs, and to distribute those programs without any restriction
  11. coming from the use of this file. (The GNU Lesser General Public
  12. License restrictions do apply in other respects; for example, they
  13. cover modification of the file, and distribution when not linked
  14. into another program.)
  15. Note that people who make modified versions of this file are not
  16. obligated to grant this special exception for their modified
  17. versions; it is their choice whether to do so. The GNU Lesser
  18. General Public License gives permission to release a modified
  19. version without this exception; this exception also makes it
  20. possible to release a modified version which carries forward this
  21. exception.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library. If not, see
  28. <http://www.gnu.org/licenses/>. */
  29. #define __ASSEMBLY__ 1
  30. #include <sysdep.h>
  31. #include <sys/asm.h>
  32. /* The entry point's job is to call __uClibc_main. Per the ABI,
  33. a0 contains the address of a function to be passed to atexit.
  34. __uClibc_main wants this in a5. */
  35. .text
  36. .globl _start
  37. .type _start,%function
  38. .weak _init
  39. .weak _fini
  40. _start:
  41. call .Lload_gp
  42. mv a5, a0 /* rtld_fini. */
  43. /* main may be in a shared library. */
  44. la a0, main
  45. REG_L a1, 0(sp) /* argc. */
  46. addi a2, sp, SZREG /* argv. */
  47. andi sp, sp, ALMASK /* Align stack. */
  48. lla a3, _init
  49. lla a4, _fini
  50. mv a6, sp /* stack_end. */
  51. tail __uClibc_main@plt
  52. .size _start,.-_start
  53. /* Dynamic links need the global pointer to be initialized prior to calling
  54. any shared library's initializers, so we use preinit_array to load it.
  55. This doesn't cut it for static links, though, since the global pointer
  56. needs to be initialized before calling __libc_start_main in that case.
  57. So we redundantly initialize it at the beginning of _start. */
  58. .Lload_gp:
  59. .option push
  60. .option norelax
  61. lla gp, __global_pointer$
  62. .option pop
  63. ret
  64. .section .preinit_array,"aw"
  65. .dc.a .Lload_gp
  66. /* Define a symbol for the first piece of initialized data. */
  67. .data
  68. .globl __data_start
  69. __data_start:
  70. .weak data_start
  71. data_start = __data_start