gem5  v21.0.0.0
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 
52 //This really determines how many bytes are passed to the decoder.
53 typedef uint64_t MachInst;
54 
55 enum Prefixes {
67  Rep,
72 };
73 
74 BitUnion8(LegacyPrefixVector)
75  Bitfield<7, 4> decodeVal;
76  Bitfield<7> repne;
77  Bitfield<6> rep;
78  Bitfield<5> lock;
79  Bitfield<4> op;
80  Bitfield<3> addr;
81  //There can be only one segment override, so they share the
82  //first 3 bits in the legacyPrefixes bitfield.
83  Bitfield<2,0> seg;
84 EndBitUnion(LegacyPrefixVector)
85 
86 BitUnion8(ModRM)
87  Bitfield<7,6> mod;
88  Bitfield<5,3> reg;
89  Bitfield<2,0> rm;
90 EndBitUnion(ModRM)
91 
92 BitUnion8(Sib)
93  Bitfield<7,6> scale;
94  Bitfield<5,3> index;
95  Bitfield<2,0> base;
96 EndBitUnion(Sib)
97 
98 BitUnion8(Rex)
99  //This bit doesn't mean anything according to the ISA, but in
100  //this implementation, it being set means an REX prefix was present.
101  Bitfield<6> present;
102  Bitfield<3> w;
103  Bitfield<2> r;
104  Bitfield<1> x;
105  Bitfield<0> b;
106 EndBitUnion(Rex)
107 
108 BitUnion8(Vex2Of3)
109  // Inverted bits from the REX prefix.
110  Bitfield<7> r;
111  Bitfield<6> x;
112  Bitfield<5> b;
113  // Selector for what would be two or three byte opcode types.
114  Bitfield<4, 0> m;
115 EndBitUnion(Vex2Of3)
116 
117 BitUnion8(Vex3Of3)
118  // Bit from the REX prefix.
119  Bitfield<7> w;
120  // Inverted extra register index.
121  Bitfield<6, 3> v;
122  // Vector length specifier.
123  Bitfield<2> l;
124  // Implied 66, F2, or F3 opcode prefix.
125  Bitfield<1, 0> p;
126 EndBitUnion(Vex3Of3)
127 
128 BitUnion8(Vex2Of2)
129  // Inverted bit from the REX prefix.
130  Bitfield<7> r;
131  // Inverted extra register index.
132  Bitfield<6, 3> v;
133  // Vector length specifier
134  Bitfield<2> l;
135  // Implied 66, F2, or F3 opcode prefix.
136  Bitfield<1, 0> p;
137 EndBitUnion(Vex2Of2)
138 
139 BitUnion8(VexInfo)
140  // Extra register index.
141  Bitfield<6, 3> v;
142  // Vector length specifier.
143  Bitfield<2> l;
144  // Whether the VEX prefix was used.
145  Bitfield<0> present;
146 EndBitUnion(VexInfo)
147 
148 enum OpcodeType {
149  BadOpcode,
150  OneByteOpcode,
151  TwoByteOpcode,
152  ThreeByte0F38Opcode,
153  ThreeByte0F3AOpcode,
154 };
155 
156 static inline const char *
158 {
159  switch (type) {
160  case BadOpcode:
161  return "bad";
162  case OneByteOpcode:
163  return "one byte";
164  case TwoByteOpcode:
165  return "two byte";
166  case ThreeByte0F38Opcode:
167  return "three byte 0f38";
168  case ThreeByte0F3AOpcode:
169  return "three byte 0f3a";
170  default:
171  return "unrecognized!";
172  }
173 }
174 
175 BitUnion8(Opcode)
176  Bitfield<7,3> top5;
177  Bitfield<2,0> bottom3;
178 EndBitUnion(Opcode)
179 
181  Bitfield<3> mode;
182  Bitfield<2,0> submode;
184 
185 enum X86Mode {
186  LongMode,
187  LegacyMode
188 };
189 
196 };
197 
198 //The intermediate structure used by the x86 decoder.
200 {
201  void reset() { memset(static_cast<void *>(this), 0, sizeof(*this)); }
202 
203  //Prefixes
204  LegacyPrefixVector legacy;
205  Rex rex;
206  VexInfo vex;
207 
208  //This holds all of the bytes of the opcode
209  struct
210  {
211  OpcodeType type;
212  //The main opcode byte. The highest addressed byte in the opcode.
213  Opcode op;
214  } opcode;
215  //Modifier bytes
216  ModRM modRM;
217  Sib sib;
218  //Immediate fields
219  uint64_t immediate;
220  uint64_t displacement;
221 
222  //The effective operand size.
223  uint8_t opSize;
224  //The effective address size.
225  uint8_t addrSize;
226  //The effective stack size.
227  uint8_t stackSize;
228  //The size of the displacement
229  uint8_t dispSize;
230 
231  //Mode information
233 };
234 
235 inline static std::ostream &
236 operator << (std::ostream &os, const ExtMachInst &emi)
237 {
238  ccprintf(os, "\n{\n\tleg = %#x,\n\trex = %#x,\n\t"
239  "vex/xop = %#x,\n\t"
240  "op = {\n\t\ttype = %s,\n\t\top = %#x,\n\t\t},\n\t"
241  "modRM = %#x,\n\tsib = %#x,\n\t"
242  "immediate = %#x,\n\tdisplacement = %#x\n\t"
243  "dispSize = %d}\n",
244  (uint8_t)emi.legacy, (uint8_t)emi.rex,
245  (uint8_t)emi.vex,
246  opcodeTypeToStr(emi.opcode.type), (uint8_t)emi.opcode.op,
247  (uint8_t)emi.modRM, (uint8_t)emi.sib,
248  emi.immediate, emi.displacement, emi.dispSize);
249  return os;
250 }
251 
252 inline static bool
253 operator == (const ExtMachInst &emi1, const ExtMachInst &emi2)
254 {
255  if (emi1.legacy != emi2.legacy)
256  return false;
257  if (emi1.rex != emi2.rex)
258  return false;
259  if (emi1.vex != emi2.vex)
260  return false;
261  if (emi1.opcode.type != emi2.opcode.type)
262  return false;
263  if (emi1.opcode.op != emi2.opcode.op)
264  return false;
265  if (emi1.modRM != emi2.modRM)
266  return false;
267  if (emi1.sib != emi2.sib)
268  return false;
269  if (emi1.immediate != emi2.immediate)
270  return false;
271  if (emi1.displacement != emi2.displacement)
272  return false;
273  if (emi1.mode != emi2.mode)
274  return false;
275  if (emi1.opSize != emi2.opSize)
276  return false;
277  if (emi1.addrSize != emi2.addrSize)
278  return false;
279  if (emi1.stackSize != emi2.stackSize)
280  return false;
281  if (emi1.dispSize != emi2.dispSize)
282  return false;
283  return true;
284 }
285 
286 class PCState : public GenericISA::UPCState<MachInst>
287 {
288  protected:
290 
291  uint8_t _size;
292 
293  public:
294  void
296  {
297  Base::set(val);
298  _size = 0;
299  }
300 
301  PCState() {}
303 
304  void
306  {
307  Base::setNPC(val);
308  _size = 0;
309  }
310 
311  uint8_t size() const { return _size; }
312  void size(uint8_t newSize) { _size = newSize; }
313 
314  bool
315  branching() const
316  {
317  return (this->npc() != this->pc() + size()) ||
318  (this->nupc() != this->upc() + 1);
319  }
320 
321  void
323  {
324  Base::advance();
325  _size = 0;
326  }
327 
328  void
330  {
331  Base::uEnd();
332  _size = 0;
333  }
334 
335  void
337  {
340  }
341 
342  void
344  {
347  }
348 };
349 
350 }
351 
352 namespace std
353 {
354 
355 template<>
356 struct hash<X86ISA::ExtMachInst>
357 {
358  size_t
359  operator()(const X86ISA::ExtMachInst &emi) const
360  {
361  return (((uint64_t)emi.legacy << 48) |
362  ((uint64_t)emi.rex << 40) |
363  ((uint64_t)emi.vex << 32) |
364  ((uint64_t)emi.modRM << 24) |
365  ((uint64_t)emi.sib << 16) |
366  ((uint64_t)emi.opcode.type << 8) |
367  ((uint64_t)emi.opcode.op)) ^
368  emi.immediate ^ emi.displacement ^
369  emi.mode ^
370  emi.opSize ^ emi.addrSize ^
371  emi.stackSize ^ emi.dispSize;
372  };
373 };
374 
375 }
376 
377 // These two functions allow ExtMachInst to be used with SERIALIZE_SCALAR
378 // and UNSERIALIZE_SCALAR.
379 template <>
380 void paramOut(CheckpointOut &cp, const std::string &name,
381  const X86ISA::ExtMachInst &machInst);
382 template <>
383 void paramIn(CheckpointIn &cp, const std::string &name,
384  X86ISA::ExtMachInst &machInst);
385 
386 #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:311
X86ISA::r
Bitfield< 41 > r
Definition: misc.hh:934
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
X86ISA::Rep
@ Rep
Definition: types.hh:67
X86ISA::Virtual8086Mode
@ Virtual8086Mode
Definition: types.hh:194
X86ISA::operator==
static bool operator==(const ExtMachInst &emi1, const ExtMachInst &emi2)
Definition: types.hh:253
X86ISA::ExtMachInst::mode
OperatingMode mode
Definition: types.hh:232
GenericISA::SimplePCState::advance
void advance()
Definition: types.hh:188
GenericISA::UPCState::set
void set(Addr val)
Definition: types.hh:228
serialize.hh
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:591
X86ISA::DSOverride
@ DSOverride
Definition: types.hh:60
X86ISA::ExtMachInst::op
Opcode op
Definition: types.hh:213
X86ISA::BitUnion8
BitUnion8(LegacyPrefixVector) Bitfield< 7
X86ISA::PCState::PCState
PCState(Addr val)
Definition: types.hh:302
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:57
paramIn
void paramIn(CheckpointIn &cp, const std::string &name, X86ISA::ExtMachInst &machInst)
Definition: types.cc:69
X86ISA::lock
Bitfield< 5 > lock
Definition: types.hh:78
X86ISA::CompatabilityMode
@ CompatabilityMode
Definition: types.hh:192
X86ISA::MachInst
uint64_t MachInst
Definition: types.hh:53
X86ISA::PCState::setNPC
void setNPC(Addr val)
Definition: types.hh:305
X86ISA::PCState::branching
bool branching() const
Definition: types.hh:315
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:138
X86ISA::op
Bitfield< 4 > op
Definition: types.hh:79
X86ISA::Vex2Prefix
@ Vex2Prefix
Definition: types.hh:69
X86ISA::ExtMachInst::immediate
uint64_t immediate
Definition: types.hh:219
X86ISA::x
Bitfield< 1 > x
Definition: types.hh:104
X86ISA::PCState::uEnd
void uEnd()
Definition: types.hh:329
X86ISA::PCState::serialize
void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: types.hh:336
X86ISA::PCState::set
void set(Addr val)
Definition: types.hh:295
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:88
X86ISA::scale
scale
Definition: types.hh:93
X86ISA::v
Bitfield< 6, 3 > v
Definition: types.hh:121
X86ISA::SSOverride
@ SSOverride
Definition: types.hh:59
X86ISA::ExtMachInst::displacement
uint64_t displacement
Definition: types.hh:220
GenericISA::SimplePCState::npc
Addr npc() const
Definition: types.hh:161
X86ISA::ProtectedMode
@ ProtectedMode
Definition: types.hh:193
X86ISA::AddressSizeOverride
@ AddressSizeOverride
Definition: types.hh:65
X86ISA::FSOverride
@ FSOverride
Definition: types.hh:61
cp
Definition: cprintf.cc:37
X86ISA::NoOverride
@ NoOverride
Definition: types.hh:56
X86ISA::index
Bitfield< 5, 3 > index
Definition: types.hh:94
X86ISA::GSOverride
@ GSOverride
Definition: types.hh:62
X86ISA::PCState::_size
uint8_t _size
Definition: types.hh:291
X86ISA::ExtMachInst::opSize
uint8_t opSize
Definition: types.hh:223
X86ISA::PCState::unserialize
void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: types.hh:343
X86ISA::OperandSizeOverride
@ OperandSizeOverride
Definition: types.hh:64
X86ISA::ExtMachInst::opcode
struct X86ISA::ExtMachInst::@20 opcode
GenericISA::UPCState::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: types.hh:285
bitunion.hh
X86ISA::RealMode
@ RealMode
Definition: types.hh:195
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
X86ISA::ExtMachInst::addrSize
uint8_t addrSize
Definition: types.hh:225
X86ISA::b
Bitfield< 54 > b
Definition: misc.hh:919
X86ISA::PCState
Definition: types.hh:286
X86ISA::Repne
@ Repne
Definition: types.hh:68
X86ISA::ExtMachInst
Definition: types.hh:199
cprintf.hh
paramOut
void paramOut(CheckpointOut &cp, const std::string &name, const X86ISA::ExtMachInst &machInst)
Definition: types.cc:37
std::hash< X86ISA::ExtMachInst >::operator()
size_t operator()(const X86ISA::ExtMachInst &emi) const
Definition: types.hh:359
X86ISA::repne
Bitfield< 7 > repne
Definition: types.hh:76
X86ISA::X86SubMode
X86SubMode
Definition: types.hh:190
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
X86ISA::w
Bitfield< 1 > w
Definition: pagetable.hh:147
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:148
X86ISA::ExtMachInst::modRM
ModRM modRM
Definition: types.hh:216
GenericISA::UPCState::uEnd
void uEnd()
Definition: types.hh:255
X86ISA::Vex3Prefix
@ Vex3Prefix
Definition: types.hh:70
name
const std::string & name()
Definition: trace.cc:48
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:584
X86ISA::opcodeTypeToStr
static const char * opcodeTypeToStr(OpcodeType type)
Definition: types.hh:157
X86ISA::bottom3
Bitfield< 2, 0 > bottom3
Definition: types.hh:177
X86ISA::Prefixes
Prefixes
Definition: types.hh:55
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
X86ISA::Lock
@ Lock
Definition: types.hh:66
types.hh
X86ISA::CSOverride
@ CSOverride
Definition: types.hh:58
X86ISA::PCState::advance
void advance()
Definition: types.hh:322
X86ISA::ExtMachInst::stackSize
uint8_t stackSize
Definition: types.hh:227
X86ISA::mod
mod
Definition: types.hh:87
GenericISA::UPCState::nupc
MicroPC nupc() const
Definition: types.hh:218
X86ISA::p
Bitfield< 0 > p
Definition: pagetable.hh:148
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
types.hh
X86ISA::rep
Bitfield< 6 > rep
Definition: types.hh:77
GenericISA::UPCState::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: types.hh:293
X86ISA::ExtMachInst::type
OpcodeType type
Definition: types.hh:211
X86ISA::EndBitUnion
EndBitUnion(TriggerIntMessage) namespace DeliveryMode
Definition: intmessage.hh:49
X86ISA::XopPrefix
@ XopPrefix
Definition: types.hh:71
X86ISA::ExtMachInst::rex
Rex rex
Definition: types.hh:205
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
X86ISA::ExtMachInst::sib
Sib sib
Definition: types.hh:217
X86ISA::ExtMachInst::vex
VexInfo vex
Definition: types.hh:206
X86ISA::ExtMachInst::dispSize
uint8_t dispSize
Definition: types.hh:229
GenericISA::SimplePCState::pc
Addr pc() const
Definition: types.hh:158
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:64
X86ISA::type
type
Definition: misc.hh:727
X86ISA::ExtMachInst::legacy
LegacyPrefixVector legacy
Definition: types.hh:204
X86ISA::SixtyFourBitMode
@ SixtyFourBitMode
Definition: types.hh:191
X86ISA::rm
Bitfield< 2, 0 > rm
Definition: types.hh:89
X86ISA::RexPrefix
@ RexPrefix
Definition: types.hh:63
X86ISA::PCState::size
void size(uint8_t newSize)
Definition: types.hh:312
CheckpointIn
Definition: serialize.hh:68
X86ISA::m
Bitfield< 4, 0 > m
Definition: types.hh:114
X86ISA::decodeVal
decodeVal
Definition: types.hh:75
X86ISA::submode
Bitfield< 3, 1 > submode
Definition: misc.hh:579
X86ISA::PCState::PCState
PCState()
Definition: types.hh:301
X86ISA::operator<<
static std::ostream & operator<<(std::ostream &os, const ExtMachInst &emi)
Definition: types.hh:236
X86ISA::top5
top5
Definition: types.hh:176
X86ISA::seg
Bitfield< 2, 0 > seg
Definition: types.hh:83
GenericISA::SimplePCState::setNPC
void setNPC(Addr val)
Definition: types.hh:172
X86ISA::PCState::Base
GenericISA::UPCState< MachInst > Base
Definition: types.hh:289
GenericISA::UPCState
Definition: types.hh:205
X86ISA::ExtMachInst::reset
void reset()
Definition: types.hh:201

Generated on Tue Mar 23 2021 19:41:20 for gem5 by doxygen 1.8.17