aboutsummaryrefslogtreecommitdiff
path: root/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h')
-rw-r--r--lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h b/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h
index 3e12786704a2..6af43d88afbb 100644
--- a/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h
+++ b/lib/ReaderWriter/ELF/Hexagon/HexagonEncodings.h
@@ -6,7 +6,27 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/ErrorHandling.h"
+
+namespace lld {
+namespace elf {
+
+/// \brief Applying fixup on Hexagon requires the relocator to fetch the fixup
+/// mask from the instruction. To fetch the fixup encoding, the linker uses a
+/// static array that contains the instruction mask, the compare mask and the
+/// relocation mask.
+typedef struct {
+ uint32_t insnMask; // Instruction mask.
+ uint32_t insnCmpMask; // Compare mask.
+ uint32_t insnBitMask; // Relocation mask.
+ bool isDuplex; // Indicates if the instruction is a duplex instruction.
+} Instruction;
+
Instruction insn_encodings[] = {
+ // InsnMask CompareMask BitMask IsDuplexInstruction
{ 0xffe00004, 0x40000000, 0x20f8, 0x0 },
{ 0xffe03080, 0x9ca03080, 0xf60, 0x0 },
{ 0xf9e00000, 0x48c00000, 0x61f20ff, 0x0 },
@@ -599,3 +619,20 @@ Instruction insn_encodings[] = {
{ 0xff602060, 0x3f000060, 0x1f80, 0x0 },
{ 0xf7c02000, 0x11000000, 0x3000fe, 0x0 },
};
+
+/// \brief finds the scatter Bits that need to be used to apply relocations
+inline uint32_t findv4bitmask(uint8_t *location) {
+ uint32_t insn = llvm::support::endian::read32le(location);
+ for (int32_t i = 0, e = llvm::array_lengthof(insn_encodings); i < e; i++) {
+ if ((insn & 0xc000) == 0 && !insn_encodings[i].isDuplex)
+ continue;
+ if ((insn & 0xc000) != 0 && insn_encodings[i].isDuplex)
+ continue;
+ if ((insn_encodings[i].insnMask & insn) == insn_encodings[i].insnCmpMask)
+ return insn_encodings[i].insnBitMask;
+ }
+ llvm_unreachable("found unknown Hexagon instruction");
+}
+
+} // namespace elf
+} // namespace lld