ld_sysdep.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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) = (SYMBOL) + (RELP)->r_addend \
  34. - (unsigned long)(REL); \
  35. break; \
  36. case R_SH_DIR32: \
  37. case R_SH_GLOB_DAT: \
  38. case R_SH_JMP_SLOT: \
  39. *(REL) = (SYMBOL) + (RELP)->r_addend; \
  40. break; \
  41. case R_SH_RELATIVE: \
  42. *(REL) = (LOAD) + (RELP)->r_addend; \
  43. break; \
  44. case R_SH_NONE: \
  45. break; \
  46. default: \
  47. SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc type "); \
  48. SEND_NUMBER_STDERR(ELF32_R_TYPE((RELP)->r_info), 1); \
  49. SEND_STDERR("REL, SYMBOL, LOAD: "); \
  50. SEND_ADDRESS_STDERR(REL, 0); \
  51. SEND_STDERR(", "); \
  52. SEND_ADDRESS_STDERR(SYMBOL, 0); \
  53. SEND_STDERR(", "); \
  54. SEND_ADDRESS_STDERR(LOAD, 1); \
  55. _dl_exit(1); \
  56. }
  57. /*
  58. * Transfer control to the user's application, once the dynamic loader
  59. * is done. This routine has to exit the current function, then
  60. * call the _dl_elf_main function.
  61. */
  62. #define START() return _dl_elf_main;
  63. /* Here we define the magic numbers that this dynamic loader should accept */
  64. #define MAGIC1 EM_SH
  65. #undef MAGIC2
  66. /* Used for error messages */
  67. #define ELF_TARGET "sh"
  68. struct elf_resolve;
  69. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  70. static __inline__ unsigned int
  71. _dl_urem(unsigned int n, unsigned int base)
  72. {
  73. int res;
  74. __asm__ (""\
  75. "mov #0, r0\n\t" \
  76. "div0u\n\t" \
  77. "" \
  78. "! get one bit from the msb of the numerator into the T\n\t" \
  79. "! bit and divide it by whats in %2. Put the answer bit\n\t" \
  80. "! into the T bit so it can come out again at the bottom\n\t" \
  81. "" \
  82. "rotcl %1 ; div1 %2, r0\n\t" \
  83. "rotcl %1 ; div1 %2, r0\n\t" \
  84. "rotcl %1 ; div1 %2, r0\n\t" \
  85. "rotcl %1 ; div1 %2, r0\n\t" \
  86. "rotcl %1 ; div1 %2, r0\n\t" \
  87. "rotcl %1 ; div1 %2, r0\n\t" \
  88. "rotcl %1 ; div1 %2, r0\n\t" \
  89. "rotcl %1 ; div1 %2, r0\n\t" \
  90. "" \
  91. "rotcl %1 ; div1 %2, r0\n\t" \
  92. "rotcl %1 ; div1 %2, r0\n\t" \
  93. "rotcl %1 ; div1 %2, r0\n\t" \
  94. "rotcl %1 ; div1 %2, r0\n\t" \
  95. "rotcl %1 ; div1 %2, r0\n\t" \
  96. "rotcl %1 ; div1 %2, r0\n\t" \
  97. "rotcl %1 ; div1 %2, r0\n\t" \
  98. "rotcl %1 ; div1 %2, r0\n\t" \
  99. "" \
  100. "rotcl %1 ; div1 %2, r0\n\t" \
  101. "rotcl %1 ; div1 %2, r0\n\t" \
  102. "rotcl %1 ; div1 %2, r0\n\t" \
  103. "rotcl %1 ; div1 %2, r0\n\t" \
  104. "rotcl %1 ; div1 %2, r0\n\t" \
  105. "rotcl %1 ; div1 %2, r0\n\t" \
  106. "rotcl %1 ; div1 %2, r0\n\t" \
  107. "rotcl %1 ; div1 %2, r0\n\t" \
  108. "" \
  109. "rotcl %1 ; div1 %2, r0\n\t" \
  110. "rotcl %1 ; div1 %2, r0\n\t" \
  111. "rotcl %1 ; div1 %2, r0\n\t" \
  112. "rotcl %1 ; div1 %2, r0\n\t" \
  113. "rotcl %1 ; div1 %2, r0\n\t" \
  114. "rotcl %1 ; div1 %2, r0\n\t" \
  115. "rotcl %1 ; div1 %2, r0\n\t" \
  116. "rotcl %1 ; div1 %2, r0\n\t" \
  117. "rotcl %1\n\t"
  118. : "=r" (res)
  119. : "0" (n), "r" (base)
  120. : "r0","cc");
  121. return n - (base * res);
  122. }
  123. #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
  124. /* 4096 bytes alignment */
  125. #define PAGE_ALIGN 0xfffff000
  126. #define ADDR_ALIGN 0xfff
  127. #define OFFS_ALIGN 0x7ffff000