c67-link.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifdef TARGET_DEFS_ONLY
  2. #define EM_TCC_TARGET EM_C60
  3. /* relocation type for 32 bit data relocation */
  4. #define R_DATA_32 R_C60_32
  5. #define R_DATA_PTR R_C60_32
  6. #define R_JMP_SLOT R_C60_JMP_SLOT
  7. #define R_GLOB_DAT R_C60_GLOB_DAT
  8. #define R_COPY R_C60_COPY
  9. #define R_RELATIVE R_C60_RELATIVE
  10. #define R_NUM R_C60_NUM
  11. #define ELF_START_ADDR 0x00000400
  12. #define ELF_PAGE_SIZE 0x1000
  13. #define PCRELATIVE_DLLPLT 0
  14. #define RELOCATE_DLLPLT 0
  15. #else /* !TARGET_DEFS_ONLY */
  16. #include "tcc.h"
  17. /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
  18. relocations, returns -1. */
  19. int code_reloc (int reloc_type)
  20. {
  21. switch (reloc_type) {
  22. case R_C60_32:
  23. case R_C60LO16:
  24. case R_C60HI16:
  25. case R_C60_GOT32:
  26. case R_C60_GOTOFF:
  27. case R_C60_GOTPC:
  28. case R_C60_COPY:
  29. return 0;
  30. case R_C60_PLT32:
  31. return 1;
  32. }
  33. tcc_error ("Unknown relocation type: %d", reloc_type);
  34. return -1;
  35. }
  36. /* Returns an enumerator to describe whether and when the relocation needs a
  37. GOT and/or PLT entry to be created. See tcc.h for a description of the
  38. different values. */
  39. int gotplt_entry_type (int reloc_type)
  40. {
  41. switch (reloc_type) {
  42. case R_C60_32:
  43. case R_C60LO16:
  44. case R_C60HI16:
  45. case R_C60_COPY:
  46. return NO_GOTPLT_ENTRY;
  47. case R_C60_GOTOFF:
  48. case R_C60_GOTPC:
  49. return BUILD_GOT_ONLY;
  50. case R_C60_PLT32:
  51. case R_C60_GOT32:
  52. return ALWAYS_GOTPLT_ENTRY;
  53. }
  54. tcc_error ("Unknown relocation type: %d", reloc_type);
  55. return -1;
  56. }
  57. ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
  58. {
  59. tcc_error("C67 got not implemented");
  60. return 0;
  61. }
  62. /* relocate the PLT: compute addresses and offsets in the PLT now that final
  63. address for PLT and GOT are known (see fill_program_header) */
  64. ST_FUNC void relocate_plt(TCCState *s1)
  65. {
  66. uint8_t *p, *p_end;
  67. if (!s1->plt)
  68. return;
  69. p = s1->plt->data;
  70. p_end = p + s1->plt->data_offset;
  71. if (p < p_end) {
  72. /* XXX: TODO */
  73. while (p < p_end) {
  74. /* XXX: TODO */
  75. }
  76. }
  77. }
  78. void relocate_init(Section *sr) {}
  79. void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
  80. {
  81. switch(type) {
  82. case R_C60_32:
  83. *(int *)ptr += val;
  84. break;
  85. case R_C60LO16:
  86. {
  87. uint32_t orig;
  88. /* put the low 16 bits of the absolute address add to what is
  89. already there */
  90. orig = ((*(int *)(ptr )) >> 7) & 0xffff;
  91. orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16;
  92. /* patch both at once - assumes always in pairs Low - High */
  93. *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) |
  94. (((val+orig) & 0xffff) << 7);
  95. *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) |
  96. ((((val+orig)>>16) & 0xffff) << 7);
  97. }
  98. break;
  99. case R_C60HI16:
  100. break;
  101. default:
  102. fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
  103. type, (unsigned) addr, ptr, (unsigned) val);
  104. break;
  105. }
  106. }
  107. #endif /* !TARGET_DEFS_ONLY */