gem5  v20.1.0.0
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
297  {
298  Base::set(val);
299  _size = 0;
300  }
301 
302  PCState() {}
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  {
341  }
342 
343  void
345  {
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__
X86ISA::l
Bitfield< 53 > l
Definition: misc.hh:920
SparcISA::ExtMachInst
uint64_t ExtMachInst
Definition: types.hh:39
X86ISA::PCState::size
uint8_t size() const
Definition: types.hh:312
X86ISA::r
Bitfield< 41 > r
Definition: misc.hh:934
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
X86ISA::Rep
@ Rep
Definition: types.hh:66
X86ISA::Virtual8086Mode
@ Virtual8086Mode
Definition: types.hh:193
X86ISA::operator==
static bool operator==(const ExtMachInst &emi1, const ExtMachInst &emi2)
Definition: types.hh:254
X86ISA::ExtMachInst::mode
OperatingMode mode
Definition: types.hh:233
GenericISA::SimplePCState::advance
void advance()
Definition: types.hh:188
GenericISA::UPCState::set
void set(Addr val)
Definition: types.hh:228
X86ISA::ExtMachInst::opcode
struct X86ISA::ExtMachInst::@22 opcode
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
X86ISA::DSOverride
@ DSOverride
Definition: types.hh:59
X86ISA::ExtMachInst::op
Opcode op
Definition: types.hh:214
X86ISA::BitUnion8
BitUnion8(LegacyPrefixVector) Bitfield< 7
X86ISA::PCState::PCState
PCState(Addr val)
Definition: types.hh:303
GenericISA::UPCState::upc
MicroPC upc() const
Definition: types.hh:215
ArmISA::OperatingMode
OperatingMode
Definition: types.hh:628
X86ISA::present
Bitfield< 7 > present
Definition: misc.hh:992
X86ISA::ESOverride
@ ESOverride
Definition: types.hh:56
paramIn
void paramIn(CheckpointIn &cp, const std::string &name, X86ISA::ExtMachInst &machInst)
X86ISA::lock
Bitfield< 5 > lock
Definition: types.hh:77
X86ISA::CompatabilityMode
@ CompatabilityMode
Definition: types.hh:191
X86ISA::MachInst
uint64_t MachInst
Definition: types.hh:52
X86ISA::PCState::setNPC
void setNPC(Addr val)
Definition: types.hh:306
X86ISA::PCState::branching
bool branching() const
Definition: types.hh:316
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
X86ISA::op
Bitfield< 4 > op
Definition: types.hh:78
X86ISA::Vex2Prefix
@ Vex2Prefix
Definition: types.hh:68
X86ISA::ExtMachInst::immediate
uint64_t immediate
Definition: types.hh:220
X86ISA::x
Bitfield< 1 > x
Definition: types.hh:103
X86ISA::PCState::uEnd
void uEnd()
Definition: types.hh:330
X86ISA::PCState::serialize
void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: types.hh:337
X86ISA::PCState::set
void set(Addr val)
Definition: types.hh:296
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
X86ISA::scale
scale
Definition: types.hh:92
X86ISA::v
Bitfield< 6, 3 > v
Definition: types.hh:120
X86ISA::SSOverride
@ SSOverride
Definition: types.hh:58
X86ISA::ExtMachInst::displacement
uint64_t displacement
Definition: types.hh:221
GenericISA::SimplePCState::npc
Addr npc() const
Definition: types.hh:161
X86ISA::ProtectedMode
@ ProtectedMode
Definition: types.hh:192
X86ISA::AddressSizeOverride
@ AddressSizeOverride
Definition: types.hh:64
X86ISA::FSOverride
@ FSOverride
Definition: types.hh:60
cp
Definition: cprintf.cc:40
X86ISA::NoOverride
@ NoOverride
Definition: types.hh:55
X86ISA::index
Bitfield< 5, 3 > index
Definition: types.hh:93
X86ISA::GSOverride
@ GSOverride
Definition: types.hh:61
X86ISA::PCState::_size
uint8_t _size
Definition: types.hh:292
X86ISA::ExtMachInst::opSize
uint8_t opSize
Definition: types.hh:224
X86ISA::PCState::unserialize
void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: types.hh:344
X86ISA::OperandSizeOverride
@ OperandSizeOverride
Definition: types.hh:63
GenericISA::UPCState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:285
bitunion.hh
X86ISA::RealMode
@ RealMode
Definition: types.hh:194
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
X86ISA::ExtMachInst::addrSize
uint8_t addrSize
Definition: types.hh:226
X86ISA::b
Bitfield< 54 > b
Definition: misc.hh:919
X86ISA::PCState
Definition: types.hh:287
X86ISA::Repne
@ Repne
Definition: types.hh:67
X86ISA::ExtMachInst
Definition: types.hh:198
cprintf.hh
paramOut
void paramOut(CheckpointOut &cp, const std::string &name, const X86ISA::ExtMachInst &machInst)
std::hash< X86ISA::ExtMachInst >::operator()
size_t operator()(const X86ISA::ExtMachInst &emi) const
Definition: types.hh:356
X86ISA::repne
Bitfield< 7 > repne
Definition: types.hh:75
X86ISA::X86SubMode
X86SubMode
Definition: types.hh:189
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
X86ISA::w
Bitfield< 1 > w
Definition: pagetable.hh:150
X86ISA
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
X86ISA::ExtMachInst::modRM
ModRM modRM
Definition: types.hh:217
GenericISA::UPCState::uEnd
void uEnd()
Definition: types.hh:255
X86ISA::Vex3Prefix
@ Vex3Prefix
Definition: types.hh:69
name
const std::string & name()
Definition: trace.cc:50
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
X86ISA::opcodeTypeToStr
static const char * opcodeTypeToStr(OpcodeType type)
Definition: types.hh:156
X86ISA::bottom3
Bitfield< 2, 0 > bottom3
Definition: types.hh:176
X86ISA::Prefixes
Prefixes
Definition: types.hh:54
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:79
X86ISA::Lock
@ Lock
Definition: types.hh:65
types.hh
X86ISA::CSOverride
@ CSOverride
Definition: types.hh:57
X86ISA::PCState::advance
void advance()
Definition: types.hh:323
X86ISA::ExtMachInst::stackSize
uint8_t stackSize
Definition: types.hh:228
X86ISA::mod
mod
Definition: types.hh:86
GenericISA::UPCState::nupc
MicroPC nupc() const
Definition: types.hh:218
X86ISA::p
Bitfield< 0 > p
Definition: pagetable.hh:151
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
types.hh
X86ISA::rep
Bitfield< 6 > rep
Definition: types.hh:76
GenericISA::UPCState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:293
X86ISA::ExtMachInst::type
OpcodeType type
Definition: types.hh:212
X86ISA::EndBitUnion
EndBitUnion(TriggerIntMessage) namespace DeliveryMode
Definition: intmessage.hh:49
X86ISA::XopPrefix
@ XopPrefix
Definition: types.hh:70
X86ISA::ExtMachInst::rex
Rex rex
Definition: types.hh:206
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
X86ISA::ExtMachInst::sib
Sib sib
Definition: types.hh:218
X86ISA::ExtMachInst::vex
VexInfo vex
Definition: types.hh:207
X86ISA::ExtMachInst::dispSize
uint8_t dispSize
Definition: types.hh:230
GenericISA::SimplePCState::pc
Addr pc() const
Definition: types.hh:158
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
X86ISA::type
type
Definition: misc.hh:727
X86ISA::ExtMachInst::legacy
LegacyPrefixVector legacy
Definition: types.hh:205
X86ISA::SixtyFourBitMode
@ SixtyFourBitMode
Definition: types.hh:190
X86ISA::rm
Bitfield< 2, 0 > rm
Definition: types.hh:88
X86ISA::RexPrefix
@ RexPrefix
Definition: types.hh:62
X86ISA::PCState::size
void size(uint8_t newSize)
Definition: types.hh:313
CheckpointIn
Definition: serialize.hh:67
X86ISA::m
Bitfield< 4, 0 > m
Definition: types.hh:113
X86ISA::decodeVal
decodeVal
Definition: types.hh:74
X86ISA::submode
Bitfield< 3, 1 > submode
Definition: misc.hh:579
X86ISA::PCState::PCState
PCState()
Definition: types.hh:302
X86ISA::operator<<
static std::ostream & operator<<(std::ostream &os, const ExtMachInst &emi)
Definition: types.hh:237
X86ISA::top5
top5
Definition: types.hh:175
X86ISA::seg
Bitfield< 2, 0 > seg
Definition: types.hh:82
GenericISA::SimplePCState::setNPC
void setNPC(Addr val)
Definition: types.hh:172
X86ISA::PCState::Base
GenericISA::UPCState< MachInst > Base
Definition: types.hh:290
GenericISA::UPCState
Definition: types.hh:205
X86ISA::ExtMachInst::reset
void reset()
Definition: types.hh:200

Generated on Wed Sep 30 2020 14:02:01 for gem5 by doxygen 1.8.17