2 * Copyright (c) 2007 The Hewlett-Packard Development Company
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.
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.
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.
40 #ifndef __ARCH_X86_TYPES_HH__
41 #define __ARCH_X86_TYPES_HH__
45 #include "arch/generic/types.hh"
46 #include "base/bitunion.hh"
47 #include "base/cprintf.hh"
48 #include "base/types.hh"
49 #include "sim/serialize.hh"
53 //This really determines how many bytes are passed to the decoder.
54 typedef uint64_t MachInst;
75 BitUnion8(LegacyPrefixVector)
76 Bitfield<7, 4> decodeVal;
82 //There can be only one segment override, so they share the
83 //first 3 bits in the legacyPrefixes bitfield.
85 EndBitUnion(LegacyPrefixVector)
100 //This bit doesn't mean anything according to the ISA, but in
101 //this implementation, it being set means an REX prefix was present.
110 // Inverted bits from the REX prefix.
114 // Selector for what would be two or three byte opcode types.
119 // Bit from the REX prefix.
121 // Inverted extra register index.
123 // Vector length specifier.
125 // Implied 66, F2, or F3 opcode prefix.
130 // Inverted bit from the REX prefix.
132 // Inverted extra register index.
134 // Vector length specifier
136 // Implied 66, F2, or F3 opcode prefix.
141 // Extra register index.
143 // Vector length specifier.
145 // Whether the VEX prefix was used.
157 static inline const char *
158 opcodeTypeToStr(OpcodeType type)
167 case ThreeByte0F38Opcode:
168 return "three byte 0f38";
169 case ThreeByte0F3AOpcode:
170 return "three byte 0f3a";
172 return "unrecognized!";
178 Bitfield<2,0> bottom3;
181 BitUnion8(OperatingMode)
183 Bitfield<2,0> submode;
184 EndBitUnion(OperatingMode)
199 //The intermediate structure used by the x86 decoder.
203 memset(static_cast<void *>(this), 0, sizeof(*this));
207 LegacyPrefixVector legacy;
211 //This holds all of the bytes of the opcode
215 //The main opcode byte. The highest addressed byte in the opcode.
223 uint64_t displacement;
225 //The effective operand size.
227 //The effective address size.
229 //The effective stack size.
231 //The size of the displacement
238 inline static std::ostream &
239 operator << (std::ostream & os, const ExtMachInst & emi)
241 ccprintf(os, "\n{\n\tleg = %#x,\n\trex = %#x,\n\t"
243 "op = {\n\t\ttype = %s,\n\t\top = %#x,\n\t\t},\n\t"
244 "modRM = %#x,\n\tsib = %#x,\n\t"
245 "immediate = %#x,\n\tdisplacement = %#x\n\t"
247 (uint8_t)emi.legacy, (uint8_t)emi.rex,
249 opcodeTypeToStr(emi.opcode.type), (uint8_t)emi.opcode.op,
250 (uint8_t)emi.modRM, (uint8_t)emi.sib,
251 emi.immediate, emi.displacement, emi.dispSize);
256 operator == (const ExtMachInst &emi1, const ExtMachInst &emi2)
258 if (emi1.legacy != emi2.legacy)
260 if (emi1.rex != emi2.rex)
262 if (emi1.vex != emi2.vex)
264 if (emi1.opcode.type != emi2.opcode.type)
266 if (emi1.opcode.op != emi2.opcode.op)
268 if (emi1.modRM != emi2.modRM)
270 if (emi1.sib != emi2.sib)
272 if (emi1.immediate != emi2.immediate)
274 if (emi1.displacement != emi2.displacement)
276 if (emi1.mode != emi2.mode)
278 if (emi1.opSize != emi2.opSize)
280 if (emi1.addrSize != emi2.addrSize)
282 if (emi1.stackSize != emi2.stackSize)
284 if (emi1.dispSize != emi2.dispSize)
289 class PCState : public GenericISA::UPCState<MachInst>
292 typedef GenericISA::UPCState<MachInst> Base;
305 PCState(Addr val) { set(val); }
314 uint8_t size() const { return _size; }
315 void size(uint8_t newSize) { _size = newSize; }
320 return (this->npc() != this->pc() + size()) ||
321 (this->nupc() != this->upc() + 1);
339 serialize(CheckpointOut &cp) const
342 SERIALIZE_SCALAR(_size);
346 unserialize(CheckpointIn &cp)
348 Base::unserialize(cp);
349 UNSERIALIZE_SCALAR(_size);
357 struct hash<X86ISA::ExtMachInst> {
358 size_t operator()(const X86ISA::ExtMachInst &emi) const {
359 return (((uint64_t)emi.legacy << 48) |
360 ((uint64_t)emi.rex << 40) |
361 ((uint64_t)emi.vex << 32) |
362 ((uint64_t)emi.modRM << 24) |
363 ((uint64_t)emi.sib << 16) |
364 ((uint64_t)emi.opcode.type << 8) |
365 ((uint64_t)emi.opcode.op)) ^
366 emi.immediate ^ emi.displacement ^
368 emi.opSize ^ emi.addrSize ^
369 emi.stackSize ^ emi.dispSize;
374 // These two functions allow ExtMachInst to be used with SERIALIZE_SCALAR
375 // and UNSERIALIZE_SCALAR.
378 paramOut(CheckpointOut &cp, const std::string &name,
379 const X86ISA::ExtMachInst &machInst);
382 paramIn(CheckpointIn &cp, const std::string &name,
383 X86ISA::ExtMachInst &machInst);
385 #endif // __ARCH_X86_TYPES_HH__