dl-sysdep.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #define LINUXBIN
  6. /*
  7. * Define this if the system uses RELOCA.
  8. */
  9. #define ELF_USES_RELOCA
  10. /*
  11. * Get the address of the Global offset table. This must be absolute, not
  12. * relative.
  13. */
  14. #define GET_GOT(X) __asm__("\tmov %%l7,%0\n\t" : "=r" (X))
  15. /*
  16. * Get a pointer to the argv array. On many platforms this can be just
  17. * the address if the first argument, on other platforms we need to
  18. * do something a little more subtle here. We assume that argc is stored
  19. * at the word just below the argvp that we return here.
  20. */
  21. #define GET_ARGV(ARGVP, ARGS) __asm__("\tadd %%fp,68,%0\n" : "=r" (ARGVP));
  22. /*
  23. * Initialization sequence for a GOT. For the Sparc, this points to the
  24. * PLT, and we need to initialize a couple of the slots. The PLT should
  25. * look like:
  26. *
  27. * save %sp, -64, %sp
  28. * call _dl_linux_resolve
  29. * nop
  30. * .word implementation_dependent
  31. */
  32. #define INIT_GOT(GOT_BASE,MODULE) \
  33. { \
  34. GOT_BASE[0] = 0x9de3bfc0; /* save %sp, -64, %sp */ \
  35. GOT_BASE[1] = 0x40000000 | (((unsigned int) _dl_linux_resolve - (unsigned int) GOT_BASE - 4) >> 2); \
  36. GOT_BASE[2] = 0x01000000; /* nop */ \
  37. GOT_BASE[3] = (int) MODULE; \
  38. }
  39. /*
  40. * Here is a macro to perform a relocation. This is only used when
  41. * bootstrapping the dynamic loader.
  42. */
  43. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \
  44. switch(ELF32_R_TYPE((RELP)->r_info)) { \
  45. case R_SPARC_32: \
  46. *REL = SYMBOL + (RELP)->r_addend; \
  47. break; \
  48. case R_SPARC_GLOB_DAT: \
  49. *REL = SYMBOL + (RELP)->r_addend; \
  50. break; \
  51. case R_SPARC_JMP_SLOT: \
  52. REL[1] = 0x03000000 | ((SYMBOL >> 10) & 0x3fffff); \
  53. REL[2] = 0x81c06000 | (SYMBOL & 0x3ff); \
  54. break; \
  55. case R_SPARC_NONE: \
  56. break; \
  57. case R_SPARC_WDISP30: \
  58. break; \
  59. case R_SPARC_RELATIVE: \
  60. *REL += (unsigned int) LOAD + (RELP)->r_addend; \
  61. break; \
  62. default: \
  63. _dl_exit(1); \
  64. }
  65. /*
  66. * Transfer control to the user's application, once the dynamic loader
  67. * is done. The crt calls atexit with $g1 if not null, so we need to
  68. * ensure that it contains NULL.
  69. */
  70. #define START() \
  71. __asm__ volatile ( \
  72. "add %%g0,%%g0,%%g1\n\t" \
  73. "jmpl %0, %%o7\n\t" \
  74. "restore %%g0,%%g0,%%g0\n\t" \
  75. : /*"=r" (status) */ : \
  76. "r" (_dl_elf_main): "g1", "o0", "o1")
  77. /* Here we define the magic numbers that this dynamic loader should accept */
  78. #define MAGIC1 EM_SPARC
  79. #undef MAGIC2
  80. /* Used for error messages */
  81. #define ELF_TARGET "Sparc"
  82. #ifndef COMPILE_ASM
  83. extern unsigned int _dl_linux_resolver(unsigned int reloc_entry,
  84. unsigned int * i);
  85. #endif
  86. /*
  87. * Define this if you want a dynamic loader that works on Solaris.
  88. */
  89. #define SOLARIS_COMPATIBLE
  90. /*
  91. * Define this because we do not want to call .udiv in the library.
  92. * Change on the plans -miguel:
  93. * We just statically link against .udiv. This is required
  94. * if we want to be able to run on Sun4c machines.
  95. */
  96. /* We now link .urem against this one */
  97. #ifdef USE_V8
  98. #define do_rem(result,n,base) ({ \
  99. volatile int __res; \
  100. __asm__("mov %%g0,%%Y\n\t" \
  101. "sdiv %2,%3,%%l6\n\t" \
  102. "smul %%l6,%3,%%l6\n\t" \
  103. "sub %2,%%l6,%0\n\t" \
  104. :"=r" (result),"=r" (__res):"r" (n),"r"(base) : "l6" ); __res; })
  105. #else
  106. #define do_rem(a,b,c) a = _dl_urem (b,c);
  107. #endif
  108. /*
  109. * dbx wants the binder to have a specific name. Mustn't disappoint it.
  110. */
  111. #ifdef SOLARIS_COMPATIBLE
  112. #define _dl_linux_resolve _elf_rtbndr
  113. #endif