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