crt1.S 3.0 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. _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. /*
  46. * No support fo app_init/app_fini as we don't support shared libraries.
  47. */
  48. mv a3, zero
  49. mv a4, zero
  50. andi sp, sp, ALMASK /* Align stack. */
  51. mv a6, sp /* stack_end. */
  52. tail __uClibc_main@plt
  53. .size _start,.-_start
  54. /* Dynamic links need the global pointer to be initialized prior to calling
  55. any shared library's initializers, so we use preinit_array to load it.
  56. This doesn't cut it for static links, though, since the global pointer
  57. needs to be initialized before calling __libc_start_main in that case.
  58. So we redundantly initialize it at the beginning of _start. */
  59. .Lload_gp:
  60. .option push
  61. .option norelax
  62. lla gp, __global_pointer$
  63. .option pop
  64. ret
  65. .section .preinit_array,"aw"
  66. .dc.a .Lload_gp
  67. /* Define a symbol for the first piece of initialized data. */
  68. .data
  69. .globl __data_start
  70. __data_start:
  71. .weak data_start
  72. data_start = __data_start