blob: e271a1e6fe77206962b5509cd45484411061470d [file] [log] [blame]
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +00001//===--- ARMWinEHPrinter.h - Windows on ARM Unwind Information Printer ----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000010#ifndef LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
11#define LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000012
Saleem Abdulrasoolfbb7c202014-06-04 16:03:18 +000013#include "llvm/Object/COFF.h"
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000014#include "llvm/Support/ErrorOr.h"
Zachary Turner2448e9f2016-05-03 00:28:04 +000015#include "llvm/Support/ScopedPrinter.h"
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000016
17namespace llvm {
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000018namespace ARM {
19namespace WinEH {
20class RuntimeFunction;
21
22class Decoder {
23 static const size_t PDataEntrySize;
24
Zachary Turner2448e9f2016-05-03 00:28:04 +000025 ScopedPrinter &SW;
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000026 raw_ostream &OS;
Sanjin Sijarice10866a2018-10-24 00:03:34 +000027 bool isAArch64;
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000028
29 struct RingEntry {
30 uint8_t Mask;
31 uint8_t Value;
Sanjin Sijarice10866a2018-10-24 00:03:34 +000032 uint8_t Length;
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000033 bool (Decoder::*Routine)(const uint8_t *, unsigned &, unsigned, bool);
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000034 };
35 static const RingEntry Ring[];
Sanjin Sijarice10866a2018-10-24 00:03:34 +000036 static const RingEntry Ring64[];
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000037
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000038 bool opcode_0xxxxxxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000039 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000040 bool opcode_10Lxxxxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000041 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000042 bool opcode_1100xxxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000043 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000044 bool opcode_11010Lxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000045 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000046 bool opcode_11011Lxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000047 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000048 bool opcode_11100xxx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000049 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000050 bool opcode_111010xx(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000051 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000052 bool opcode_1110110L(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000053 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000054 bool opcode_11101110(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000055 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000056 bool opcode_11101111(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000057 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000058 bool opcode_11110101(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000059 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000060 bool opcode_11110110(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000061 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000062 bool opcode_11110111(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000063 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000064 bool opcode_11111000(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000065 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000066 bool opcode_11111001(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000067 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000068 bool opcode_11111010(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000069 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000070 bool opcode_11111011(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000071 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000072 bool opcode_11111100(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000073 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000074 bool opcode_11111101(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000075 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000076 bool opcode_11111110(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000077 unsigned Length, bool Prologue);
Rui Ueyamaf70f3d42014-09-11 21:46:33 +000078 bool opcode_11111111(const uint8_t *Opcodes, unsigned &Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +000079 unsigned Length, bool Prologue);
80
Sanjin Sijarice10866a2018-10-24 00:03:34 +000081 // ARM64 unwind codes start here.
82 bool opcode_alloc_s(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
83 bool Prologue);
84 bool opcode_save_r19r20_x(const uint8_t *Opcodes, unsigned &Offset,
85 unsigned Length, bool Prologue);
86 bool opcode_save_fplr(const uint8_t *Opcodes, unsigned &Offset,
87 unsigned Length, bool Prologue);
88 bool opcode_save_fplr_x(const uint8_t *Opcodes, unsigned &Offset,
89 unsigned Length, bool Prologue);
90 bool opcode_alloc_m(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
91 bool Prologue);
92 bool opcode_save_regp(const uint8_t *Opcodes, unsigned &Offset,
93 unsigned Length, bool Prologue);
94 bool opcode_save_regp_x(const uint8_t *Opcodes, unsigned &Offset,
95 unsigned Length, bool Prologue);
96 bool opcode_save_reg(const uint8_t *Opcodes, unsigned &Offset,
97 unsigned Length, bool Prologue);
98 bool opcode_save_reg_x(const uint8_t *Opcodes, unsigned &Offset,
99 unsigned Length, bool Prologue);
100 bool opcode_save_lrpair(const uint8_t *Opcodes, unsigned &Offset,
101 unsigned Length, bool Prologue);
102 bool opcode_save_fregp(const uint8_t *Opcodes, unsigned &Offset,
103 unsigned Length, bool Prologue);
104 bool opcode_save_fregp_x(const uint8_t *Opcodes, unsigned &Offset,
105 unsigned Length, bool Prologue);
106 bool opcode_save_freg(const uint8_t *Opcodes, unsigned &Offset,
107 unsigned Length, bool Prologue);
108 bool opcode_save_freg_x(const uint8_t *Opcodes, unsigned &Offset,
109 unsigned Length, bool Prologue);
110 bool opcode_alloc_l(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
111 bool Prologue);
112 bool opcode_setfp(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
113 bool Prologue);
114 bool opcode_addfp(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
115 bool Prologue);
116 bool opcode_nop(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
117 bool Prologue);
118 bool opcode_end(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
119 bool Prologue);
120 bool opcode_end_c(const uint8_t *Opcodes, unsigned &Offset, unsigned Length,
121 bool Prologue);
122 bool opcode_save_next(const uint8_t *Opcodes, unsigned &Offset,
123 unsigned Length, bool Prologue);
124
Rui Ueyamaf70f3d42014-09-11 21:46:33 +0000125 void decodeOpcodes(ArrayRef<uint8_t> Opcodes, unsigned Offset,
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +0000126 bool Prologue);
127
128 void printRegisters(const std::pair<uint16_t, uint32_t> &RegisterMask);
129
130 ErrorOr<object::SectionRef>
131 getSectionContaining(const object::COFFObjectFile &COFF, uint64_t Address);
132
133 ErrorOr<object::SymbolRef>
134 getSymbol(const object::COFFObjectFile &COFF, uint64_t Address,
135 bool FunctionOnly = false);
136
137 ErrorOr<object::SymbolRef>
138 getRelocatedSymbol(const object::COFFObjectFile &COFF,
139 const object::SectionRef &Section, uint64_t Offset);
140
141 bool dumpXDataRecord(const object::COFFObjectFile &COFF,
142 const object::SectionRef &Section,
143 uint64_t FunctionAddress, uint64_t VA);
144 bool dumpUnpackedEntry(const object::COFFObjectFile &COFF,
145 const object::SectionRef Section, uint64_t Offset,
146 unsigned Index, const RuntimeFunction &Entry);
147 bool dumpPackedEntry(const object::COFFObjectFile &COFF,
148 const object::SectionRef Section, uint64_t Offset,
149 unsigned Index, const RuntimeFunction &Entry);
150 bool dumpProcedureDataEntry(const object::COFFObjectFile &COFF,
151 const object::SectionRef Section, unsigned Entry,
152 ArrayRef<uint8_t> Contents);
153 void dumpProcedureData(const object::COFFObjectFile &COFF,
154 const object::SectionRef Section);
155
156public:
Sanjin Sijarice10866a2018-10-24 00:03:34 +0000157 Decoder(ScopedPrinter &SW, bool isAArch64) : SW(SW),
158 OS(SW.getOStream()),
159 isAArch64(isAArch64) {}
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000160 std::error_code dumpProcedureData(const object::COFFObjectFile &COFF);
Saleem Abdulrasoolfe3b74e2014-06-04 15:47:15 +0000161};
162}
163}
164}
165
166#endif