1
0

0001-lm32-add-support-for-architecture.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From f5d1ee11dfc74dba39110cbefde93c53ae1cf3df Mon Sep 17 00:00:00 2001
  2. From: Waldemar Brodkorb <wbx@openadk.org>
  3. Date: Sat, 19 Mar 2016 18:35:06 +0100
  4. Subject: [PATCH] lm32: add support for architecture
  5. Add lm32 support patch from:
  6. https://github.com/m-labs/elf2flt-lm32
  7. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  8. ---
  9. elf2flt.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
  10. 1 file changed, 102 insertions(+), 1 deletion(-)
  11. diff --git a/elf2flt.c b/elf2flt.c
  12. index 7d0e639..3b59b92 100644
  13. --- a/elf2flt.c
  14. +++ b/elf2flt.c
  15. @@ -62,6 +62,8 @@ const char *elf2flt_progname;
  16. #include "cygwin-elf.h" /* Cygwin uses a local copy */
  17. #elif defined(TARGET_xtensa)
  18. #include <elf/xtensa.h> /* TARGET_* ELF support for the BFD library */
  19. +#elif defined(TARGET_lm32)
  20. +#include <elf/lm32.h>
  21. #elif defined(TARGET_microblaze)
  22. #include <elf/microblaze.h> /* TARGET_* ELF support for the BFD library */
  23. #elif defined(TARGET_v850)
  24. @@ -115,6 +117,11 @@ const char *elf2flt_progname;
  25. #define ARCH "nios"
  26. #elif defined(TARGET_nios2)
  27. #define ARCH "nios2"
  28. +#elif defined(TARGET_lm32)
  29. +#define ARCH "lm32"
  30. +#define FLAT_LM32_RELOC_TYPE_32_BIT 0
  31. +#define FLAT_LM32_RELOC_TYPE_HI16_BIT 1
  32. +#define FLAT_LM32_RELOC_TYPE_LO16_BIT 2
  33. #elif defined(TARGET_xtensa)
  34. #define ARCH "xtensa"
  35. #else
  36. @@ -345,7 +352,7 @@ output_relocs (
  37. int bad_relocs = 0;
  38. asymbol **symb;
  39. long nsymb;
  40. -#ifdef TARGET_bfin
  41. +#if defined (TARGET_bfin) || defined (TARGET_lm32)
  42. unsigned long persistent_data = 0;
  43. #endif
  44. @@ -669,6 +676,36 @@ dump_symbols(symbols, number_of_symbols);
  45. break;
  46. default:
  47. goto bad_resolved_reloc;
  48. +#elif defined(TARGET_lm32)
  49. + case R_LM32_HI16:
  50. + case R_LM32_LO16:
  51. + if (q->howto->type == R_LM32_HI16) {
  52. + pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29;
  53. + } else {
  54. + pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29;
  55. + }
  56. +
  57. + relocation_needed = 1;
  58. +
  59. + /* remember the upper 16 bits */
  60. + if ((0xffff0000 & sym_addr) != persistent_data) {
  61. + flat_relocs = (uint32_t *)
  62. + (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t)));
  63. + if (verbose)
  64. + printf ("New persistent data for %08lx\n", sym_addr);
  65. + persistent_data = 0xffff0000 & sym_addr;
  66. + flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29);
  67. + }
  68. + break;
  69. + case R_LM32_32:
  70. + pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29;
  71. + relocation_needed = 1;
  72. + break;
  73. + case R_LM32_CALL:
  74. + relocation_needed = 0;
  75. + break;
  76. + default:
  77. + goto bad_resolved_reloc;
  78. #elif defined(TARGET_m68k)
  79. case R_68K_32:
  80. goto good_32bit_resolved_reloc;
  81. @@ -1447,6 +1484,63 @@ DIS29_RELOCATION:
  82. #undef _30BITS_RELOC
  83. #undef _28BITS_RELOC
  84. #endif
  85. +#ifdef TARGET_lm32
  86. + case R_LM32_32:
  87. + {
  88. + pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29;
  89. + sym_vma = bfd_section_vma(abs_bfd, sym_section);
  90. + sym_addr += sym_vma + q->addend;
  91. + relocation_needed = 1;
  92. + break;
  93. + }
  94. + case R_LM32_CALL:
  95. + {
  96. + sym_vma = 0;
  97. + sym_addr += sym_vma + q->addend;
  98. + sym_addr -= q->address;
  99. + sym_addr = (int32_t)sym_addr >> q->howto->rightshift;
  100. +
  101. + if ((int32_t)sym_addr < -0x8000000 || (int32_t)sym_addr > 0x7ffffff) {
  102. + printf("ERROR: Relocation overflow for R_LM32_CALL relocation against %s\n", sym_name);
  103. + bad_relocs++;
  104. + continue;
  105. + }
  106. +
  107. + r_mem[0] |= (sym_addr >> 24) & 0x03;
  108. + r_mem[1] = (sym_addr >> 16) & 0xff;
  109. + r_mem[2] = (sym_addr >> 8) & 0xff;
  110. + r_mem[3] = sym_addr & 0xff;
  111. + break;
  112. + }
  113. + case R_LM32_HI16:
  114. + case R_LM32_LO16:
  115. + {
  116. + if (q->howto->type == R_LM32_HI16) {
  117. + pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29;
  118. + } else {
  119. + pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29;
  120. + }
  121. +
  122. + sym_vma = bfd_section_vma(abs_bfd, sym_section);
  123. + sym_addr += sym_vma + q->addend;
  124. +
  125. + relocation_needed = 1;
  126. +
  127. + /* remember the upper 16 bits */
  128. + if ((0xffff0000 & sym_addr) != persistent_data) {
  129. + flat_relocs = (uint32_t *)
  130. + (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t)));
  131. + if (verbose)
  132. + printf ("New persistent data for %08lx\n", sym_addr);
  133. + persistent_data = 0xffff0000 & sym_addr;
  134. + flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29);
  135. + }
  136. +
  137. + r_mem[2] = (sym_addr >> 8) & 0xff;
  138. + r_mem[3] = sym_addr & 0xff;
  139. + break;
  140. + }
  141. +#endif /* TARGET_lm32 */
  142. default:
  143. /* missing support for other types of relocs */
  144. printf("ERROR: bad reloc type %d\n", (*p)->howto->type);
  145. @@ -1584,6 +1678,13 @@ DIS29_RELOCATION:
  146. break;
  147. #endif
  148. +#ifdef TARGET_lm32
  149. + case R_LM32_HI16:
  150. + case R_LM32_LO16:
  151. + case R_LM32_CALL:
  152. + /* entry has already been written */
  153. + break;
  154. +#endif
  155. default:
  156. /* The alignment of the build host
  157. might be stricter than that of the
  158. --
  159. 2.1.4