specialize.isa (4582:963ea0dcf174) | specialize.isa (4601:38c989d15fef) |
---|---|
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): | 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]*))") | 88 parser = re.compile(r"(?P<tag>[A-Z]+)(?P<size>[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]) | 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 opTypes.pop(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"): | 109 110 if opType.reg: 111 #Figure out what to do with fixed register operands 112 #This is the index to use, so we should stick it some place. 113 if opType.reg in ("A", "B", "C", "D"): |
113 env.addReg("INTREG_R%sX" % opType.reg) | 114 env.addReg("INTREG_R%sX | (REX_B << 3)" % opType.reg) |
114 else: | 115 else: |
115 env.addReg("INTREG_R%s" % opType.reg) | 116 env.addReg("INTREG_R%s | (REX_B << 3)" % 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" | 117 if opType.size: 118 if opType.rsize in ("l", "h", "b"): 119 print "byte" 120 elif opType.rsize == "x": 121 print "word" 122 else: 123 print "Didn't recognize fixed register size %s!" % opType.rsize 124 Name += "_R" |
125 elif opType.tag == "M": 126 # This refers to memory. The macroop constructor sets up modrm 127 # addressing. Non memory modrm settings should cause an error. 128 Name += "_M" 129 env.doModRM = True |
|
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. | 130 elif opType.tag == None or opType.size == None: 131 raise Exception, "Problem parsing operand tag: %s" % opType.tag 132 elif opType.tag in ("C", "D", "G", "P", "S", "T", "V"): 133 # Use the "reg" field of the ModRM byte to select the register 134 env.addReg(ModRMRegIndex) 135 Name += "_R" 136 elif opType.tag in ("E", "Q", "W"): 137 # This might refer to memory or to a register. We need to 138 # divide it up farther. |
133 regTypes = copy.copy(opTypes) 134 regTypes.pop(0) | |
135 regEnv = copy.copy(env) 136 regEnv.addReg(ModRMRMIndex) | 139 regEnv = copy.copy(env) 140 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) | 141 # This refers to memory. The macroop constructor should set up 142 # modrm addressing. |
143 memEnv = copy.copy(env) | 143 memEnv = copy.copy(env) |
144 memName = Name + "_M" 145 print "%0" | 144 memEnv.doModRM = True |
146 return doSplitDecode(specializeInst, "MODRM_MOD", | 145 return doSplitDecode(specializeInst, "MODRM_MOD", |
147 {"3" : (regName, regTypes, regEnv)}, 148 (memName, memTypes, memEnv)) | 146 {"3" : (Name + "_R", copy.copy(opTypes), regEnv)}, 147 (Name + "_M", copy.copy(opTypes), memEnv)) |
149 elif opType.tag in ("I", "J"): 150 # Immediates 151 Name += "_I" | 148 elif opType.tag in ("I", "J"): 149 # Immediates 150 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"): | 151 elif opType.tag in ("PR", "R", "VR"): |
159 # There should probably be a check here to verify that mod 160 # is equal to 11b | 152 # Non register modrm settings should cause an error |
161 env.addReg(ModRMRMIndex) 162 Name += "_R" 163 else: 164 raise Exception, "Unrecognized tag %s." % opType.tag | 153 env.addReg(ModRMRMIndex) 154 Name += "_R" 155 else: 156 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}}; | 157 158 # Generate code to return a macroop of the given name which will 159 # operate in the "emulation environment" env 160 return genMacroop(Name, env) 161}}; |