2006-05-22 20:29:33 +02:00
|
|
|
// Copyright (c) 2006 The Regents of The University of Michigan
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// 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: Ali Saidi
|
|
|
|
// Gabe Black
|
|
|
|
// Steve Reinhardt
|
|
|
|
|
2006-01-29 23:25:54 +01:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Base class for sparc instructions, and some support functions
|
|
|
|
//
|
|
|
|
|
|
|
|
output header {{
|
2006-03-07 10:33:10 +01:00
|
|
|
|
2006-03-17 20:02:38 +01:00
|
|
|
union CondCodes
|
2006-03-07 10:33:10 +01:00
|
|
|
{
|
2006-03-17 20:02:38 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint8_t c:1;
|
|
|
|
uint8_t v:1;
|
|
|
|
uint8_t z:1;
|
|
|
|
uint8_t n:1;
|
|
|
|
};
|
|
|
|
uint32_t bits;
|
2006-03-14 21:59:19 +01:00
|
|
|
};
|
2006-03-07 10:33:10 +01:00
|
|
|
|
2006-03-17 20:02:38 +01:00
|
|
|
enum CondTest
|
2006-03-07 10:33:10 +01:00
|
|
|
{
|
|
|
|
Always=0x8,
|
|
|
|
Never=0x0,
|
|
|
|
NotEqual=0x9,
|
|
|
|
Equal=0x1,
|
|
|
|
Greater=0xA,
|
|
|
|
LessOrEqual=0x2,
|
|
|
|
GreaterOrEqual=0xB,
|
|
|
|
Less=0x3,
|
|
|
|
GreaterUnsigned=0xC,
|
|
|
|
LessOrEqualUnsigned=0x4,
|
|
|
|
CarryClear=0xD,
|
|
|
|
CarrySet=0x5,
|
|
|
|
Positive=0xE,
|
|
|
|
Negative=0x6,
|
|
|
|
OverflowClear=0xF,
|
|
|
|
OverflowSet=0x7
|
2006-03-14 21:59:19 +01:00
|
|
|
};
|
2006-03-07 10:33:10 +01:00
|
|
|
|
2006-04-18 15:27:22 +02:00
|
|
|
extern char * CondTestAbbrev[];
|
|
|
|
|
2006-01-29 23:25:54 +01:00
|
|
|
/**
|
|
|
|
* Base class for all SPARC static instructions.
|
|
|
|
*/
|
2006-03-07 10:33:10 +01:00
|
|
|
class SparcStaticInst : public StaticInst
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
2006-03-07 10:33:10 +01:00
|
|
|
protected:
|
|
|
|
// Constructor.
|
|
|
|
SparcStaticInst(const char *mnem,
|
2006-10-16 21:52:14 +02:00
|
|
|
ExtMachInst _machInst, OpClass __opClass)
|
2006-03-07 10:33:10 +01:00
|
|
|
: StaticInst(mnem, _machInst, __opClass)
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
std::string generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const;
|
2006-03-16 19:58:50 +01:00
|
|
|
|
2006-07-21 03:01:57 +02:00
|
|
|
void printReg(std::ostream &os, int reg) const;
|
2006-07-19 08:07:00 +02:00
|
|
|
void printSrcReg(std::ostream &os, int reg) const;
|
|
|
|
void printDestReg(std::ostream &os, int reg) const;
|
|
|
|
|
|
|
|
void printRegArray(std::ostream &os,
|
|
|
|
const RegIndex indexArray[], int num) const;
|
2006-01-29 23:25:54 +01:00
|
|
|
};
|
|
|
|
|
2006-03-17 20:02:38 +01:00
|
|
|
bool passesCondition(uint32_t codes, uint32_t condition);
|
2006-04-01 03:31:53 +02:00
|
|
|
|
|
|
|
inline int64_t sign_ext(uint64_t data, int origWidth)
|
|
|
|
{
|
2006-04-06 20:52:44 +02:00
|
|
|
int shiftAmount = 64 - origWidth;
|
2006-04-01 03:31:53 +02:00
|
|
|
return (((int64_t)data) << shiftAmount) >> shiftAmount;
|
|
|
|
}
|
2006-03-17 20:02:38 +01:00
|
|
|
}};
|
|
|
|
|
2006-04-18 15:27:22 +02:00
|
|
|
output decoder {{
|
|
|
|
|
|
|
|
char * CondTestAbbrev[] =
|
|
|
|
{
|
|
|
|
"nev", //Never
|
|
|
|
"e", //Equal
|
|
|
|
"le", //Less or Equal
|
|
|
|
"l", //Less
|
|
|
|
"leu", //Less or Equal Unsigned
|
|
|
|
"c", //Carry set
|
|
|
|
"n", //Negative
|
|
|
|
"o", //Overflow set
|
|
|
|
"a", //Always
|
|
|
|
"ne", //Not Equal
|
|
|
|
"g", //Greater
|
|
|
|
"ge", //Greater or Equal
|
|
|
|
"gu", //Greater Unsigned
|
|
|
|
"cc", //Carry clear
|
|
|
|
"p", //Positive
|
|
|
|
"oc" //Overflow Clear
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2006-03-17 20:02:38 +01:00
|
|
|
def template ROrImmDecode {{
|
|
|
|
{
|
|
|
|
return (I ? (SparcStaticInst *)(new %(class_name)sImm(machInst))
|
|
|
|
: (SparcStaticInst *)(new %(class_name)s(machInst)));
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
let {{
|
|
|
|
def splitOutImm(code):
|
2006-05-15 05:56:16 +02:00
|
|
|
matcher = re.compile(r'Rs(?P<rNum>\d)_or_imm(?P<iNum>\d+)(?P<typeQual>\.\w+)?')
|
2006-03-17 20:02:38 +01:00
|
|
|
rOrImmMatch = matcher.search(code)
|
|
|
|
if (rOrImmMatch == None):
|
2006-04-01 03:31:53 +02:00
|
|
|
return (False, code, '', '', '')
|
|
|
|
rString = rOrImmMatch.group("rNum")
|
2006-05-15 05:56:16 +02:00
|
|
|
if (rOrImmMatch.group("typeQual") != None):
|
|
|
|
rString += rOrImmMatch.group("typeQual")
|
2006-04-01 03:31:53 +02:00
|
|
|
iString = rOrImmMatch.group("iNum")
|
2006-03-17 20:02:38 +01:00
|
|
|
orig_code = code
|
2006-05-15 05:56:16 +02:00
|
|
|
code = matcher.sub('Rs' + rString, orig_code)
|
2006-03-17 20:02:38 +01:00
|
|
|
imm_code = matcher.sub('imm', orig_code)
|
2006-04-01 03:31:53 +02:00
|
|
|
return (True, code, imm_code, rString, iString)
|
2006-01-29 23:25:54 +01:00
|
|
|
}};
|
|
|
|
|
|
|
|
output decoder {{
|
|
|
|
|
2006-04-01 03:31:53 +02:00
|
|
|
inline void printMnemonic(std::ostream &os, const char * mnemonic)
|
|
|
|
{
|
|
|
|
ccprintf(os, "\t%s ", mnemonic);
|
|
|
|
}
|
|
|
|
|
2006-07-19 08:07:00 +02:00
|
|
|
void SparcStaticInst::printRegArray(std::ostream &os,
|
|
|
|
const RegIndex indexArray[], int num) const
|
|
|
|
{
|
|
|
|
if(num <= 0)
|
|
|
|
return;
|
|
|
|
printReg(os, indexArray[0]);
|
|
|
|
for(int x = 1; x < num; x++)
|
|
|
|
{
|
|
|
|
os << ", ";
|
|
|
|
printReg(os, indexArray[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SparcStaticInst::printSrcReg(std::ostream &os, int reg) const
|
|
|
|
{
|
|
|
|
if(_numSrcRegs > reg)
|
|
|
|
printReg(os, _srcRegIdx[reg]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SparcStaticInst::printDestReg(std::ostream &os, int reg) const
|
|
|
|
{
|
|
|
|
if(_numDestRegs > reg)
|
|
|
|
printReg(os, _destRegIdx[reg]);
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:58:50 +01:00
|
|
|
void
|
2006-07-21 03:01:57 +02:00
|
|
|
SparcStaticInst::printReg(std::ostream &os, int reg) const
|
2006-03-16 19:58:50 +01:00
|
|
|
{
|
2006-04-01 03:31:53 +02:00
|
|
|
const int MaxGlobal = 8;
|
|
|
|
const int MaxOutput = 16;
|
|
|
|
const int MaxLocal = 24;
|
|
|
|
const int MaxInput = 32;
|
2006-11-10 21:25:52 +01:00
|
|
|
const int MaxMicroReg = 33;
|
2006-04-01 03:31:53 +02:00
|
|
|
if (reg == FramePointerReg)
|
|
|
|
ccprintf(os, "%%fp");
|
|
|
|
else if (reg == StackPointerReg)
|
|
|
|
ccprintf(os, "%%sp");
|
|
|
|
else if(reg < MaxGlobal)
|
|
|
|
ccprintf(os, "%%g%d", reg);
|
|
|
|
else if(reg < MaxOutput)
|
|
|
|
ccprintf(os, "%%o%d", reg - MaxGlobal);
|
|
|
|
else if(reg < MaxLocal)
|
|
|
|
ccprintf(os, "%%l%d", reg - MaxOutput);
|
|
|
|
else if(reg < MaxInput)
|
|
|
|
ccprintf(os, "%%i%d", reg - MaxLocal);
|
2006-11-10 21:25:52 +01:00
|
|
|
else if(reg < MaxMicroReg)
|
|
|
|
ccprintf(os, "%%u%d", reg - MaxInput);
|
2006-03-16 19:58:50 +01:00
|
|
|
else {
|
2006-04-01 03:31:53 +02:00
|
|
|
ccprintf(os, "%%f%d", reg - FP_Base_DepTag);
|
2006-03-16 19:58:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
std::string SparcStaticInst::generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
2006-03-07 10:33:10 +01:00
|
|
|
std::stringstream ss;
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-04-01 03:31:53 +02:00
|
|
|
printMnemonic(ss, mnemonic);
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
// just print the first two source regs... if there's
|
|
|
|
// a third one, it's a read-modify-write dest (Rc),
|
|
|
|
// e.g. for CMOVxx
|
|
|
|
if(_numSrcRegs > 0)
|
|
|
|
{
|
|
|
|
printReg(ss, _srcRegIdx[0]);
|
|
|
|
}
|
|
|
|
if(_numSrcRegs > 1)
|
|
|
|
{
|
|
|
|
ss << ",";
|
|
|
|
printReg(ss, _srcRegIdx[1]);
|
|
|
|
}
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
// just print the first dest... if there's a second one,
|
|
|
|
// it's generally implicit
|
|
|
|
if(_numDestRegs > 0)
|
|
|
|
{
|
|
|
|
if(_numSrcRegs > 0)
|
|
|
|
ss << ",";
|
|
|
|
printReg(ss, _destRegIdx[0]);
|
|
|
|
}
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
return ss.str();
|
2006-01-29 23:25:54 +01:00
|
|
|
}
|
|
|
|
|
2006-03-17 20:02:38 +01:00
|
|
|
bool passesCondition(uint32_t codes, uint32_t condition)
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
2006-03-17 20:02:38 +01:00
|
|
|
CondCodes condCodes;
|
2006-11-11 02:17:42 +01:00
|
|
|
condCodes.bits = 0;
|
|
|
|
condCodes.c = codes & 0x1 ? 1 : 0;
|
|
|
|
condCodes.v = codes & 0x2 ? 1 : 0;
|
|
|
|
condCodes.z = codes & 0x4 ? 1 : 0;
|
|
|
|
condCodes.n = codes & 0x8 ? 1 : 0;
|
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
switch(condition)
|
|
|
|
{
|
|
|
|
case Always:
|
|
|
|
return true;
|
|
|
|
case Never:
|
|
|
|
return false;
|
|
|
|
case NotEqual:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !condCodes.z;
|
2006-03-07 10:33:10 +01:00
|
|
|
case Equal:
|
2006-03-17 20:02:38 +01:00
|
|
|
return condCodes.z;
|
2006-03-07 10:33:10 +01:00
|
|
|
case Greater:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !(condCodes.z | (condCodes.n ^ condCodes.v));
|
2006-03-07 10:33:10 +01:00
|
|
|
case LessOrEqual:
|
2006-03-17 20:02:38 +01:00
|
|
|
return condCodes.z | (condCodes.n ^ condCodes.v);
|
2006-03-07 10:33:10 +01:00
|
|
|
case GreaterOrEqual:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !(condCodes.n ^ condCodes.v);
|
2006-03-07 10:33:10 +01:00
|
|
|
case Less:
|
2006-03-17 20:02:38 +01:00
|
|
|
return (condCodes.n ^ condCodes.v);
|
2006-03-07 10:33:10 +01:00
|
|
|
case GreaterUnsigned:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !(condCodes.c | condCodes.z);
|
2006-03-07 10:33:10 +01:00
|
|
|
case LessOrEqualUnsigned:
|
2006-03-17 20:02:38 +01:00
|
|
|
return (condCodes.c | condCodes.z);
|
2006-03-07 10:33:10 +01:00
|
|
|
case CarryClear:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !condCodes.c;
|
2006-03-07 10:33:10 +01:00
|
|
|
case CarrySet:
|
2006-03-17 20:02:38 +01:00
|
|
|
return condCodes.c;
|
2006-03-07 10:33:10 +01:00
|
|
|
case Positive:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !condCodes.n;
|
2006-03-07 10:33:10 +01:00
|
|
|
case Negative:
|
2006-03-17 20:02:38 +01:00
|
|
|
return condCodes.n;
|
2006-03-07 10:33:10 +01:00
|
|
|
case OverflowClear:
|
2006-03-17 20:02:38 +01:00
|
|
|
return !condCodes.v;
|
2006-03-07 10:33:10 +01:00
|
|
|
case OverflowSet:
|
2006-03-17 20:02:38 +01:00
|
|
|
return condCodes.v;
|
2006-03-07 10:33:10 +01:00
|
|
|
}
|
2006-03-16 19:58:50 +01:00
|
|
|
panic("Tried testing condition nonexistant "
|
|
|
|
"condition code %d", condition);
|
2006-01-29 23:25:54 +01:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|