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]+)(?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]) |
108 opTypes.pop(0) |
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"): |
114 env.addReg("INTREG_R%sX | (REX_B << 3)" % opType.reg) |
115 else: |
116 env.addReg("INTREG_R%s | (REX_B << 3)" % opType.reg) |
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 |
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. |
139 regEnv = copy.copy(env) 140 regEnv.addReg(ModRMRMIndex) |
141 # This refers to memory. The macroop constructor should set up 142 # modrm addressing. |
143 memEnv = copy.copy(env) |
144 memEnv.doModRM = True |
145 return doSplitDecode(specializeInst, "MODRM_MOD", |
146 {"3" : (Name + "_R", copy.copy(opTypes), regEnv)}, 147 (Name + "_M", copy.copy(opTypes), memEnv)) |
148 elif opType.tag in ("I", "J"): 149 # Immediates 150 Name += "_I" |
151 elif opType.tag in ("PR", "R", "VR"): |
152 # Non register modrm settings should cause an error |
153 env.addReg(ModRMRMIndex) 154 Name += "_R" 155 else: 156 raise Exception, "Unrecognized tag %s." % opType.tag |
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}}; |