crt1.S 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. _start:
  39. call .Lload_gp
  40. mv a5, a0 /* rtld_fini. */
  41. /* main may be in a shared library. */
  42. la a0, main
  43. REG_L a1, 0(sp) /* argc. */
  44. addi a2, sp, SZREG /* argv. */
  45. mv a3, zero
  46. mv a4, zero
  47. andi sp, sp, ALMASK /* Align stack. */
  48. mv a6, sp /* stack_end. */
  49. tail __uClibc_main@plt
  50. .size _start,.-_start
  51. /* Dynamic links need the global pointer to be initialized prior to calling
  52. any shared library's initializers, so we use preinit_array to load it.
  53. This doesn't cut it for static links, though, since the global pointer
  54. needs to be initialized before calling __libc_start_main in that case.
  55. So we redundantly initialize it at the beginning of _start. */
  56. .Lload_gp:
  57. .option push
  58. .option norelax
  59. lla gp, __global_pointer$
  60. .option pop
  61. ret
  62. .section .preinit_array,"aw"
  63. .dc.a .Lload_gp
  64. /* Define a symbol for the first piece of initialized data. */
  65. .data
  66. .globl __data_start
  67. __data_start:
  68. .weak data_start
  69. data_start = __data_start