Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 9 | #ifndef TARGET_HEXAGON_HEXAGONPLT_H_ |
| 10 | #define TARGET_HEXAGON_HEXAGONPLT_H_ |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 11 | |
| 12 | #include "HexagonGOT.h" |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 13 | #include "HexagonGOTPLT.h" |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 14 | #include "mcld/Target/GOT.h" |
| 15 | #include "mcld/Target/PLT.h" |
| 16 | #include "mcld/Support/MemoryRegion.h" |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 17 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 18 | const uint8_t hexagon_plt0[] = { |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 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 |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 33 | const uint8_t hexagon_plt1[] = { |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 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 |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 40 | namespace mcld { |
| 41 | |
| 42 | class GOTEntry; |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 43 | class HexagonPLT1; |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 44 | class LinkerConfig; |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 45 | |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | // HexagonPLT Entry |
| 48 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 49 | class HexagonPLT0 : public PLT::Entry<sizeof(hexagon_plt0)> { |
| 50 | public: |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 51 | HexagonPLT0(SectionData& pParent); |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | // HexagonPLT |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | /** \class HexagonPLT |
| 58 | * \brief Hexagon Procedure Linkage Table |
| 59 | */ |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 60 | class HexagonPLT : public PLT { |
| 61 | public: |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 62 | HexagonPLT(LDSection& pSection, |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 63 | HexagonGOTPLT& pGOTPLT, |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 64 | const LinkerConfig& pConfig); |
| 65 | ~HexagonPLT(); |
| 66 | |
| 67 | // finalizeSectionSize - set LDSection size |
| 68 | void finalizeSectionSize(); |
| 69 | |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 70 | // hasPLT1 - return if this PLT has any PLT1 entry |
| 71 | bool hasPLT1() const; |
| 72 | |
Stephen Hines | 87f3465 | 2014-02-14 18:00:16 -0800 | [diff] [blame] | 73 | HexagonPLT1* create(); |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 74 | |
| 75 | void applyPLT0(); |
| 76 | |
| 77 | void applyPLT1(); |
| 78 | |
| 79 | uint64_t emit(MemoryRegion& pRegion); |
| 80 | |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 81 | PLTEntryBase* getPLT0() const; |
| 82 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 83 | private: |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 84 | HexagonGOTPLT& m_GOTPLT; |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 85 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 86 | const uint8_t* m_PLT0; |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 87 | unsigned int m_PLT0Size; |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 90 | class HexagonPLT1 : public PLT::Entry<sizeof(hexagon_plt1)> { |
| 91 | public: |
Stephen Hines | f7ac0f1 | 2013-05-03 19:09:24 -0700 | [diff] [blame] | 92 | HexagonPLT1(SectionData& pParent); |
| 93 | }; |
| 94 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 95 | } // namespace mcld |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 96 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 97 | #endif // TARGET_HEXAGON_HEXAGONPLT_H_ |