dl-startup.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifdef __CSKYABIV2__
  8. __asm__ (
  9. " .text\n\t"
  10. " .globl _start\n\t"
  11. "_start:\n\t"
  12. " mov a0, sp\n\t"
  13. " bsr _dl_start\n\t"
  14. " # Return from _dl_start, user entry point address in a0 \n\t"
  15. " # the code is PIC, so get global offset table\n\t"
  16. " grs gb,.Lgetpc1\n\t"
  17. ".Lgetpc1:\n\t "
  18. " lrw t0, .Lgetpc1@GOTPC\n\t"
  19. " add gb, gb,t0\n\t"
  20. " lrw r5, _dl_skip_args@GOT\n\t"
  21. " ldr.w r5, (gb, r5 << 0)\n\t"
  22. " # get the value of variable _dl_skip_args in r6\n\t"
  23. " ldw r6, (r5, 0)\n\t"
  24. " # get the argc in r7 \n\t"
  25. " ldw r7, (sp, 0)\n\t"
  26. " # adjust the argc, this may be a bug when _dl_skip_args > argc\n\t"
  27. " rsub r6, r7\n\t"
  28. " # adjust the stack\n\t"
  29. " mov r7, r6\n\t"
  30. " lsli r6, 2\n\t"
  31. " # adjust the stack pointer,this may be a bug, "
  32. " # because it must be 8 bytes align"
  33. " addu sp, r6\n\t"
  34. " stw r7, (sp, 0)\n\t"
  35. " lrw r7, _dl_fini@GOTOFF\n\t"
  36. " addu r7, gb\n\t"
  37. " jmp a0"
  38. );
  39. #else
  40. __asm__ (
  41. " .text\n\t"
  42. " .globl _start\n\t"
  43. "_start:\n\t"
  44. " mov r2, r0\n\t"
  45. # if defined(__ck810__)
  46. " bsr _dl_start\n\t"
  47. #else
  48. " # the code is PIC, so get global offset table\n\t"
  49. " bsr .Lgetpc0\n\t"
  50. ".Lgetpc0:\n\t "
  51. " lrw r14, .Lgetpc0@GOTPC\n\t"
  52. " add r14, r15\n\t"
  53. " lrw r4, _dl_start@GOTOFF\n\t"
  54. " add r4, r14\n\t"
  55. " jsr r4\n\t"
  56. #endif
  57. " # Return from _dl_start, user entry point address in r2 \n\t"
  58. " # the code is PIC, so get global offset table\n\t"
  59. " bsr .Lgetpc1\n\t"
  60. ".Lgetpc1:\n\t "
  61. " lrw r3, .Lgetpc1@GOTPC\n\t"
  62. " add r3, r15\n\t"
  63. # if defined(__ck810__)
  64. " ldw r5, (r3, _dl_skip_args@GOT)\n\t"
  65. #else
  66. " lrw r4, _dl_skip_args@GOT\n\t"
  67. " add r4, r3\n\t"
  68. " ldw r5, (r4, 0)\n\t"
  69. #endif
  70. " # get the value of variable _dl_skip_args in r6\n\t"
  71. " ldw r6, (r5, 0)\n\t"
  72. " # get the argc in r7 \n\t"
  73. " ldw r7, (r0, 0)\n\t"
  74. " # adjust the argc, this may be a bug when _dl_skip_args > argc\n\t"
  75. " rsub r6, r7\n\t"
  76. " # adjust the stack\n\t"
  77. " mov r7, r6\n\t"
  78. " lsli r6, 2\n\t"
  79. " # adjust the stack pointer,this may be a bug, "
  80. " # because it must be 8 bytes align"
  81. " addu r0, r6\n\t"
  82. " stw r7, (r0, 0)\n\t"
  83. " lrw r7, _dl_fini@GOTOFF\n\t"
  84. " addu r7, r3\n\t"
  85. " jmp r2"
  86. );
  87. #endif
  88. /* Get a pointer to the argv array. */
  89. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*)ARGS)+1)
  90. /* Function calls are not safe until the GOT relocations have been done. */
  91. #define NO_FUNCS_BEFORE_BOOTSTRAP
  92. /* Handle relocation of the symbols in the dynamic loader. */
  93. static __always_inline
  94. void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  95. unsigned long symbol_addr, unsigned long load_addr, attribute_unused Elf32_Sym *symtab)
  96. {
  97. switch (ELF32_R_TYPE(rpnt->r_info))
  98. {
  99. case R_CKCORE_RELATIVE:
  100. *reloc_addr = load_addr + rpnt->r_addend;
  101. break;
  102. case R_CKCORE_GLOB_DAT:
  103. case R_CKCORE_JUMP_SLOT:
  104. *reloc_addr = symbol_addr;
  105. break;
  106. case R_CKCORE_ADDR32:
  107. *reloc_addr = symbol_addr + rpnt->r_addend;
  108. break;
  109. case R_CKCORE_NONE:
  110. break;
  111. default:
  112. _dl_exit(1);
  113. }
  114. }