crt1.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Startup code compliant to the ELF NDS32 ABI */
  6. #include <sys/regdef.h>
  7. #include <features.h>
  8. #define BP_SYM(name) name
  9. /* We need to call:
  10. __uClibc_main (int (*main) (int, char **, char **), int argc,
  11. char **argv, void (*init) (void), void (*fini) (void),
  12. void (*rtld_fini) (void), void *stack_end)
  13. */
  14. .text
  15. .globl _start
  16. .type _start,@function
  17. .type _init,@function
  18. .type _fini,@function
  19. #ifndef __UCLIBC_CTOR_DTOR__
  20. .weak _init
  21. .weak _fini
  22. #endif
  23. .type main,@function
  24. .type __uClibc_main,@function
  25. #ifdef SHARED
  26. .pic
  27. 1:
  28. ret
  29. #endif
  30. _start:
  31. movi $fp, 0 ! clear FP
  32. lwi $r1, [$sp + 0] ! r1 = argc
  33. addi $r2, $sp, 4 ! r2 = argv
  34. /* align sp to 8-byte boundary */
  35. movi $r0, -8
  36. and $sp, $sp, $r0
  37. addi $r6, $sp, 0 ! r6 = stack top
  38. #ifdef SHARED
  39. /* set gp register */
  40. #ifdef __NDS32_N1213_43U1H__
  41. jal 1b
  42. sethi $gp, HI20(_GLOBAL_OFFSET_TABLE_)
  43. ori $gp, $gp, LO12(_GLOBAL_OFFSET_TABLE_ + 4)
  44. add $gp, $lp, $gp
  45. #else
  46. mfusr $r15, $PC
  47. sethi $gp, HI20(_GLOBAL_OFFSET_TABLE_+4)
  48. ori $gp, $gp, LO12(_GLOBAL_OFFSET_TABLE_ + 8)
  49. add $gp, $r15, $gp
  50. #endif
  51. la $r3, _init@GOTOFF
  52. la $r4, _fini@GOTOFF
  53. la $r0, main@GOT
  54. /* push everything to stack, r5 is rtld_fini and r7 is garbage */
  55. pushm $r0, $r7
  56. /* now start it up */
  57. bal __uClibc_main@PLT
  58. /* should never get here */
  59. bal abort@PLT
  60. #else
  61. la $gp, _SDA_BASE_ ! init GP for small data access
  62. la $r3, _init
  63. la $r4, _fini
  64. la $r0, main
  65. /* push everything to stack, r5 is rtld_fini and r7 is garbage */
  66. pushm $r0, $r7
  67. /* now start it up */
  68. bal __uClibc_main
  69. /* should never get here */
  70. bal abort
  71. #endif
  72. ret
  73. /* Define a symbol for the first piece of initialized data. */
  74. .data
  75. .globl __data_start
  76. __data_start:
  77. .long 0
  78. .weak data_start
  79. data_start = __data_start