2007-03-03 17:01:48 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 The Hewlett-Packard Development Company
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2010-05-24 07:44:15 +02:00
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
2007-03-03 17:01:48 +01:00
|
|
|
*
|
2010-05-24 07:44:15 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
2007-03-03 17:01:48 +01:00
|
|
|
* contributors may be used to endorse or promote products derived from
|
2010-05-24 07:44:15 +02:00
|
|
|
* this software without specific prior written permission.
|
2007-03-03 17:01:48 +01:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Gabe Black
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARCH_X86_TYPES_HH__
|
|
|
|
#define __ARCH_X86_TYPES_HH__
|
|
|
|
|
2007-03-15 03:47:42 +01:00
|
|
|
#include <iostream>
|
2007-03-05 15:53:51 +01:00
|
|
|
|
2007-07-15 02:28:26 +02:00
|
|
|
#include "base/bitunion.hh"
|
2007-03-21 20:19:53 +01:00
|
|
|
#include "base/cprintf.hh"
|
2009-05-17 23:34:51 +02:00
|
|
|
#include "base/types.hh"
|
2007-03-21 20:19:53 +01:00
|
|
|
|
2007-03-03 17:01:48 +01:00
|
|
|
namespace X86ISA
|
|
|
|
{
|
2007-03-13 17:13:21 +01:00
|
|
|
//This really determines how many bytes are passed to the predecoder.
|
|
|
|
typedef uint64_t MachInst;
|
2007-03-15 03:47:42 +01:00
|
|
|
|
|
|
|
enum Prefixes {
|
2007-04-06 17:19:23 +02:00
|
|
|
NoOverride,
|
2007-08-05 05:12:54 +02:00
|
|
|
ESOverride,
|
2007-04-06 17:19:23 +02:00
|
|
|
CSOverride,
|
2007-08-05 05:12:54 +02:00
|
|
|
SSOverride,
|
2007-04-06 17:19:23 +02:00
|
|
|
DSOverride,
|
|
|
|
FSOverride,
|
|
|
|
GSOverride,
|
|
|
|
RexPrefix,
|
|
|
|
OperandSizeOverride,
|
|
|
|
AddressSizeOverride,
|
|
|
|
Lock,
|
|
|
|
Rep,
|
|
|
|
Repne
|
|
|
|
};
|
|
|
|
|
|
|
|
BitUnion8(LegacyPrefixVector)
|
2007-07-20 23:57:04 +02:00
|
|
|
Bitfield<7, 4> decodeVal;
|
2007-04-06 17:19:23 +02:00
|
|
|
Bitfield<7> repne;
|
|
|
|
Bitfield<6> rep;
|
|
|
|
Bitfield<5> lock;
|
2007-07-20 23:57:04 +02:00
|
|
|
Bitfield<4> op;
|
|
|
|
Bitfield<3> addr;
|
2007-03-15 03:47:42 +01:00
|
|
|
//There can be only one segment override, so they share the
|
|
|
|
//first 3 bits in the legacyPrefixes bitfield.
|
2007-04-06 17:19:23 +02:00
|
|
|
Bitfield<2,0> seg;
|
|
|
|
EndBitUnion(LegacyPrefixVector)
|
2007-03-15 03:47:42 +01:00
|
|
|
|
2007-03-21 20:19:53 +01:00
|
|
|
BitUnion8(ModRM)
|
|
|
|
Bitfield<7,6> mod;
|
|
|
|
Bitfield<5,3> reg;
|
|
|
|
Bitfield<2,0> rm;
|
|
|
|
EndBitUnion(ModRM)
|
|
|
|
|
|
|
|
BitUnion8(Sib)
|
|
|
|
Bitfield<7,6> scale;
|
|
|
|
Bitfield<5,3> index;
|
|
|
|
Bitfield<2,0> base;
|
|
|
|
EndBitUnion(Sib)
|
|
|
|
|
|
|
|
BitUnion8(Rex)
|
2007-07-30 22:20:08 +02:00
|
|
|
//This bit doesn't mean anything according to the ISA, but in
|
|
|
|
//this implementation, it being set means an REX prefix was present.
|
|
|
|
Bitfield<6> present;
|
2007-03-21 20:19:53 +01:00
|
|
|
Bitfield<3> w;
|
|
|
|
Bitfield<2> r;
|
|
|
|
Bitfield<1> x;
|
|
|
|
Bitfield<0> b;
|
|
|
|
EndBitUnion(Rex)
|
|
|
|
|
|
|
|
BitUnion8(Opcode)
|
|
|
|
Bitfield<7,3> top5;
|
|
|
|
Bitfield<2,0> bottom3;
|
|
|
|
EndBitUnion(Opcode)
|
|
|
|
|
2007-06-14 15:50:58 +02:00
|
|
|
BitUnion8(OperatingMode)
|
|
|
|
Bitfield<3> mode;
|
|
|
|
Bitfield<2,0> submode;
|
|
|
|
EndBitUnion(OperatingMode)
|
|
|
|
|
|
|
|
enum X86Mode {
|
|
|
|
LongMode,
|
|
|
|
LegacyMode
|
|
|
|
};
|
|
|
|
|
|
|
|
enum X86SubMode {
|
|
|
|
SixtyFourBitMode,
|
|
|
|
CompatabilityMode,
|
|
|
|
ProtectedMode,
|
|
|
|
Virtual8086Mode,
|
|
|
|
RealMode
|
|
|
|
};
|
|
|
|
|
2007-03-13 17:13:21 +01:00
|
|
|
//The intermediate structure the x86 predecoder returns.
|
|
|
|
struct ExtMachInst
|
|
|
|
{
|
2007-03-21 20:19:53 +01:00
|
|
|
//Prefixes
|
2007-04-06 17:19:23 +02:00
|
|
|
LegacyPrefixVector legacy;
|
2007-03-21 20:19:53 +01:00
|
|
|
Rex rex;
|
|
|
|
//This holds all of the bytes of the opcode
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
//The number of bytes in this opcode. Right now, we ignore that
|
|
|
|
//this can be 3 in some cases
|
|
|
|
uint8_t num;
|
|
|
|
//The first byte detected in a 2+ byte opcode. Should be 0xF0.
|
|
|
|
uint8_t prefixA;
|
2009-08-18 09:52:45 +02:00
|
|
|
//The second byte detected in a 3+ byte opcode. Could be 0x38-0x3F
|
|
|
|
//for some SSE instructions. 3dNow! instructions are handled as
|
|
|
|
//two byte opcodes and then split out further by the immediate
|
|
|
|
//byte.
|
2007-03-21 20:19:53 +01:00
|
|
|
uint8_t prefixB;
|
|
|
|
//The main opcode byte. The highest addressed byte in the opcode.
|
|
|
|
Opcode op;
|
|
|
|
} opcode;
|
|
|
|
//Modifier bytes
|
|
|
|
ModRM modRM;
|
2007-06-20 17:02:50 +02:00
|
|
|
Sib sib;
|
2007-03-21 20:19:53 +01:00
|
|
|
//Immediate fields
|
2007-03-15 03:47:42 +01:00
|
|
|
uint64_t immediate;
|
|
|
|
uint64_t displacement;
|
2007-04-06 17:19:23 +02:00
|
|
|
|
|
|
|
//The effective operand size.
|
|
|
|
uint8_t opSize;
|
2007-06-12 18:23:42 +02:00
|
|
|
//The effective address size.
|
|
|
|
uint8_t addrSize;
|
2007-06-19 16:18:25 +02:00
|
|
|
//The effective stack size.
|
|
|
|
uint8_t stackSize;
|
2009-08-03 20:01:40 +02:00
|
|
|
//The size of the displacement
|
|
|
|
uint8_t dispSize;
|
2007-06-14 15:50:58 +02:00
|
|
|
|
|
|
|
//Mode information
|
|
|
|
OperatingMode mode;
|
2007-03-13 17:13:21 +01:00
|
|
|
};
|
|
|
|
|
2007-03-15 03:47:42 +01:00
|
|
|
inline static std::ostream &
|
|
|
|
operator << (std::ostream & os, const ExtMachInst & emi)
|
|
|
|
{
|
2007-03-21 20:19:53 +01:00
|
|
|
ccprintf(os, "\n{\n\tleg = %#x,\n\trex = %#x,\n\t"
|
|
|
|
"op = {\n\t\tnum = %d,\n\t\top = %#x,\n\t\t"
|
|
|
|
"prefixA = %#x,\n\t\tprefixB = %#x\n\t},\n\t"
|
|
|
|
"modRM = %#x,\n\tsib = %#x,\n\t"
|
2009-08-03 20:01:40 +02:00
|
|
|
"immediate = %#x,\n\tdisplacement = %#x\n\t"
|
|
|
|
"dispSize = %d}\n",
|
2007-07-19 02:45:43 +02:00
|
|
|
(uint8_t)emi.legacy, (uint8_t)emi.rex,
|
|
|
|
emi.opcode.num, (uint8_t)emi.opcode.op,
|
2007-03-21 20:19:53 +01:00
|
|
|
emi.opcode.prefixA, emi.opcode.prefixB,
|
|
|
|
(uint8_t)emi.modRM, (uint8_t)emi.sib,
|
2009-08-03 20:01:40 +02:00
|
|
|
emi.immediate, emi.displacement, emi.dispSize);
|
2007-03-15 03:47:42 +01:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool
|
|
|
|
operator == (const ExtMachInst &emi1, const ExtMachInst &emi2)
|
2007-03-13 17:13:21 +01:00
|
|
|
{
|
2007-04-04 16:27:00 +02:00
|
|
|
if(emi1.legacy != emi2.legacy)
|
|
|
|
return false;
|
|
|
|
if(emi1.rex != emi2.rex)
|
|
|
|
return false;
|
|
|
|
if(emi1.opcode.num != emi2.opcode.num)
|
|
|
|
return false;
|
|
|
|
if(emi1.opcode.op != emi2.opcode.op)
|
|
|
|
return false;
|
|
|
|
if(emi1.opcode.prefixA != emi2.opcode.prefixA)
|
|
|
|
return false;
|
|
|
|
if(emi1.opcode.prefixB != emi2.opcode.prefixB)
|
|
|
|
return false;
|
|
|
|
if(emi1.modRM != emi2.modRM)
|
|
|
|
return false;
|
|
|
|
if(emi1.sib != emi2.sib)
|
|
|
|
return false;
|
|
|
|
if(emi1.immediate != emi2.immediate)
|
|
|
|
return false;
|
|
|
|
if(emi1.displacement != emi2.displacement)
|
|
|
|
return false;
|
2007-06-19 16:18:25 +02:00
|
|
|
if(emi1.mode != emi2.mode)
|
|
|
|
return false;
|
|
|
|
if(emi1.opSize != emi2.opSize)
|
|
|
|
return false;
|
|
|
|
if(emi1.addrSize != emi2.addrSize)
|
|
|
|
return false;
|
|
|
|
if(emi1.stackSize != emi2.stackSize)
|
|
|
|
return false;
|
2009-08-03 20:01:40 +02:00
|
|
|
if(emi1.dispSize != emi2.dispSize)
|
|
|
|
return false;
|
2007-03-13 17:13:21 +01:00
|
|
|
return true;
|
|
|
|
}
|
2007-03-03 18:19:52 +01:00
|
|
|
|
2007-11-15 20:17:21 +01:00
|
|
|
struct CoreSpecific {
|
|
|
|
int core_type;
|
|
|
|
};
|
2007-03-03 17:01:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __ARCH_X86_TYPES_HH__
|