summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/Hexagon/HexagonRelocationFunctions.h
blob: 8df0c8aee2eb8f23e88427d1857de0538fca9fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===- HexagonRelocationFunction.h ----------------------------------------===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_FUNCTIONS_H
#define LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_FUNCTIONS_H

namespace lld {
namespace elf {

/// \brief HexagonInstruction which is used to store various values
typedef struct {
	const char *insnSyntax;
	uint32_t insnMask;
	uint32_t insnCmpMask;
	uint32_t insnBitMask;
        bool isDuplex;
} Instruction;

#include "HexagonV4Encodings.h"

#define FINDV4BITMASK(INSN) findBitMask(*((uint32_t *)INSN), \
                            insn_encodings_v4, \
                            sizeof(insn_encodings_v4)/sizeof(Instruction))

/// \brief finds the scatter Bits that need to be used to apply relocations
uint32_t findBitMask(uint32_t insn, Instruction *encodings, int32_t numInsns) {
  for (int32_t i = 0; i < numInsns ; i++) {
    if (((insn & 0xc000) == 0) && !(encodings[i].isDuplex))
      continue;

    if (((insn & 0xc000) != 0) && (encodings[i].isDuplex))
      continue;

    if (((encodings[i].insnMask) & insn) == encodings[i].insnCmpMask) 
      return encodings[i].insnBitMask;
  }
  assert(0 && "found unknown instruction");
}

} // elf 
} // lld

#endif // LLD_READER_WRITER_ELF_HEXAGON_RELOCATION_FUNCTIONS_H
OpenPOWER on IntegriCloud