crt1.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. mfusr $r15, $PC
  41. sethi $gp, HI20(_GLOBAL_OFFSET_TABLE_+4)
  42. ori $gp, $gp, LO12(_GLOBAL_OFFSET_TABLE_ + 8)
  43. add $gp, $r15, $gp
  44. la $r3, _init@GOTOFF
  45. la $r4, _fini@GOTOFF
  46. la $r0, main@GOT
  47. /* push everything to stack, r5 is rtld_fini and r7 is garbage */
  48. pushm $r0, $r7
  49. /* now start it up */
  50. bal __uClibc_main@PLT
  51. /* should never get here */
  52. bal abort@PLT
  53. #else
  54. la $gp, _SDA_BASE_ ! init GP for small data access
  55. la $r3, _init
  56. la $r4, _fini
  57. la $r0, main
  58. /* push everything to stack, r5 is rtld_fini and r7 is garbage */
  59. pushm $r0, $r7
  60. /* now start it up */
  61. bal __uClibc_main
  62. /* should never get here */
  63. bal abort
  64. #endif
  65. ret
  66. /* Define a symbol for the first piece of initialized data. */
  67. .data
  68. .globl __data_start
  69. __data_start:
  70. .long 0
  71. .weak data_start
  72. data_start = __data_start