ld_sysdep.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #undef 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_ARM_ABS32: \
  33. *REL += SYMBOL; \
  34. break; \
  35. case R_ARM_PC24: \
  36. { \
  37. unsigned long newval, topbits; \
  38. long addend=*REL & 0x00ffffff; \
  39. if(addend & 0x00800000) \
  40. addend|=0xff000000; \
  41. newval=SYMBOL- ((unsigned long)REL) + (addend<<2); \
  42. topbits=newval & 0xfe000000; \
  43. if (topbits != 0xfe000000 && topbits != 0x00000000) {/* \
  44. newval=fix_bad_pc24(REL,value) - \
  45. ((unsigned long)REL) + (addend << 2); \
  46. topbits=newval & 0xfe000000; \
  47. if(topbits != 0xfe000000 && topbits != 0x00000000)*/ \
  48. _dl_exit(1); \
  49. } \
  50. newval>>=2; \
  51. SYMBOL= (*REL & 0xff000000)|(newval & 0x00ffffff); \
  52. *REL=SYMBOL; \
  53. } \
  54. break; \
  55. case R_ARM_GLOB_DAT: \
  56. case R_ARM_JUMP_SLOT: \
  57. *REL = SYMBOL; \
  58. break; \
  59. case R_ARM_RELATIVE: \
  60. *REL += (unsigned long) LOAD; \
  61. break; \
  62. case R_ARM_NONE: \
  63. break; \
  64. default: \
  65. _dl_exit(1); \
  66. }
  67. /*
  68. * Transfer control to the user's application, once the dynamic loader
  69. * is done. This routine has to exit the current function, then
  70. * call the _dl_elf_main function.
  71. */
  72. #define START() return _dl_elf_main;
  73. /* Here we define the magic numbers that this dynamic loader should accept */
  74. #define MAGIC1 EM_ARM
  75. #undef MAGIC2
  76. /* Used for error messages */
  77. #define ELF_TARGET "ARM"
  78. struct elf_resolve;
  79. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  80. static inline unsigned long arm_modulus(unsigned long m, unsigned long p) {
  81. unsigned long i,t,inc;
  82. i=p; t=0;
  83. while(!(i&(1<<31))) {
  84. i<<=1;
  85. t++;
  86. }
  87. t--;
  88. for(inc=t;inc>2;inc--) {
  89. i=p<<inc;
  90. if(i&(1<<31))
  91. break;
  92. while(m>=i) {
  93. m-=i;
  94. i<<=1;
  95. if(i&(1<<31))
  96. break;
  97. if(i<p)
  98. break;
  99. }
  100. }
  101. while(m>=p) {
  102. m-=p;
  103. }
  104. return m;
  105. }
  106. #define do_rem(result, n, base) result=arm_modulus(n,base);