ld_sysdep.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * Get a pointer to the argv array. On many platforms this can be just
  11. * the address if the first argument, on other platforms we need to
  12. * do something a little more subtle here.
  13. */
  14. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*) ARGS)
  15. /*
  16. * Initialization sequence for a GOT.
  17. */
  18. #define INIT_GOT(GOT_BASE,MODULE) \
  19. { \
  20. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  21. GOT_BASE[1] = (unsigned long) (MODULE); \
  22. }
  23. /*
  24. * Here is a macro to perform a relocation. This is only used when
  25. * bootstrapping the dynamic loader. RELP is the relocation that we
  26. * are performing, REL is the pointer to the address we are relocating.
  27. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  28. * load address.
  29. */
  30. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \
  31. switch(ELF32_R_TYPE((RELP)->r_info)){ \
  32. case R_SH_REL32: \
  33. *(REL) += (RELP)->r_addend - (LOAD); \
  34. break; \
  35. case R_SH_DIR32: \
  36. *(REL) += (SYMBOL) + (RELP)->r_addend; \
  37. break; \
  38. case R_SH_RELATIVE: \
  39. *(REL) += (LOAD); \
  40. break; \
  41. case R_SH_NONE: \
  42. break; \
  43. default: \
  44. SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc type "); \
  45. SEND_NUMBER_STDERR(ELF32_R_TYPE((RELP)->r_info), 1); \
  46. SEND_STDERR("REL, SYMBOL, LOAD: "); \
  47. SEND_ADDRESS_STDERR(REL, 0); \
  48. SEND_STDERR(", "); \
  49. SEND_ADDRESS_STDERR(SYMBOL, 0); \
  50. SEND_STDERR(", "); \
  51. SEND_ADDRESS_STDERR(LOAD, 1); \
  52. _dl_exit(1); \
  53. }
  54. /*
  55. * Transfer control to the user's application, once the dynamic loader
  56. * is done. This routine has to exit the current function, then
  57. * call the _dl_elf_main function.
  58. */
  59. #define START() return _dl_elf_main;
  60. /* Here we define the magic numbers that this dynamic loader should accept */
  61. #define MAGIC1 EM_SH
  62. #undef MAGIC2
  63. /* Used for error messages */
  64. #define ELF_TARGET "sh"
  65. struct elf_resolve;
  66. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  67. static __inline__ unsigned int
  68. _dl_urem(unsigned int n, unsigned int base)
  69. {
  70. register unsigned int __r0 __asm__ ("r0");
  71. register unsigned int __r4 __asm__ ("r4") = n;
  72. register unsigned int __r5 __asm__ ("r5") = base;
  73. __asm__ ("
  74. mov #0, r0
  75. div0u
  76. ! get one bit from the msb of the numerator into the T
  77. ! bit and divide it by whats in %2. Put the answer bit
  78. ! into the T bit so it can come out again at the bottom
  79. rotcl r4 ; div1 r5, r0
  80. rotcl r4 ; div1 r5, r0
  81. rotcl r4 ; div1 r5, r0
  82. rotcl r4 ; div1 r5, r0
  83. rotcl r4 ; div1 r5, r0
  84. rotcl r4 ; div1 r5, r0
  85. rotcl r4 ; div1 r5, r0
  86. rotcl r4 ; div1 r5, r0
  87. rotcl r4 ; div1 r5, r0
  88. rotcl r4 ; div1 r5, r0
  89. rotcl r4 ; div1 r5, r0
  90. rotcl r4 ; div1 r5, r0
  91. rotcl r4 ; div1 r5, r0
  92. rotcl r4 ; div1 r5, r0
  93. rotcl r4 ; div1 r5, r0
  94. rotcl r4 ; div1 r5, r0
  95. rotcl r4 ; div1 r5, r0
  96. rotcl r4 ; div1 r5, r0
  97. rotcl r4 ; div1 r5, r0
  98. rotcl r4 ; div1 r5, r0
  99. rotcl r4 ; div1 r5, r0
  100. rotcl r4 ; div1 r5, r0
  101. rotcl r4 ; div1 r5, r0
  102. rotcl r4 ; div1 r5, r0
  103. rotcl r4 ; div1 r5, r0
  104. rotcl r4 ; div1 r5, r0
  105. rotcl r4 ; div1 r5, r0
  106. rotcl r4 ; div1 r5, r0
  107. rotcl r4 ; div1 r5, r0
  108. rotcl r4 ; div1 r5, r0
  109. rotcl r4 ; div1 r5, r0
  110. rotcl r4 ; div1 r5, r0
  111. rotcl r4
  112. mov r4, r0
  113. "
  114. : "=r" (__r0)
  115. : "r" (__r4), "r" (__r5)
  116. : "r4", "cc");
  117. return n - (base * __r0);
  118. }
  119. #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
  120. /* 4096 bytes alignment */
  121. #define PAGE_ALIGN 0xfffff000
  122. #define ADDR_ALIGN 0xfff
  123. #define OFFS_ALIGN 0x7ffff000