dl-sysdep.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Various assmbly language/system dependent hacks that are required
  3. * so that we can minimize the amount of platform specific code.
  4. */
  5. /*
  6. * Define this if the system uses RELOCA.
  7. */
  8. #define ELF_USES_RELOCA
  9. /*
  10. * Initialization sequence for a GOT.
  11. */
  12. #define INIT_GOT(GOT_BASE,MODULE) _dl_init_got(GOT_BASE,MODULE)
  13. /* Stuff for the PLT. */
  14. #define PLT_INITIAL_ENTRY_WORDS 18
  15. #define PLT_LONGBRANCH_ENTRY_WORDS 0
  16. #define PLT_TRAMPOLINE_ENTRY_WORDS 6
  17. #define PLT_DOUBLE_SIZE (1<<13)
  18. #define PLT_ENTRY_START_WORDS(entry_number) \
  19. (PLT_INITIAL_ENTRY_WORDS + (entry_number)*2 \
  20. + ((entry_number) > PLT_DOUBLE_SIZE \
  21. ? ((entry_number) - PLT_DOUBLE_SIZE)*2 \
  22. : 0))
  23. #define PLT_DATA_START_WORDS(num_entries) PLT_ENTRY_START_WORDS(num_entries)
  24. /* Macros to build PowerPC opcode words. */
  25. #define OPCODE_ADDI(rd,ra,simm) \
  26. (0x38000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
  27. #define OPCODE_ADDIS(rd,ra,simm) \
  28. (0x3c000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
  29. #define OPCODE_ADD(rd,ra,rb) \
  30. (0x7c000214 | (rd) << 21 | (ra) << 16 | (rb) << 11)
  31. #define OPCODE_B(target) (0x48000000 | ((target) & 0x03fffffc))
  32. #define OPCODE_BA(target) (0x48000002 | ((target) & 0x03fffffc))
  33. #define OPCODE_BCTR() 0x4e800420
  34. #define OPCODE_LWZ(rd,d,ra) \
  35. (0x80000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
  36. #define OPCODE_LWZU(rd,d,ra) \
  37. (0x84000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
  38. #define OPCODE_MTCTR(rd) (0x7C0903A6 | (rd) << 21)
  39. #define OPCODE_RLWINM(ra,rs,sh,mb,me) \
  40. (0x54000000 | (rs) << 21 | (ra) << 16 | (sh) << 11 | (mb) << 6 | (me) << 1)
  41. #define OPCODE_LI(rd,simm) OPCODE_ADDI(rd,0,simm)
  42. #define OPCODE_ADDIS_HI(rd,ra,value) \
  43. OPCODE_ADDIS(rd,ra,((value) + 0x8000) >> 16)
  44. #define OPCODE_LIS_HI(rd,value) OPCODE_ADDIS_HI(rd,0,value)
  45. #define OPCODE_SLWI(ra,rs,sh) OPCODE_RLWINM(ra,rs,sh,0,31-sh)
  46. #define PPC_DCBST(where) asm volatile ("dcbst 0,%0" : : "r"(where) : "memory")
  47. #define PPC_SYNC asm volatile ("sync" : : : "memory")
  48. #define PPC_ISYNC asm volatile ("sync; isync" : : : "memory")
  49. #define PPC_ICBI(where) asm volatile ("icbi 0,%0" : : "r"(where) : "memory")
  50. #define PPC_DIE asm volatile ("tweq 0,0")
  51. /* Here we define the magic numbers that this dynamic loader should accept */
  52. #define MAGIC1 EM_PPC
  53. #undef MAGIC2
  54. /* Used for error messages */
  55. #define ELF_TARGET "powerpc"
  56. struct elf_resolve;
  57. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  58. void _dl_init_got(unsigned long *lpnt,struct elf_resolve *tpnt);
  59. #define do_rem(result, n, base) ((result) = (n) % (base))
  60. /* 4096 bytes alignment */
  61. #define PAGE_ALIGN 0xfffff000
  62. #define ADDR_ALIGN 0xfff
  63. #define OFFS_ALIGN 0x7ffff000
  64. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
  65. PLT entries should not be allowed to define the value.
  66. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  67. of the main executable's symbols, as for a COPY reloc. */
  68. /* We never want to use a PLT entry as the destination of a
  69. reloc, when what is being relocated is a branch. This is
  70. partly for efficiency, but mostly so we avoid loops. */
  71. #define elf_machine_type_class(type) \
  72. ((((type) == R_PPC_JMP_SLOT \
  73. || (type) == R_PPC_REL24 \
  74. || (type) == R_PPC_ADDR24) * ELF_RTYPE_CLASS_PLT) \
  75. | (((type) == R_PPC_COPY) * ELF_RTYPE_CLASS_COPY))
  76. /* The SVR4 ABI specifies that the JMPREL relocs must be inside the
  77. DT_RELA table. */
  78. #define ELF_MACHINE_PLTREL_OVERLAP 1