1//===- HexagonPLT.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_HEXAGONPLT_H_
10#define TARGET_HEXAGON_HEXAGONPLT_H_
11
12#include "HexagonGOT.h"
13#include "HexagonGOTPLT.h"
14#include "mcld/Target/GOT.h"
15#include "mcld/Target/PLT.h"
16#include "mcld/Support/MemoryRegion.h"
17
18const uint8_t hexagon_plt0[] = {
19    0x00, 0x40, 0x00, 0x00,  // { immext (#0)
20    0x1c, 0xc0, 0x49, 0x6a,  //   r28 = add (pc, ##GOT0@PCREL) } # address of GOT0   // NOLINT
21    0x0e, 0x42, 0x9c, 0xe2,  // { r14 -= add (r28, #16)   # offset of GOTn from GOTa // NOLINT
22    0x4f, 0x40, 0x9c, 0x91,  //   r15 = memw (r28 + #8)   # object ID at GOT2
23    0x3c, 0xc0, 0x9c, 0x91,  //   r28 = memw (r28 + #4) } # dynamic link at GOT1
24    0x0e, 0x42, 0x0e, 0x8c,  // { r14 = asr (r14, #2)     # index of PLTn
25    0x00, 0xc0, 0x9c, 0x52,  //   jumpr r28 }             # call dynamic linker
26    0x00, 0x00, 0x00, 0x00,
27    0x00, 0x00, 0x00, 0x00,
28    0x00, 0x00, 0x00, 0x00,
29    0x00, 0x00, 0x00, 0x00,
30    0x00, 0x00, 0x00, 0x00
31};
32
33const uint8_t hexagon_plt1[] = {
34    0x00, 0x40, 0x00, 0x00,  // { immext (#0)
35    0x0e, 0xc0, 0x49, 0x6a,  //   r14 = add (pc, ##GOTn@PCREL) } # address of GOTn  // NOLINT
36    0x1c, 0xc0, 0x8e, 0x91,  // r28 = memw (r14)                 # contents of GOTn // NOLINT
37    0x00, 0xc0, 0x9c, 0x52   // jumpr r28                        # call it
38};
39
40namespace mcld {
41
42class GOTEntry;
43class HexagonPLT1;
44class LinkerConfig;
45
46//===----------------------------------------------------------------------===//
47// HexagonPLT Entry
48//===----------------------------------------------------------------------===//
49class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)> {
50 public:
51  HexagonPLT0(SectionData& pParent);
52};
53
54//===----------------------------------------------------------------------===//
55// HexagonPLT
56//===----------------------------------------------------------------------===//
57/** \class HexagonPLT
58 *  \brief Hexagon Procedure Linkage Table
59 */
60class HexagonPLT : public PLT {
61 public:
62  HexagonPLT(LDSection& pSection,
63             HexagonGOTPLT& pGOTPLT,
64             const LinkerConfig& pConfig);
65  ~HexagonPLT();
66
67  // finalizeSectionSize - set LDSection size
68  void finalizeSectionSize();
69
70  // hasPLT1 - return if this PLT has any PLT1 entry
71  bool hasPLT1() const;
72
73  HexagonPLT1* create();
74
75  void applyPLT0();
76
77  void applyPLT1();
78
79  uint64_t emit(MemoryRegion& pRegion);
80
81  PLTEntryBase* getPLT0() const;
82
83 private:
84  HexagonGOTPLT& m_GOTPLT;
85
86  const uint8_t* m_PLT0;
87  unsigned int m_PLT0Size;
88};
89
90class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)> {
91 public:
92  HexagonPLT1(SectionData& pParent);
93};
94
95}  // namespace mcld
96
97#endif  // TARGET_HEXAGON_HEXAGONPLT_H_
98