0001-lm32.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c
  2. --- elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.c 2017-09-27 06:06:04.000000000 +0200
  3. +++ elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.c 2017-09-27 06:07:51.032597579 +0200
  4. @@ -61,6 +61,8 @@
  5. #include <elf/bfin.h>
  6. #elif defined(TARGET_h8300)
  7. #include <elf/h8.h>
  8. +#elif defined(TARGET_lm32)
  9. +#include <elf/lm32.h>
  10. #elif defined(TARGET_m68k)
  11. #include <elf/m68k.h>
  12. #elif defined(TARGET_microblaze)
  13. @@ -120,6 +122,11 @@
  14. #define ARCH "nios"
  15. #elif defined(TARGET_nios2)
  16. #define ARCH "nios2"
  17. +#elif defined(TARGET_lm32)
  18. +#define ARCH "lm32"
  19. +#define FLAT_LM32_RELOC_TYPE_32_BIT 0
  20. +#define FLAT_LM32_RELOC_TYPE_HI16_BIT 1
  21. +#define FLAT_LM32_RELOC_TYPE_LO16_BIT 2
  22. #elif defined(TARGET_xtensa)
  23. #define ARCH "xtensa"
  24. #else
  25. @@ -357,7 +364,7 @@
  26. int bad_relocs = 0;
  27. asymbol **symb;
  28. long nsymb;
  29. -#ifdef TARGET_bfin
  30. +#if defined (TARGET_bfin) || defined (TARGET_lm32)
  31. unsigned long persistent_data = 0;
  32. #endif
  33. @@ -682,6 +689,36 @@
  34. break;
  35. default:
  36. goto bad_resolved_reloc;
  37. +#elif defined(TARGET_lm32)
  38. + case R_LM32_HI16:
  39. + case R_LM32_LO16:
  40. + if (q->howto->type == R_LM32_HI16) {
  41. + pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29;
  42. + } else {
  43. + pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29;
  44. + }
  45. +
  46. + relocation_needed = 1;
  47. +
  48. + /* remember the upper 16 bits */
  49. + if ((0xffff0000 & sym_addr) != persistent_data) {
  50. + flat_relocs = (uint32_t *)
  51. + (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t)));
  52. + if (verbose)
  53. + printf ("New persistent data for %08lx\n", sym_addr);
  54. + persistent_data = 0xffff0000 & sym_addr;
  55. + flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29);
  56. + }
  57. + break;
  58. + case R_LM32_32:
  59. + pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29;
  60. + relocation_needed = 1;
  61. + break;
  62. + case R_LM32_CALL:
  63. + relocation_needed = 0;
  64. + break;
  65. + default:
  66. + goto bad_resolved_reloc;
  67. #elif defined(TARGET_m68k)
  68. case R_68K_32:
  69. goto good_32bit_resolved_reloc;
  70. @@ -1459,6 +1496,63 @@
  71. #undef _30BITS_RELOC
  72. #undef _28BITS_RELOC
  73. #endif
  74. +#ifdef TARGET_lm32
  75. + case R_LM32_32:
  76. + {
  77. + pflags = FLAT_LM32_RELOC_TYPE_32_BIT << 29;
  78. + sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
  79. + sym_addr += sym_vma + q->addend;
  80. + relocation_needed = 1;
  81. + break;
  82. + }
  83. + case R_LM32_CALL:
  84. + {
  85. + sym_vma = 0;
  86. + sym_addr += sym_vma + q->addend;
  87. + sym_addr -= q->address;
  88. + sym_addr = (int32_t)sym_addr >> q->howto->rightshift;
  89. +
  90. + if ((int32_t)sym_addr < -0x8000000 || (int32_t)sym_addr > 0x7ffffff) {
  91. + printf("ERROR: Relocation overflow for R_LM32_CALL relocation against %s\n", sym_name);
  92. + bad_relocs++;
  93. + continue;
  94. + }
  95. +
  96. + r_mem[0] |= (sym_addr >> 24) & 0x03;
  97. + r_mem[1] = (sym_addr >> 16) & 0xff;
  98. + r_mem[2] = (sym_addr >> 8) & 0xff;
  99. + r_mem[3] = sym_addr & 0xff;
  100. + break;
  101. + }
  102. + case R_LM32_HI16:
  103. + case R_LM32_LO16:
  104. + {
  105. + if (q->howto->type == R_LM32_HI16) {
  106. + pflags = FLAT_LM32_RELOC_TYPE_HI16_BIT << 29;
  107. + } else {
  108. + pflags = FLAT_LM32_RELOC_TYPE_LO16_BIT << 29;
  109. + }
  110. +
  111. + sym_vma = elf2flt_bfd_section_vma(abs_bfd, sym_section);
  112. + sym_addr += sym_vma + q->addend;
  113. +
  114. + relocation_needed = 1;
  115. +
  116. + /* remember the upper 16 bits */
  117. + if ((0xffff0000 & sym_addr) != persistent_data) {
  118. + flat_relocs = (uint32_t *)
  119. + (realloc (flat_relocs, (flat_reloc_count + 1) * sizeof (uint32_t)));
  120. + if (verbose)
  121. + printf ("New persistent data for %08lx\n", sym_addr);
  122. + persistent_data = 0xffff0000 & sym_addr;
  123. + flat_relocs[flat_reloc_count++] = (sym_addr >> 16) | (3 << 29);
  124. + }
  125. +
  126. + r_mem[2] = (sym_addr >> 8) & 0xff;
  127. + r_mem[3] = sym_addr & 0xff;
  128. + break;
  129. + }
  130. +#endif /* TARGET_lm32 */
  131. default:
  132. /* missing support for other types of relocs */
  133. printf("ERROR: bad reloc type %d\n", (*p)->howto->type);
  134. @@ -1596,6 +1690,13 @@
  135. break;
  136. #endif
  137. +#ifdef TARGET_lm32
  138. + case R_LM32_HI16:
  139. + case R_LM32_LO16:
  140. + case R_LM32_CALL:
  141. + /* entry has already been written */
  142. + break;
  143. +#endif
  144. default:
  145. /* The alignment of the build host
  146. might be stricter than that of the
  147. diff -Nur elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.ld.in elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.ld.in
  148. --- elf2flt-6d80ab6c93409e796f85da404bde84b841231531.orig/elf2flt.ld.in 2017-09-27 06:06:04.000000000 +0200
  149. +++ elf2flt-6d80ab6c93409e796f85da404bde84b841231531/elf2flt.ld.in 2017-09-29 18:11:30.999698955 +0200
  150. @@ -34,6 +34,7 @@
  151. W_RODAT *(.rodata1)
  152. W_RODAT *(.rodata.*)
  153. W_RODAT *(.gnu.linkonce.r*)
  154. +W_RODAT *(.rofixup)
  155. /* .ARM.extab name sections containing exception unwinding information */
  156. *(.ARM.extab* .gnu.linkonce.armextab.*)