gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
types.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_X86_TYPES_HH__
39 #define __ARCH_X86_TYPES_HH__
40 
41 #include <iostream>
42 
43 #include "arch/generic/types.hh"
44 #include "base/bitunion.hh"
45 #include "base/cprintf.hh"
46 #include "base/types.hh"
47 #include "sim/serialize.hh"
48 
49 namespace X86ISA
50 {
51  //This really determines how many bytes are passed to the decoder.
52  typedef uint64_t MachInst;
53 
54  enum Prefixes {
66  Rep,
71  };
72 
73  BitUnion8(LegacyPrefixVector)
74  Bitfield<7, 4> decodeVal;
75  Bitfield<7> repne;
76  Bitfield<6> rep;
77  Bitfield<5> lock;
78  Bitfield<4> op;
79  Bitfield<3> addr;
80  //There can be only one segment override, so they share the
81  //first 3 bits in the legacyPrefixes bitfield.
82  Bitfield<2,0> seg;
83  EndBitUnion(LegacyPrefixVector)
84 
85  BitUnion8(ModRM)
86  Bitfield<7,6> mod;
87  Bitfield<5,3> reg;
88  Bitfield<2,0> rm;
89  EndBitUnion(ModRM)
90 
91  BitUnion8(Sib)
92  Bitfield<7,6> scale;
93  Bitfield<5,3> index;
94  Bitfield<2,0> base;
95  EndBitUnion(Sib)
96 
97  BitUnion8(Rex)
98  //This bit doesn't mean anything according to the ISA, but in
99  //this implementation, it being set means an REX prefix was present.
100  Bitfield<6> present;
101  Bitfield<3> w;
102  Bitfield<2> r;
103  Bitfield<1> x;
104  Bitfield<0> b;
105  EndBitUnion(Rex)
106 
107  BitUnion8(Vex2Of3)
108  // Inverted bits from the REX prefix.
109  Bitfield<7> r;
110  Bitfield<6> x;
111  Bitfield<5> b;
112  // Selector for what would be two or three byte opcode types.
113  Bitfield<4, 0> m;
114  EndBitUnion(Vex2Of3)
115 
116  BitUnion8(Vex3Of3)
117  // Bit from the REX prefix.
118  Bitfield<7> w;
119  // Inverted extra register index.
120  Bitfield<6, 3> v;
121  // Vector length specifier.
122  Bitfield<2> l;
123  // Implied 66, F2, or F3 opcode prefix.
124  Bitfield<1, 0> p;
125  EndBitUnion(Vex3Of3)
126 
127  BitUnion8(Vex2Of2)
128  // Inverted bit from the REX prefix.
129  Bitfield<7> r;
130  // Inverted extra register index.
131  Bitfield<6, 3> v;
132  // Vector length specifier
133  Bitfield<2> l;
134  // Implied 66, F2, or F3 opcode prefix.
135  Bitfield<1, 0> p;
136  EndBitUnion(Vex2Of2)
137 
138  BitUnion8(VexInfo)
139  // Extra register index.
140  Bitfield<6, 3> v;
141  // Vector length specifier.
142  Bitfield<2> l;
143  // Whether the VEX prefix was used.
144  Bitfield<0> present;
145  EndBitUnion(VexInfo)
146 
147  enum OpcodeType {
148  BadOpcode,
149  OneByteOpcode,
150  TwoByteOpcode,
151  ThreeByte0F38Opcode,
152  ThreeByte0F3AOpcode,
153  };
154 
155  static inline const char *
156  opcodeTypeToStr(OpcodeType type)
157  {
158  switch (type) {
159  case BadOpcode:
160  return "bad";
161  case OneByteOpcode:
162  return "one byte";
163  case TwoByteOpcode:
164  return "two byte";
165  case ThreeByte0F38Opcode:
166  return "three byte 0f38";
167  case ThreeByte0F3AOpcode:
168  return "three byte 0f3a";
169  default:
170  return "unrecognized!";
171  }
172  }
173 
174  BitUnion8(Opcode)
175  Bitfield<7,3> top5;
176  Bitfield<2,0> bottom3;
177  EndBitUnion(Opcode)
178 
180  Bitfield<3> mode;
181  Bitfield<2,0> submode;
183 
184  enum X86Mode {
185  LongMode,
186  LegacyMode
187  };
188 
189  enum X86SubMode {
195  };
196 
197  //The intermediate structure used by the x86 decoder.
198  struct ExtMachInst
199  {
200  void reset() {
201  memset(static_cast<void *>(this), 0, sizeof(*this));
202  }
203 
204  //Prefixes
205  LegacyPrefixVector legacy;
206  Rex rex;
207  VexInfo vex;
208 
209  //This holds all of the bytes of the opcode
210  struct
211  {
212  OpcodeType type;
213  //The main opcode byte. The highest addressed byte in the opcode.
214  Opcode op;
215  } opcode;
216  //Modifier bytes
217  ModRM modRM;
218  Sib sib;
219  //Immediate fields
220  uint64_t immediate;
221  uint64_t displacement;
222 
223  //The effective operand size.
224  uint8_t opSize;
225  //The effective address size.
226  uint8_t addrSize;
227  //The effective stack size.
228  uint8_t stackSize;
229  //The size of the displacement
230  uint8_t dispSize;
231 
232  //Mode information
234  };
235 
236  inline static std::ostream &
237  operator << (std::ostream & os, const ExtMachInst & emi)
238  {
239  ccprintf(os, "\n{\n\tleg = %#x,\n\trex = %#x,\n\t"
240  "vex/xop = %#x,\n\t"
241  "op = {\n\t\ttype = %s,\n\t\top = %#x,\n\t\t},\n\t"
242  "modRM = %#x,\n\tsib = %#x,\n\t"
243  "immediate = %#x,\n\tdisplacement = %#x\n\t"
244  "dispSize = %d}\n",
245  (uint8_t)emi.legacy, (uint8_t)emi.rex,
246  (uint8_t)emi.vex,
247  opcodeTypeToStr(emi.opcode.type), (uint8_t)emi.opcode.op,
248  (uint8_t)emi.modRM, (uint8_t)emi.sib,
249  emi.immediate, emi.displacement, emi.dispSize);
250  return os;
251  }
252 
253  inline static bool
254  operator == (const ExtMachInst &emi1, const ExtMachInst &emi2)
255  {
256  if (emi1.legacy != emi2.legacy)
257  return false;
258  if (emi1.rex != emi2.rex)
259  return false;
260  if (emi1.vex != emi2.vex)
261  return false;
262  if (emi1.opcode.type != emi2.opcode.type)
263  return false;
264  if (emi1.opcode.op != emi2.opcode.op)
265  return false;
266  if (emi1.modRM != emi2.modRM)
267  return false;
268  if (emi1.sib != emi2.sib)
269  return false;
270  if (emi1.immediate != emi2.immediate)
271  return false;
272  if (emi1.displacement != emi2.displacement)
273  return false;
274  if (emi1.mode != emi2.mode)
275  return false;
276  if (emi1.opSize != emi2.opSize)
277  return false;
278  if (emi1.addrSize != emi2.addrSize)
279  return false;
280  if (emi1.stackSize != emi2.stackSize)
281  return false;
282  if (emi1.dispSize != emi2.dispSize)
283  return false;
284  return true;
285  }
286 
287  class PCState : public GenericISA::UPCState<MachInst>
288  {
289  protected:
291 
292  uint8_t _size;
293 
294  public:
295  void
296  set(Addr val)
297  {
298  Base::set(val);
299  _size = 0;
300  }
301 
302  PCState() {}
303  PCState(Addr val) { set(val); }
304 
305  void
307  {
308  Base::setNPC(val);
309  _size = 0;
310  }
311 
312  uint8_t size() const { return _size; }
313  void size(uint8_t newSize) { _size = newSize; }
314 
315  bool
316  branching() const
317  {
318  return (this->npc() != this->pc() + size()) ||
319  (this->nupc() != this->upc() + 1);
320  }
321 
322  void
324  {
325  Base::advance();
326  _size = 0;
327  }
328 
329  void
331  {
332  Base::uEnd();
333  _size = 0;
334  }
335 
336  void
338  {
339  Base::serialize(cp);
340  SERIALIZE_SCALAR(_size);
341  }
342 
343  void
345  {
346  Base::unserialize(cp);
347  UNSERIALIZE_SCALAR(_size);
348  }
349  };
350 
351 }
352 
353 namespace std {
354  template<>
355  struct hash<X86ISA::ExtMachInst> {
356  size_t operator()(const X86ISA::ExtMachInst &emi) const {
357  return (((uint64_t)emi.legacy << 48) |
358  ((uint64_t)emi.rex << 40) |
359  ((uint64_t)emi.vex << 32) |
360  ((uint64_t)emi.modRM << 24) |
361  ((uint64_t)emi.sib << 16) |
362  ((uint64_t)emi.opcode.type << 8) |
363  ((uint64_t)emi.opcode.op)) ^
364  emi.immediate ^ emi.displacement ^
365  emi.mode ^
366  emi.opSize ^ emi.addrSize ^
367  emi.stackSize ^ emi.dispSize;
368  };
369  };
370 }
371 
372 // These two functions allow ExtMachInst to be used with SERIALIZE_SCALAR
373 // and UNSERIALIZE_SCALAR.
374 template <>
375 void
376 paramOut(CheckpointOut &cp, const std::string &name,
377  const X86ISA::ExtMachInst &machInst);
378 template <>
379 void
380 paramIn(CheckpointIn &cp, const std::string &name,
381  X86ISA::ExtMachInst &machInst);
382 
383 #endif // __ARCH_X86_TYPES_HH__
void paramIn(CheckpointIn &cp, const std::string &name, X86ISA::ExtMachInst &machInst)
BitUnion8(LegacyPrefixVector) Bitfield< 7
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
uint64_t immediate
Definition: types.hh:220
Bitfield< 5, 3 > reg
Definition: types.hh:87
Bitfield< 5, 3 > index
Definition: types.hh:93
void setNPC(Addr val)
Definition: types.hh:306
const std::string & name()
Definition: trace.cc:50
uint8_t size() const
Definition: types.hh:312
void uEnd()
Definition: types.hh:330
EndBitUnion(TriggerIntMessage) namespace DeliveryMode
Definition: intmessage.hh:49
uint8_t dispSize
Definition: types.hh:230
bool branching() const
Definition: types.hh:316
Bitfield< 3, 1 > submode
Definition: misc.hh:579
size_t operator()(const X86ISA::ExtMachInst &emi) const
Definition: types.hh:356
OperatingMode
Definition: types.hh:590
Bitfield< 7 > present
Definition: misc.hh:992
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Bitfield< 4, 0 > m
Definition: types.hh:113
Bitfield< 19 > pc
Definition: misc.hh:805
Definition: cprintf.cc:40
Bitfield< 53 > l
Definition: misc.hh:920
Bitfield< 4, 0 > mode
uint8_t _size
Definition: types.hh:292
top5
Definition: types.hh:175
static std::ostream & operator<<(std::ostream &os, const ExtMachInst &emi)
Definition: types.hh:237
Bitfield< 17 > os
Definition: misc.hh:803
Bitfield< 63 > val
Definition: misc.hh:769
Bitfield< 6, 3 > v
Definition: types.hh:120
uint8_t stackSize
Definition: types.hh:228
Bitfield< 2, 0 > bottom3
Definition: types.hh:176
mod
Definition: types.hh:86
Bitfield< 41 > r
Definition: misc.hh:934
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
Bitfield< 6 > rep
Definition: types.hh:76
OpcodeType type
Definition: types.hh:212
static bool operator==(const ExtMachInst &emi1, const ExtMachInst &emi2)
Definition: types.hh:254
void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: types.hh:337
Bitfield< 7 > repne
Definition: types.hh:75
X86SubMode
Definition: types.hh:189
Bitfield< 1 > w
Definition: pagetable.hh:150
LegacyPrefixVector legacy
Definition: types.hh:205
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: types.hh:344
Bitfield< 2, 0 > rm
Definition: types.hh:88
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
uint64_t MachInst
Definition: types.hh:52
decodeVal
Definition: types.hh:74
void paramOut(CheckpointOut &cp, const std::string &name, const X86ISA::ExtMachInst &machInst)
Bitfield< 2, 0 > seg
Definition: types.hh:82
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
void advance()
Definition: types.hh:323
scale
Definition: types.hh:92
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
Bitfield< 54 > b
Definition: misc.hh:919
static const char * opcodeTypeToStr(OpcodeType type)
Definition: types.hh:156
struct X86ISA::ExtMachInst::@22 opcode
type
Definition: misc.hh:727
uint64_t displacement
Definition: types.hh:221
std::ostream CheckpointOut
Definition: serialize.hh:63
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
Prefixes
Definition: types.hh:54
uint8_t opSize
Definition: types.hh:224
uint8_t addrSize
Definition: types.hh:226
OperatingMode mode
Definition: types.hh:233
void size(uint8_t newSize)
Definition: types.hh:313
void unserialize(ThreadContext &tc, CheckpointIn &cp)
uint64_t ExtMachInst
Definition: types.hh:39
Bitfield< 0 > p
Definition: pagetable.hh:151
Bitfield< 4 > op
Definition: types.hh:78
GenericISA::UPCState< MachInst > Base
Definition: types.hh:290
Bitfield< 1 > x
Definition: types.hh:103
Bitfield< 3 > addr
Definition: types.hh:79
Bitfield< 5 > lock
Definition: types.hh:77
PCState(Addr val)
Definition: types.hh:303

Generated on Mon Jun 8 2020 15:34:40 for gem5 by doxygen 1.8.13