crt1.S 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Startup code compliant to the ELF LoongArch64 ABI.
  2. Copyright (C) 2024 uClibc-ng contributors.
  3. Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #define __ASSEMBLY__ 1
  6. #include <sysdep.h>
  7. #include <sys/asm.h>
  8. /* The entry point's job is to call __uClibc_main. Per the ABI,
  9. a0 contains the address of a function to be passed to atexit.
  10. __uClibc_main wants this in a5. */
  11. .text
  12. .globl _start
  13. .type _start,%function
  14. _start:
  15. move $s0, $a0 /* rtld_fini. */
  16. #ifdef L_rcrt1
  17. la.pcrel $a0, __ehdr_start
  18. bl reloc_static_pie
  19. #endif
  20. move $a5, $s0 /* rtld_fini. */
  21. /* main may be in a shared library. */
  22. la.got $a0, main
  23. ld.d $a1, $sp, 0 /* argc. */
  24. addi.d $a2, $sp, SZREG /* argv. */
  25. move $a3, $zero
  26. move $a4, $zero
  27. bstrins.d $sp, $zero, 3, 0 /* Align stack to 16 bytes. */
  28. move $a6, $sp /* stack_end. */
  29. bl __uClibc_main
  30. .size _start,.-_start
  31. /* Define a symbol for the first piece of initialized data. */
  32. .data
  33. .globl __data_start
  34. __data_start:
  35. .weak data_start
  36. data_start = __data_start