def format MultiInst(switchVal, *opTypeSets) {{
switcher = {}
for (count, opTypeSet) in zip(xrange(len(opTypeSets)), opTypeSets):
- switcher[count] = (opTypeSet, EmulEnv())
- blocks = doSplitDecode(Name, specializeInst, switchVal, switcher)
+ switcher[count] = (Name, opTypeSet, EmulEnv())
+ blocks = doSplitDecode(specializeInst, switchVal, switcher)
(header_output, decoder_output,
decode_block, exec_output) = blocks.makeList()
}};
# Authors: Gabe Black
microcode = '''
-def macroop XOR
+def macroop XOR_R_R
{
xor "env.reg", "env.reg", "env.regm"
};
+
+def macroop XOR_R_I
+{
+ limm "NUM_INTREGS", "env.immediate"
+ xor "env.reg", "env.reg", "NUM_INTREGS"
+};
+
+def macroop XOR_M_R
+{
+ #Do a load to get one of the sources
+ xor "NUM_INTREGS", "NUM_INTREGS", "env.reg"
+ #Do a store to write the destination
+};
+
+def macroop XOR_R_M
+{
+ #Do a load to get one of the sources
+ xor "env.reg", "env.reg", "NUM_INTREGS"
+};
+
+def macroop AND_R_I
+{
+ limm "NUM_INTREGS", "env.immediate"
+ and "env.reg", "env.reg", "NUM_INTREGS"
+};
+
+def macroop AND_M_I
+{
+ #Do a load to get one of the sources
+ limm "NUM_INTREGS", "env.immediate"
+ and "NUM_INTREGS", "NUM_INTREGS", "NUM_INTREGS+1"
+ #Do a store to write the destination
+};
'''
#let {{
#microcodeString = '''
# vals is a dict which matches case values with what should be decoded to.
# builder is called on the exploded contents of "vals" values to generate
# whatever code should be used.
- def doSplitDecode(Name, builder, switchVal, vals, default = None):
+ def doSplitDecode(builder, switchVal, vals, default = None):
blocks = OutputBlocks()
blocks.decode_block = 'switch(%s) {\n' % switchVal
for (val, todo) in vals.items():
- new_blocks = builder(Name, *todo)
+ new_blocks = builder(*todo)
new_blocks.decode_block = \
'\tcase %s: %s\n' % (val, new_blocks.decode_block)
blocks.append(new_blocks)
if default:
- new_blocks = builder(Name, *default)
+ new_blocks = builder(*default)
new_blocks.decode_block = \
'\tdefault: %s\n' % new_blocks.decode_block
blocks.append(new_blocks)
print "word"
else:
print "Didn't recognize fixed register size %s!" % opType.rsize
+ Name += "_R"
elif opType.tag == None or opType.size == None:
raise Exception, "Problem parsing operand tag: %s" % opType.tag
elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"):
# Use the "reg" field of the ModRM byte to select the register
env.addReg(ModRMRegIndex)
+ Name += "_R"
elif opType.tag in ("E", "Q", "W"):
# This might refer to memory or to a register. We need to
# divide it up farther.
regTypes.pop(0)
regEnv = copy.copy(env)
regEnv.addReg(ModRMRMIndex)
+ regName = Name + "_R"
# This needs to refer to memory, but we'll fill in the details
# later. It needs to take into account unaligned memory
# addresses.
memTypes = copy.copy(opTypes)
memTypes.pop(0)
memEnv = copy.copy(env)
+ memName = Name + "_M"
print "%0"
- return doSplitDecode(Name, specializeInst, "MODRM_MOD",
- {"3" : (regTypes, regEnv)}, (memTypes, memEnv))
+ return doSplitDecode(specializeInst, "MODRM_MOD",
+ {"3" : (regName, regTypes, regEnv)},
+ (memName, memTypes, memEnv))
elif opType.tag in ("I", "J"):
# Immediates
print "IMMEDIATE"
+ Name += "_I"
elif opType.tag == "M":
# This needs to refer to memory, but we'll fill in the details
# later. It needs to take into account unaligned memory
# addresses.
print "%0"
+ Name += "_M"
elif opType.tag in ("PR", "R", "VR"):
# There should probably be a check here to verify that mod
# is equal to 11b
env.addReg(ModRMRMIndex)
+ Name += "_R"
else:
raise Exception, "Unrecognized tag %s." % opType.tag
opTypes.pop(0)