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

Generated on Tue Sep 21 2021 12:24:46 for gem5 by doxygen 1.8.17