changeset 6d4161a36ca1 in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=6d4161a36ca1
description:
X86: Autogenerate macroop generateDisassemble function.
diffstat:
3 files changed, 7 insertions(+), 4 deletions(-)
src/arch/x86/insts/macroop.hh | 4 +++-
src/arch/x86/isa/macroop.isa | 1 -
src/arch/x86/isa/specialize.isa | 6 ++++--
diffs (truncated from 409 to 300 lines):
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/insts/macroop.hh
--- a/src/arch/x86/insts/macroop.hh Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/insts/macroop.hh Tue Jan 06 22:55:27 2009 -0800
@@ -65,17 +65,19 @@
namespace X86ISA
{
// Base class for combinationally generated macroops
-class MacroopBase : public StaticInst
+class MacroopBase : public X86StaticInst
{
protected:
+ const char *macrocodeBlock;
+
const uint32_t numMicroops;
- X86ISA::EmulEnv emulEnv;
+ X86ISA::EmulEnv env;
//Constructor.
MacroopBase(const char *mnem, ExtMachInst _machInst,
- uint32_t _numMicroops, X86ISA::EmulEnv _emulEnv)
- : StaticInst(mnem, _machInst, No_OpClass),
- numMicroops(_numMicroops), emulEnv(_emulEnv)
+ uint32_t _numMicroops, X86ISA::EmulEnv _env) :
+ X86StaticInst(mnem, _machInst, No_OpClass),
+ numMicroops(_numMicroops), env(_env)
{
assert(numMicroops);
microops = new StaticInstPtr[numMicroops];
@@ -95,8 +97,8 @@
return microops[microPC];
}
- std::string generateDisassembly(Addr pc,
- const SymbolTable *symtab) const
+ std::string
+ generateDisassembly(Addr pc, const SymbolTable *symtab) const
{
return mnemonic;
}
@@ -111,7 +113,7 @@
X86ISA::EmulEnv
getEmulEnv()
{
- return emulEnv;
+ return env;
}
};
}
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/macroop.isa
--- a/src/arch/x86/isa/macroop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/macroop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -76,8 +76,8 @@
{
public:
Macroop(const char *mnem, ExtMachInst _machInst,
- uint32_t _numMicroops, X86ISA::EmulEnv _emulEnv)
- : MacroopBase(mnem, _machInst, _numMicroops, _emulEnv)
+ uint32_t _numMicroops, X86ISA::EmulEnv _env)
+ : MacroopBase(mnem, _machInst, _numMicroops, _env)
{}
%(MacroExecPanic)s
};
@@ -102,22 +102,42 @@
%(declareLabels)s
public:
// Constructor.
- %(class_name)s(ExtMachInst machInst, X86ISA::EmulEnv env);
+ %(class_name)s(ExtMachInst machInst, X86ISA::EmulEnv _env);
+
+ std::string
+ generateDisassembly(Addr pc, const SymbolTable *symtab) const;
};
};
+}};
+
+def template MacroDisassembly {{
+ std::string
+ X86Macroop::%(class_name)s::generateDisassembly(Addr pc,
+ const SymbolTable *symtab) const
+ {
+ std::stringstream out;
+ out << mnemonic << "\t";
+
+ int regSize = %(regSize)s;
+ %(disassembly)s
+ // Shut up gcc.
+ regSize = regSize;
+ return out.str();
+ }
}};
// Basic instruction class constructor template.
def template MacroConstructor {{
inline X86Macroop::%(class_name)s::%(class_name)s(
- ExtMachInst machInst, EmulEnv env)
- : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s, env)
+ ExtMachInst machInst, EmulEnv _env)
+ : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s, _env)
{
%(adjust_env)s;
%(adjust_imm)s;
%(adjust_disp)s;
%(do_modrm)s;
%(constructor)s;
+ const char *macrocodeBlock = "%(class_name)s";
//alloc_microops is the code that sets up the microops
//array in the parent class.
%(alloc_microops)s;
@@ -158,7 +178,12 @@
adjustedDisp = adjustedDisp;
'''
def getAllocator(self, env):
- return "new X86Macroop::%s(machInst, %s)" % (self.name,
env.getAllocator())
+ return "new X86Macroop::%s(machInst, %s)" % \
+ (self.name, env.getAllocator())
+ def getMnemonic(self):
+ mnemonic = self.name.lower()
+ mnemonic = re.match(r'[^_]*', mnemonic).group(0)
+ return mnemonic
def getDeclaration(self):
#FIXME This first parameter should be the mnemonic. I need to
#write some code which pulls that out
@@ -166,12 +191,12 @@
for (label, microop) in self.labels.items():
declareLabels += "const static uint64_t label_%s = %d;\n" \
% (label, microop.micropc)
- iop = InstObjParams(self.name, self.name, "Macroop",
+ iop = InstObjParams(self.getMnemonic(), self.name, "Macroop",
{"code" : "",
"declareLabels" : declareLabels
})
return MacroDeclare.subst(iop);
- def getDefinition(self):
+ def getDefinition(self, env):
#FIXME This first parameter should be the mnemonic. I need to
#write some code which pulls that out
numMicroops = len(self.microops)
@@ -184,14 +209,28 @@
(micropc, op.getAllocator(True, not isLast,
micropc == 0, isLast))
micropc += 1
- iop = InstObjParams(self.name, self.name, "Macroop",
+ if env.useStackSize:
+ useStackSize = "true"
+ else:
+ useStackSize = "false"
+ if env.memoryInst:
+ memoryInst = "true"
+ else:
+ memoryInst = "false"
+ regSize = '''(%s || (env.base == INTREG_RSP && %s) ?
+ env.stackSize :
+ env.dataSize)''' % (useStackSize, memoryInst)
+ iop = InstObjParams(self.getMnemonic(), self.name, "Macroop",
{"code" : "", "num_microops" : numMicroops,
"alloc_microops" : allocMicroops,
"adjust_env" : self.adjust_env,
"adjust_imm" : self.adjust_imm,
"adjust_disp" : self.adjust_disp,
+ "disassembly" : env.disassembly,
+ "regSize" : regSize,
"do_modrm" : self.doModRM})
- return MacroConstructor.subst(iop);
+ return MacroConstructor.subst(iop) + \
+ MacroDisassembly.subst(iop);
}};
let {{
@@ -207,6 +246,16 @@
self.dataSize = "OPSIZE"
self.stackSize = "STACKSIZE"
self.doModRM = False
+ self.disassembly = ""
+ self.firstArgument = True
+ self.useStackSize = False
+ self.memoryInst = False
+
+ def addToDisassembly(self, code):
+ if not self.firstArgument:
+ self.disassembly += "out << \", \";\n"
+ self.firstArgument = False
+ self.disassembly += code
def getAllocator(self):
if self.size == 'b':
@@ -264,7 +313,7 @@
if env.doModRM:
macroop.doModRM = doModRMString
blocks.header_output = macroop.getDeclaration()
- blocks.decoder_output = macroop.getDefinition()
+ blocks.decoder_output = macroop.getDefinition(env)
macroop.declared = True
blocks.decode_block = "return %s;\n" % macroop.getAllocator(env)
return blocks
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/base.isa
--- a/src/arch/x86/isa/microops/base.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/base.isa Tue Jan 06 22:55:27 2009 -0800
@@ -76,7 +76,7 @@
StaticInstPtr
''' + generatorNameTemplate + '''(StaticInstPtr curMacroop)
{
- static const char * mnemonic = romMnemonic;
+ static const char *macrocodeBlock = romMnemonic;
static const ExtMachInst dummyExtMachInst;
static const EmulEnv dummyEmulEnv(0, 0, 1, 1, 1);
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/debug.isa
--- a/src/arch/x86/isa/microops/debug.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/debug.isa Tue Jan 06 22:55:27 2009 -0800
@@ -183,7 +183,7 @@
self.cond = "0"
def getAllocator(self, *microFlags):
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, "%(message)s", %(cc)s)''' % {
"class_name" : self.className,
"flags" : self.microFlagsText(microFlags),
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/fpop.isa
--- a/src/arch/x86/isa/microops/fpop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/fpop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -245,7 +245,7 @@
self.className += "Top"
def getAllocator(self, *microFlags):
- return '''new %(class_name)s(machInst, mnemonic
+ return '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(src1)s, %(src2)s, %(dest)s,
%(dataSize)s, %(spm)d)''' % {
"class_name" : self.className,
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/ldstop.isa
--- a/src/arch/x86/isa/microops/ldstop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/ldstop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -362,7 +362,7 @@
self.addressSize = addressSize
def getAllocator(self, *microFlags):
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(scale)s, %(index)s, %(base)s,
%(disp)s, %(segment)s, %(data)s,
%(dataSize)s, %(addressSize)s)''' % {
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/limmop.isa
--- a/src/arch/x86/isa/microops/limmop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/limmop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -154,7 +154,7 @@
self.dataSize = dataSize
def getAllocator(self, *microFlags):
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(dest)s, %(imm)s, %(dataSize)s)''' % {
"class_name" : self.className,
"mnemonic" : self.mnemonic,
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/regop.isa
--- a/src/arch/x86/isa/microops/regop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/regop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -438,7 +438,7 @@
className = self.className
if self.mnemonic == self.base_mnemonic + 'i':
className += "Imm"
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(src1)s, %(op2)s, %(dest)s,
%(dataSize)s, %(ext)s)''' % {
"class_name" : className,
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/seqop.isa
--- a/src/arch/x86/isa/microops/seqop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/seqop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -181,7 +181,7 @@
self.cond = "0"
def getAllocator(self, *microFlags):
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(target)s, %(cc)s)''' % {
"class_name" : self.className,
"flags" : self.microFlagsText(microFlags),
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/microops/specop.isa
--- a/src/arch/x86/isa/microops/specop.isa Tue Jan 06 22:46:28 2009 -0800
+++ b/src/arch/x86/isa/microops/specop.isa Tue Jan 06 22:55:27 2009 -0800
@@ -230,7 +230,7 @@
self.cond = "0"
def getAllocator(self, *microFlags):
- allocator = '''new %(class_name)s(machInst, mnemonic
+ allocator = '''new %(class_name)s(machInst, macrocodeBlock
%(flags)s, %(fault)s, %(cc)s)''' % {
"class_name" : self.className,
"flags" : self.microFlagsText(microFlags),
@@ -257,7 +257,7 @@
pass
def getAllocator(self, *microFlags):
- return "new MicroHalt(machInst, mnemonic %s)" % \
+ return "new MicroHalt(machInst, macrocodeBlock %s)" % \
self.microFlagsText(microFlags)
microopClasses["halt"] = Halt
diff -r e3a6f53818fe -r 6d4161a36ca1 src/arch/x86/isa/specialize.isa
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev