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