ld_sysdep.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. *(REL) = (SYMBOL) + (RELP)->r_addend; \
  38. break; \
  39. case R_SH_RELATIVE: \
  40. *(REL) = (LOAD) + (RELP)->r_addend; \
  41. break; \
  42. case R_SH_NONE: \
  43. break; \
  44. default: \
  45. SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc type "); \
  46. SEND_NUMBER_STDERR(ELF32_R_TYPE((RELP)->r_info), 1); \
  47. SEND_STDERR("REL, SYMBOL, LOAD: "); \
  48. SEND_ADDRESS_STDERR(REL, 0); \
  49. SEND_STDERR(", "); \
  50. SEND_ADDRESS_STDERR(SYMBOL, 0); \
  51. SEND_STDERR(", "); \
  52. SEND_ADDRESS_STDERR(LOAD, 1); \
  53. _dl_exit(1); \
  54. }
  55. /*
  56. * Transfer control to the user's application, once the dynamic loader
  57. * is done. This routine has to exit the current function, then
  58. * call the _dl_elf_main function.
  59. */
  60. #define START() return _dl_elf_main;
  61. /* Here we define the magic numbers that this dynamic loader should accept */
  62. #define MAGIC1 EM_SH
  63. #undef MAGIC2
  64. /* Used for error messages */
  65. #define ELF_TARGET "sh"
  66. struct elf_resolve;
  67. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  68. static __inline__ unsigned int
  69. _dl_urem(unsigned int n, unsigned int base)
  70. {
  71. register unsigned int __r0 __asm__ ("r0");
  72. register unsigned int __r4 __asm__ ("r4") = n;
  73. register unsigned int __r5 __asm__ ("r5") = base;
  74. __asm__ ("
  75. mov #0, r0
  76. div0u
  77. ! get one bit from the msb of the numerator into the T
  78. ! bit and divide it by whats in %2. Put the answer bit
  79. ! into the T bit so it can come out again at the bottom
  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 ; div1 r5, r0
  112. rotcl r4
  113. mov r4, r0
  114. "
  115. : "=r" (__r0)
  116. : "r" (__r4), "r" (__r5)
  117. : "r4", "cc");
  118. return n - (base * __r0);
  119. }
  120. #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
  121. /* 4096 bytes alignment */
  122. #define PAGE_ALIGN 0xfffff000
  123. #define ADDR_ALIGN 0xfff
  124. #define OFFS_ALIGN 0x7ffff000