crt1.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2017 Hangzhou C-SKY Microsystems co.,ltd.
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
  5. * in this tarball.
  6. */
  7. #include <sysdep.h>
  8. .text
  9. .global _start
  10. .type _start,%function
  11. .global __exit
  12. .global atexit
  13. .global _init
  14. .global _fini
  15. .global main
  16. .global __uClibc_main
  17. /*
  18. * argc, argv and envp are on the stack
  19. *
  20. * Call:
  21. * void __uClibc_main(
  22. * int (*main)(int, char **, char **),
  23. * int argc,
  24. * char **argv,
  25. * void (*app_init)(void),
  26. * void (*app_fini)(void),
  27. * void (*rtld_fini)(void),
  28. * void *stack_end attribute_unused);
  29. */
  30. _start:
  31. #ifdef __PIC__
  32. __GET_GB
  33. lrw a0, main@GOT
  34. addu a0, gb
  35. ldw a0, (a0)
  36. ldw a1, (sp)
  37. mov a2, sp
  38. addi a2, 4
  39. mov a3, sp /* push stack_end */
  40. subi sp, 8
  41. stw a3, (sp)
  42. lrw a3, _init@GOT
  43. addu a3, gb
  44. ldw a3, (a3)
  45. #ifdef __CSKYABIV2__
  46. subi sp, 8
  47. lrw l4, _fini@GOT
  48. addu l4, gb
  49. ldw l4, (l4)
  50. stw l4, (sp)
  51. stw r7, (sp, 4) /* push rtld_fini */
  52. #else
  53. lrw a4, _fini@GOT
  54. addu a4, gb
  55. ldw a4, (a4)
  56. #endif
  57. lrw l4, __uClibc_main@PLT
  58. addu l4, gb
  59. ldw l4, (l4)
  60. jsr l4
  61. #else /* __PIC__ */
  62. lrw a0, main
  63. ldw a1, (sp)
  64. mov a2, sp
  65. addi a2, 4
  66. mov a3, sp /* push stack_end */
  67. subi sp, 8
  68. stw a3, (sp)
  69. lrw a3, _init
  70. #ifdef __CSKYABIV2__
  71. subi sp, 8
  72. lrw l4, _fini
  73. stw l4, (sp)
  74. stw r7, (sp, 4)
  75. #else
  76. lrw a4, _fini
  77. #endif
  78. lrw l4, __uClibc_main
  79. jsr l4
  80. #endif /* __PIC__ */
  81. bsr __exit
  82. __exit:
  83. DO_CALL(exit, 0)
  84. br .