1//===- HexagonRelocationFunction.h ----------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9typedef struct {
10  const char *insnSyntax;
11  uint32_t insnMask;
12  uint32_t insnCmpMask;
13  uint32_t insnBitMask;
14  bool isDuplex;
15} Instruction;
16
17//===--------------------------------------------------------------------===//
18// Relocation helper function
19//===--------------------------------------------------------------------===//
20template<typename T1, typename T2>
21T1 ApplyMask(T2 pMask, T1 pData) {
22  T1 result = 0;
23  size_t off = 0;
24
25  for (size_t bit = 0; bit != sizeof (T1) * 8; ++bit) {
26    const bool valBit = (pData >> off) & 1;
27    const bool maskBit = (pMask >> bit) & 1;
28    if (maskBit) {
29      result |= static_cast<T1>(valBit) << bit;
30      ++off;
31    }
32  }
33  return result;
34}
35
36#define DECL_HEXAGON_APPLY_RELOC_FUNC(Name) \
37static HexagonRelocator::Result Name    (Relocation& pEntry, \
38                                     HexagonRelocator& pParent);
39
40#define DECL_HEXAGON_APPLY_RELOC_FUNCS \
41DECL_HEXAGON_APPLY_RELOC_FUNC(none)             \
42DECL_HEXAGON_APPLY_RELOC_FUNC(relocPCREL)     \
43DECL_HEXAGON_APPLY_RELOC_FUNC(relocGPREL)     \
44DECL_HEXAGON_APPLY_RELOC_FUNC(relocAbs)     \
45DECL_HEXAGON_APPLY_RELOC_FUNC(relocPLTB22PCREL)  \
46DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOTREL)  \
47DECL_HEXAGON_APPLY_RELOC_FUNC(relocGOT)  \
48DECL_HEXAGON_APPLY_RELOC_FUNC(unsupport)
49
50#define DECL_HEXAGON_APPLY_RELOC_FUNC_PTRS \
51  { &none,                0, "R_HEX_NONE"                        }, \
52  { &relocPCREL,          1, "R_HEX_B22_PCREL"                   }, \
53  { &relocPCREL,          2, "R_HEX_B15_PCREL"                   }, \
54  { &relocPCREL,          3, "R_HEX_B7_PCREL"                    }, \
55  { &relocAbs,            4, "R_HEX_LO16"                        }, \
56  { &relocAbs,            5, "R_HEX_HI16"                        }, \
57  { &relocAbs,            6, "R_HEX_32"                          }, \
58  { &relocAbs,            7, "R_HEX_16"                          }, \
59  { &relocAbs,            8, "R_HEX_8"                           }, \
60  { &relocGPREL,          9, "R_HEX_GPREL16_0"                   }, \
61  { &relocGPREL,          10, "R_HEX_GPREL16_1"                  }, \
62  { &relocGPREL,          11, "R_HEX_GPREL16_2"                  }, \
63  { &relocGPREL,          12, "R_HEX_GPREL16_3"                  }, \
64  { &unsupport,           13, "R_HEX_HL16"                       }, \
65  { &relocPCREL,          14, "R_HEX_B13_PCREL"                  }, \
66  { &relocPCREL,          15, "R_HEX_B9_PCREL"                   }, \
67  { &relocPCREL,          16, "R_HEX_B32_PCREL_X"                }, \
68  { &relocAbs,            17, "R_HEX_32_6_X"                     }, \
69  { &relocPCREL,          18, "R_HEX_B22_PCREL_X"                }, \
70  { &relocPCREL,          19, "R_HEX_B15_PCREL_X"                }, \
71  { &relocPCREL,          20, "R_HEX_B13_PCREL_X"                }, \
72  { &relocPCREL,          21, "R_HEX_B9_PCREL_X"                 }, \
73  { &relocPCREL,          22, "R_HEX_B7_PCREL_X"                 }, \
74  { &relocAbs,            23, "R_HEX_16_X"                       }, \
75  { &relocAbs,            24, "R_HEX_12_X"                       }, \
76  { &relocAbs,            25, "R_HEX_11_X"                       }, \
77  { &relocAbs,            26, "R_HEX_10_X"                       }, \
78  { &relocAbs,            27, "R_HEX_9_X"                        }, \
79  { &relocAbs,            28, "R_HEX_8_X"                        }, \
80  { &relocAbs,            29, "R_HEX_7_X"                        }, \
81  { &relocAbs,            30, "R_HEX_6_X"                        }, \
82  { &relocPCREL,          31, "R_HEX_32_PCREL"                   }, \
83  { &none,                32, "R_HEX_COPY"                       }, \
84  { &none,                33, "R_HEX_GLOB_DAT"                   }, \
85  { &none,                34, "R_HEX_JMP_SLOT"                   }, \
86  { &none,                35, "R_HEX_RELATIVE"                   }, \
87  { &relocPLTB22PCREL,    36, "R_HEX_PLT_B22_PCREL"              }, \
88  { &relocGOTREL,         37, "R_HEX_GOTREL_LO16"                }, \
89  { &relocGOTREL,         38, "R_HEX_GOTREL_HI16"                }, \
90  { &relocGOTREL,         39, "R_HEX_GOTREL_32"                  }, \
91  { &relocGOT,            40, "R_HEX_GOT_LO16"                   }, \
92  { &relocGOT,            41, "R_HEX_GOT_HI16"                   }, \
93  { &relocGOT,            42, "R_HEX_GOT_32"                     }, \
94  { &relocGOT,            43, "R_HEX_GOT_16"                     }, \
95  { &unsupport,           44, "R_HEX_DTPMOD_32"                  }, \
96  { &unsupport,           45, "R_HEX_DTPREL_LO16"                }, \
97  { &unsupport,           46, "R_HEX_DTPREL_HI16"                }, \
98  { &unsupport,           47, "R_HEX_DTPREL_32"                  }, \
99  { &unsupport,           48, "R_HEX_DTPREL_16"                  }, \
100  { &unsupport,           49, "R_HEX_GD_PLT_B22_PCREL"           }, \
101  { &unsupport,           50, "R_HEX_GD_GOT_LO16"                }, \
102  { &unsupport,           51, "R_HEX_GD_GOT_HI16"                }, \
103  { &unsupport,           52, "R_HEX_GD_GOT_32"                  }, \
104  { &unsupport,           53, "R_HEX_GD_GOT_16"                  }, \
105  { &unsupport,           54, "R_HEX_IE_LO16"                    }, \
106  { &unsupport,           55, "R_HEX_IE_HI16"                    }, \
107  { &unsupport,           56, "R_HEX_IE_32"                      }, \
108  { &unsupport,           57, "R_HEX_IE_GOT_LO16"                }, \
109  { &unsupport,           58, "R_HEX_IE_GOT_HI16"                }, \
110  { &unsupport,           59, "R_HEX_IE_GOT_32"                  }, \
111  { &unsupport,           60, "R_HEX_IE_GOT_16"                  }, \
112  { &unsupport,           61, "R_HEX_TPREL_LO16"                 }, \
113  { &unsupport,           62, "R_HEX_TPREL_HI16"                 }, \
114  { &unsupport,           63, "R_HEX_TPREL_32"                   }, \
115  { &unsupport,           64, "R_HEX_TPREL_16"                   }, \
116  { &relocPCREL,          65, "R_HEX_6_PCREL_X"                  }, \
117  { &relocGOTREL,         66, "R_HEX_GOTREL_32_6_X"              }, \
118  { &relocGOTREL,         67, "R_HEX_GOTREL_16_X"                }, \
119  { &relocGOTREL,         68, "R_HEX_GOTREL_11_X"                }, \
120  { &relocGOT,            69, "R_HEX_GOT_32_6_X"                 }, \
121  { &relocGOT,            70, "R_HEX_GOT_16_X"                   }, \
122  { &relocGOT,            71, "R_HEX_GOT_11_X"                   }, \
123  { &unsupport,           72, "R_HEX_DTPREL_32_6_X"              }, \
124  { &unsupport,           73, "R_HEX_DTPREL_16_X"                }, \
125  { &unsupport,           74, "R_HEX_DTPREL_11_X"                }, \
126  { &unsupport,           75, "R_HEX_GD_GOT_32_6_X"              }, \
127  { &unsupport,           76, "R_HEX_GD_GOT_16_X"                }, \
128  { &unsupport,           77, "R_HEX_GD_GOT_11_X"                }, \
129  { &unsupport,           78, "R_HEX_IE_32_6_X"                  }, \
130  { &unsupport,           79, "R_HEX_IE_16_X"                    }, \
131  { &unsupport,           80, "R_HEX_IE_GOT_32_6_X"              }, \
132  { &unsupport,           81, "R_HEX_IE_GOT_16_X"                }, \
133  { &unsupport,           82, "R_HEX_IE_GOT_11_X"                }, \
134  { &unsupport,           83, "R_HEX_TPREL_32_6_X"               }, \
135  { &unsupport,           84, "R_HEX_TPREL_16_X"                 }, \
136  { &unsupport,           85, "R_HEX_TPREL_11_X"                 }
137