crt1.S 2.9 KB

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