Deleted Added
sdiff udiff text old ( 4582:963ea0dcf174 ) new ( 4601:38c989d15fef )
full compact
1// -*- mode:c++ -*-
2
3// Copyright (c) 2007 The Hewlett-Packard Development Company
4// All rights reserved.
5//
6// Redistribution and use of this software in source and binary forms,
7// with or without modification, are permitted provided that the
8// following conditions are met:

--- 71 unchanged lines hidden (view full) ---

80 '\tdefault: %s\n' % new_blocks.decode_block
81 blocks.append(new_blocks)
82 blocks.decode_block += '}\n'
83 return blocks
84}};
85
86let {{
87 class OpType(object):
88 parser = re.compile(r"(?P<tag>[A-Z][A-Z]*)(?P<size>[a-z][a-z]*)|(r(?P<reg>[A-Z0-9]*)(?P<rsize>[a-z]*))")
89 def __init__(self, opTypeString):
90 match = OpType.parser.search(opTypeString)
91 if match == None:
92 raise Exception, "Problem parsing operand type %s" % opTypeString
93 self.reg = match.group("reg")
94 self.tag = match.group("tag")
95 self.size = match.group("size")
96 self.rsize = match.group("rsize")
97
98 ModRMRegIndex = "(MODRM_REG | (REX_R << 3))"
99 ModRMRMIndex = "(MODRM_RM | (REX_B << 3))"
100
101 # This function specializes the given piece of code to use a particular
102 # set of argument types described by "opTypes".
103 def specializeInst(Name, opTypes, env):
104 # print "Specializing %s with opTypes %s" % (Name, opTypes)
105 while len(opTypes):
106 # Parse the operand type string we're working with
107 opType = OpType(opTypes[0])
108
109 if opType.reg:
110 #Figure out what to do with fixed register operands
111 #This is the index to use, so we should stick it some place.
112 if opType.reg in ("A", "B", "C", "D"):
113 env.addReg("INTREG_R%sX" % opType.reg)
114 else:
115 env.addReg("INTREG_R%s" % opType.reg)
116 if opType.size:
117 if opType.rsize in ("l", "h", "b"):
118 print "byte"
119 elif opType.rsize == "x":
120 print "word"
121 else:
122 print "Didn't recognize fixed register size %s!" % opType.rsize
123 Name += "_R"
124 elif opType.tag == None or opType.size == None:
125 raise Exception, "Problem parsing operand tag: %s" % opType.tag
126 elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"):
127 # Use the "reg" field of the ModRM byte to select the register
128 env.addReg(ModRMRegIndex)
129 Name += "_R"
130 elif opType.tag in ("E", "Q", "W"):
131 # This might refer to memory or to a register. We need to
132 # divide it up farther.
133 regTypes = copy.copy(opTypes)
134 regTypes.pop(0)
135 regEnv = copy.copy(env)
136 regEnv.addReg(ModRMRMIndex)
137 regName = Name + "_R"
138 # This needs to refer to memory, but we'll fill in the details
139 # later. It needs to take into account unaligned memory
140 # addresses.
141 memTypes = copy.copy(opTypes)
142 memTypes.pop(0)
143 memEnv = copy.copy(env)
144 memName = Name + "_M"
145 print "%0"
146 return doSplitDecode(specializeInst, "MODRM_MOD",
147 {"3" : (regName, regTypes, regEnv)},
148 (memName, memTypes, memEnv))
149 elif opType.tag in ("I", "J"):
150 # Immediates
151 Name += "_I"
152 elif opType.tag == "M":
153 # This needs to refer to memory, but we'll fill in the details
154 # later. It needs to take into account unaligned memory
155 # addresses.
156 print "%0"
157 Name += "_M"
158 elif opType.tag in ("PR", "R", "VR"):
159 # There should probably be a check here to verify that mod
160 # is equal to 11b
161 env.addReg(ModRMRMIndex)
162 Name += "_R"
163 else:
164 raise Exception, "Unrecognized tag %s." % opType.tag
165 opTypes.pop(0)
166
167 # Generate code to return a macroop of the given name which will
168 # operate in the "emulation environment" env
169 return genMacroop(Name, env)
170}};