start.S 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Startup code compliant to the ELF LoongArch ABI.
  2. Copyright (C) 2022-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library; if not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #define __ASSEMBLY__ 1
  31. #include <entry.h>
  32. #include <sys/asm.h>
  33. /* The entry point's job is to call __libc_start_main. Per the ABI,
  34. a0 contains the address of a function to be passed to atexit.
  35. __libc_start_main wants this in a5. */
  36. /*
  37. int
  38. __libc_start_main (int (*main) (int, char **, char **),
  39. int argc,
  40. char **argv,
  41. __typeof (main) init,
  42. void (*fini) (void),
  43. void (*rtld_fini) (void),
  44. void *stack_end);
  45. */
  46. ENTRY (ENTRY_POINT)
  47. /* Terminate call stack by noting ra is undefined. Use a dummy
  48. .cfi_label to force starting the FDE. */
  49. .cfi_label .Ldummy
  50. cfi_undefined (1)
  51. or a5, a0, zero /* rtld_fini */
  52. la.pcrel a0, t0, main
  53. REG_L a1, sp, 0
  54. ADDI a2, sp, SZREG
  55. /* Adjust $sp for 16-aligned */
  56. BSTRINS sp, zero, 3, 0
  57. move a3, zero /* used to be init */
  58. move a4, zero /* used to be fini */
  59. or a6, sp, zero /* stack_end */
  60. la.pcrel ra, t0, __libc_start_main
  61. jirl ra, ra, 0
  62. la.pcrel ra, t0, abort
  63. jirl ra, ra, 0
  64. END (ENTRY_POINT)