flat.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * include/asm-m32r/flat.h
  3. *
  4. * uClinux flat-format executables
  5. *
  6. * Copyright (C) 2004 Kazuhiro Inaoka
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive for
  10. * more details.
  11. */
  12. #ifndef __ASM_M32R_FLAT_H
  13. #define __ASM_M32R_FLAT_H
  14. #define flat_argvp_envp_on_stack() 0
  15. #define flat_old_ram_flag(flags) (flags)
  16. #define flat_set_persistent(relval, p) 0
  17. #define flat_reloc_valid(reloc, size) \
  18. (((reloc) - textlen_for_m32r_lo16_data) <= (size))
  19. #define flat_get_addr_from_rp(rp, relval, flags, persistent) \
  20. m32r_flat_get_addr_from_rp(rp, relval, (text_len) )
  21. #define flat_put_addr_at_rp(rp, addr, relval) \
  22. m32r_flat_put_addr_at_rp(rp, addr, relval)
  23. /* Convert a relocation entry into an address. */
  24. static inline unsigned long
  25. flat_get_relocate_addr (unsigned long relval)
  26. {
  27. return relval & 0x00ffffff; /* Mask out top 8-bits */
  28. }
  29. #define flat_m32r_get_reloc_type(relval) ((relval) >> 24)
  30. #define M32R_SETH_OPCODE 0xd0c00000 /* SETH instruction code */
  31. #define FLAT_M32R_32 0x00 /* 32bits reloc */
  32. #define FLAT_M32R_24 0x01 /* unsigned 24bits reloc */
  33. #define FLAT_M32R_16 0x02 /* 16bits reloc */
  34. #define FLAT_M32R_LO16 0x03 /* signed low 16bits reloc (low()) */
  35. #define FLAT_M32R_LO16_DATA 0x04 /* signed low 16bits reloc (low())
  36. for a symbol in .data section */
  37. /* High 16bits of an address used
  38. when the lower 16bbits are treated
  39. as unsigned.
  40. To create SETH instruction only.
  41. 0x1X: X means a number of register.
  42. 0x10 - 0x3F are reserved. */
  43. #define FLAT_M32R_HI16_ULO 0x10 /* reloc for SETH Rn,#high(imm16) */
  44. /* High 16bits of an address used
  45. when the lower 16bbits are treated
  46. as signed.
  47. To create SETH instruction only.
  48. 0x2X: X means a number of register.
  49. 0x20 - 0x4F are reserved. */
  50. #define FLAT_M32R_HI16_SLO 0x20 /* reloc for SETH Rn,#shigh(imm16) */
  51. static unsigned long textlen_for_m32r_lo16_data = 0;
  52. static inline unsigned long m32r_flat_get_addr_from_rp (unsigned long *rp,
  53. unsigned long relval,
  54. unsigned long textlen)
  55. {
  56. unsigned int reloc = flat_m32r_get_reloc_type (relval);
  57. textlen_for_m32r_lo16_data = 0;
  58. if (reloc & 0xf0) {
  59. unsigned long addr = htonl(*rp);
  60. switch (reloc & 0xf0)
  61. {
  62. case FLAT_M32R_HI16_ULO:
  63. case FLAT_M32R_HI16_SLO:
  64. if (addr == 0) {
  65. /* put "seth Rn,#0x0" instead of 0 (addr). */
  66. *rp = (M32R_SETH_OPCODE | ((reloc & 0x0f)<<24));
  67. }
  68. return addr;
  69. default:
  70. break;
  71. }
  72. } else {
  73. switch (reloc)
  74. {
  75. case FLAT_M32R_LO16:
  76. return htonl(*rp) & 0xFFFF;
  77. case FLAT_M32R_LO16_DATA:
  78. /* FIXME: The return value will decrease by textlen
  79. at m32r_flat_put_addr_at_rp () */
  80. textlen_for_m32r_lo16_data = textlen;
  81. return (htonl(*rp) & 0xFFFF) + textlen;
  82. case FLAT_M32R_16:
  83. return htons(*(unsigned short *)rp) & 0xFFFF;
  84. case FLAT_M32R_24:
  85. return htonl(*rp) & 0xFFFFFF;
  86. case FLAT_M32R_32:
  87. return htonl(*rp);
  88. default:
  89. break;
  90. }
  91. }
  92. return ~0; /* bogus value */
  93. }
  94. static inline void m32r_flat_put_addr_at_rp (unsigned long *rp,
  95. unsigned long addr,
  96. unsigned long relval)
  97. {
  98. unsigned int reloc = flat_m32r_get_reloc_type (relval);
  99. if (reloc & 0xf0) {
  100. unsigned long Rn = reloc & 0x0f; /* get a number of register */
  101. Rn <<= 24; /* 0x0R000000 */
  102. reloc &= 0xf0;
  103. switch (reloc)
  104. {
  105. case FLAT_M32R_HI16_ULO: /* To create SETH Rn,#high(imm16) */
  106. *rp = (M32R_SETH_OPCODE | Rn
  107. | ((addr >> 16) & 0xFFFF));
  108. break;
  109. case FLAT_M32R_HI16_SLO: /* To create SETH Rn,#shigh(imm16) */
  110. *rp = (M32R_SETH_OPCODE | Rn
  111. | (((addr >> 16) + ((addr & 0x8000) ? 1 : 0))
  112. & 0xFFFF));
  113. break;
  114. }
  115. } else {
  116. switch (reloc) {
  117. case FLAT_M32R_LO16_DATA:
  118. addr -= textlen_for_m32r_lo16_data;
  119. textlen_for_m32r_lo16_data = 0;
  120. case FLAT_M32R_LO16:
  121. *rp = (htonl(*rp) & 0xFFFF0000) | (addr & 0xFFFF);
  122. break;
  123. case FLAT_M32R_16:
  124. *(unsigned short *)rp = addr & 0xFFFF;
  125. break;
  126. case FLAT_M32R_24:
  127. *rp = (htonl(*rp) & 0xFF000000) | (addr & 0xFFFFFF);
  128. break;
  129. case FLAT_M32R_32:
  130. *rp = addr;
  131. break;
  132. }
  133. }
  134. }
  135. #endif /* __ASM_M32R_FLAT_H */