dl-sysdep.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /* Define this if the system uses RELOCA. */
  8. #define ELF_USES_RELOCA
  9. #include <elf.h>
  10. /* Initialization sequence for the GOT. */
  11. #define INIT_GOT(GOT_BASE,MODULE) \
  12. do { \
  13. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  14. GOT_BASE[1] = (unsigned long) MODULE; \
  15. } while(0)
  16. /* Here we define the magic numbers that this dynamic loader should accept */
  17. #define MAGIC1 EM_MCORE
  18. #define MAGIC2 EM_CSKY
  19. /* Used for error messages */
  20. #define ELF_TARGET "csky"
  21. struct elf_resolve;
  22. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  23. /* 65536 bytes alignment */
  24. #define PAGE_ALIGN 0xfffff000 /* need modify */
  25. #define ADDR_ALIGN 0xfff
  26. #define OFFS_ALIGN 0x7ffff000
  27. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  28. TLS variable, so undefined references should not be allowed to
  29. define the value.
  30. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  31. of the main executable's symbols, as for a COPY reloc. */
  32. #define elf_machine_type_class(type) \
  33. ((((type) == R_CKCORE_JUMP_SLOT || (type) == R_CKCORE_TLS_DTPMOD32 \
  34. || (type) == R_CKCORE_TLS_DTPOFF32 || (type) == R_CKCORE_TLS_TPOFF32) \
  35. * ELF_RTYPE_CLASS_PLT) \
  36. | (((type) == R_CKCORE_COPY) * ELF_RTYPE_CLASS_COPY))
  37. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  38. first element of the GOT. This must be inlined in a function which
  39. uses global data. */
  40. static __inline__ Elf32_Addr elf_machine_dynamic (void) attribute_unused;
  41. static __inline__ Elf32_Addr
  42. elf_machine_dynamic (void)
  43. {
  44. register Elf32_Addr *got __asm__ ("gb"); /* need modify */
  45. return *got;
  46. }
  47. /* this funtion will be called only when the auxvt[AT_BASE].a_un.a_val == 0
  48. so it normal not be called, we should define a default address of the interprrter load */
  49. static __inline__ Elf32_Addr elf_machine_load_address (void) attribute_unused;
  50. static __inline__ Elf32_Addr
  51. elf_machine_load_address (void)
  52. {
  53. #ifdef __CSKYABIV2__
  54. extern Elf32_Addr internal_function __dl_start (void *) __asm__ ("_dl_start");
  55. Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
  56. Elf32_Addr pcrel_addr;
  57. __asm__ ("grs %0,_dl_start\n" : "=r" (pcrel_addr));
  58. #else
  59. extern Elf32_Addr internal_function __start_flag (void *) __asm__ ("start_flag");
  60. Elf32_Addr got_addr = (Elf32_Addr) &__start_flag;
  61. Elf32_Addr pcrel_addr;
  62. __asm__ ("subi sp,8\n" \
  63. "stw lr,(sp,0)\n" \
  64. "bsr start_flag\n" \
  65. "start_flag:" \
  66. "mov %0, lr\n" \
  67. "ldw lr,(sp,0)\n" \
  68. "addi sp,8\n" \
  69. : "=r" (pcrel_addr));
  70. #endif
  71. return pcrel_addr - got_addr;
  72. }
  73. /* some relocation information are machine special */
  74. static __inline__ void
  75. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  76. Elf32_Word relative_count)
  77. {
  78. Elf32_Rela *rpnt = (void *) rel_addr;
  79. --rpnt;
  80. do {
  81. Elf32_Addr *reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
  82. *reloc_addr = load_off + rpnt->r_addend;
  83. } while (--relative_count); /* maybe need modify */
  84. }