dl-sysdep.h 3.4 KB

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