macroop.isa (4587:2c9a2534a489) | macroop.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: --- 97 unchanged lines hidden (view full) --- 106 { 107 return mnemonic; 108 } 109 110 %(MacroExecPanic)s 111 }; 112}}; 113 | 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: --- 97 unchanged lines hidden (view full) --- 106 { 107 return mnemonic; 108 } 109 110 %(MacroExecPanic)s 111 }; 112}}; 113 |
114////////////////////////////////////////////////////////////////////////////// 115// 116// X86 specific 117// 118////////////////////////////////////////////////////////////////////////////// 119 |
|
114// Basic instruction class declaration template. 115def template MacroDeclare {{ 116 namespace X86Macroop 117 { 118 /** 119 * Static instruction class for "%(mnemonic)s". 120 */ 121 class %(class_name)s : public %(base_class)s 122 { 123 public: 124 // Constructor. | 120// Basic instruction class declaration template. 121def template MacroDeclare {{ 122 namespace X86Macroop 123 { 124 /** 125 * Static instruction class for "%(mnemonic)s". 126 */ 127 class %(class_name)s : public %(base_class)s 128 { 129 public: 130 // Constructor. |
125 %(class_name)s(ExtMachInst machInst, EmulEnv env); | 131 %(class_name)s(ExtMachInst machInst, X86ISA::EmulEnv env); |
126 }; 127 }; 128}}; 129 130// Basic instruction class constructor template. 131def template MacroConstructor {{ | 132 }; 133 }; 134}}; 135 136// Basic instruction class constructor template. 137def template MacroConstructor {{ |
132 inline X86Macroop::%(class_name)s::%(class_name)s(ExtMachInst machInst, EmulEnv env) | 138 inline X86Macroop::%(class_name)s::%(class_name)s( 139 ExtMachInst machInst, EmulEnv env) |
133 : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s) 134 { 135 %(adjust_env)s; | 140 : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s) 141 { 142 %(adjust_env)s; |
143 %(do_modrm)s; |
|
136 %(constructor)s; 137 //alloc_microops is the code that sets up the microops 138 //array in the parent class. 139 %(alloc_microops)s; 140 } 141}}; 142 | 144 %(constructor)s; 145 //alloc_microops is the code that sets up the microops 146 //array in the parent class. 147 %(alloc_microops)s; 148 } 149}}; 150 |
143////////////////////////////////////////////////////////////////////////////// 144// 145// X86 specific 146// 147 | |
148let {{ 149 from micro_asm import Combinational_Macroop, Rom_Macroop 150 class X86Macroop(Combinational_Macroop): 151 def setAdjustEnv(self, val): 152 self.adjust_env = val 153 def __init__(self, name): 154 super(X86Macroop, self).__init__(name) 155 self.directives = { 156 "adjust_env" : self.setAdjustEnv 157 } 158 self.declared = False 159 self.adjust_env = "" | 151let {{ 152 from micro_asm import Combinational_Macroop, Rom_Macroop 153 class X86Macroop(Combinational_Macroop): 154 def setAdjustEnv(self, val): 155 self.adjust_env = val 156 def __init__(self, name): 157 super(X86Macroop, self).__init__(name) 158 self.directives = { 159 "adjust_env" : self.setAdjustEnv 160 } 161 self.declared = False 162 self.adjust_env = "" |
163 self.doModRM = "" |
|
160 def getAllocator(self, env): 161 return "new X86Macroop::%s(machInst, %s)" % (self.name, env.getAllocator()) 162 def getDeclaration(self): 163 #FIXME This first parameter should be the mnemonic. I need to 164 #write some code which pulls that out 165 iop = InstObjParams(self.name, self.name, "Macroop", {"code" : ""}) 166 return MacroDeclare.subst(iop); 167 def getDefinition(self): --- 7 unchanged lines hidden (view full) --- 175 "microops[%d] = %s;\n" % \ 176 (micropc, op.getAllocator(True, False, 177 micropc == 0, 178 micropc == numMicroops - 1)) 179 micropc += 1 180 iop = InstObjParams(self.name, self.name, "Macroop", 181 {"code" : "", "num_microops" : numMicroops, 182 "alloc_microops" : allocMicroops, | 164 def getAllocator(self, env): 165 return "new X86Macroop::%s(machInst, %s)" % (self.name, env.getAllocator()) 166 def getDeclaration(self): 167 #FIXME This first parameter should be the mnemonic. I need to 168 #write some code which pulls that out 169 iop = InstObjParams(self.name, self.name, "Macroop", {"code" : ""}) 170 return MacroDeclare.subst(iop); 171 def getDefinition(self): --- 7 unchanged lines hidden (view full) --- 179 "microops[%d] = %s;\n" % \ 180 (micropc, op.getAllocator(True, False, 181 micropc == 0, 182 micropc == numMicroops - 1)) 183 micropc += 1 184 iop = InstObjParams(self.name, self.name, "Macroop", 185 {"code" : "", "num_microops" : numMicroops, 186 "alloc_microops" : allocMicroops, |
183 "adjust_env" : self.adjust_env}) | 187 "adjust_env" : self.adjust_env, 188 "do_modrm" : self.doModRM}) |
184 return MacroConstructor.subst(iop); 185}}; 186 | 189 return MacroConstructor.subst(iop); 190}}; 191 |
187output header {{ 188 struct EmulEnv 189 { 190 X86ISA::RegIndex reg; 191 X86ISA::RegIndex regm; 192 uint8_t scale; 193 X86ISA::RegIndex index; 194 X86ISA::RegIndex base; 195 int dataSize; 196 int addressSize; 197 int stackSize; 198 199 EmulEnv(X86ISA::RegIndex _reg, X86ISA::RegIndex _regm, 200 int _dataSize, int _addressSize, int _stackSize) : 201 reg(_reg), regm(_regm), 202 dataSize(_dataSize), addressSize(_addressSize), 203 stackSize(_stackSize) 204 {;} 205 }; 206}}; 207 | |
208let {{ 209 class EmulEnv(object): 210 def __init__(self): 211 self.reg = "0" 212 self.regUsed = False 213 self.regm = "0" 214 self.regmUsed = False 215 self.addressSize = "ADDRSIZE" 216 self.dataSize = "OPSIZE" 217 self.stackSize = "STACKSIZE" | 192let {{ 193 class EmulEnv(object): 194 def __init__(self): 195 self.reg = "0" 196 self.regUsed = False 197 self.regm = "0" 198 self.regmUsed = False 199 self.addressSize = "ADDRSIZE" 200 self.dataSize = "OPSIZE" 201 self.stackSize = "STACKSIZE" |
202 self.doModRM = False 203 |
|
218 def getAllocator(self): 219 return '''EmulEnv(%(reg)s, 220 %(regm)s, 221 %(dataSize)s, 222 %(addressSize)s, 223 %(stackSize)s)''' % \ 224 self.__dict__ 225 def addReg(self, reg): 226 if not self.regUsed: 227 self.reg = reg 228 self.regUsed = True 229 elif not self.regmUsed: 230 self.regm = reg 231 self.regmUsed = True 232 else: 233 raise Exception, "EmulEnv is out of register specialization spots." 234}}; 235 236let {{ | 204 def getAllocator(self): 205 return '''EmulEnv(%(reg)s, 206 %(regm)s, 207 %(dataSize)s, 208 %(addressSize)s, 209 %(stackSize)s)''' % \ 210 self.__dict__ 211 def addReg(self, reg): 212 if not self.regUsed: 213 self.reg = reg 214 self.regUsed = True 215 elif not self.regmUsed: 216 self.regm = reg 217 self.regmUsed = True 218 else: 219 raise Exception, "EmulEnv is out of register specialization spots." 220}}; 221 222let {{ |
223 doModRMString = "env.doModRM(machInst);\n" |
|
237 def genMacroop(Name, env): 238 blocks = OutputBlocks() 239 if not macroopDict.has_key(Name): 240 raise Exception, "Unrecognized instruction: %s" % Name 241 macroop = macroopDict[Name] 242 if not macroop.declared: | 224 def genMacroop(Name, env): 225 blocks = OutputBlocks() 226 if not macroopDict.has_key(Name): 227 raise Exception, "Unrecognized instruction: %s" % Name 228 macroop = macroopDict[Name] 229 if not macroop.declared: |
230 if env.doModRM: 231 macroop.doModRM = doModRMString |
|
243 blocks.header_output = macroop.getDeclaration() 244 blocks.decoder_output = macroop.getDefinition() 245 macroop.declared = True 246 blocks.decode_block = "return %s;\n" % macroop.getAllocator(env) 247 return blocks 248}}; | 232 blocks.header_output = macroop.getDeclaration() 233 blocks.decoder_output = macroop.getDefinition() 234 macroop.declared = True 235 blocks.decode_block = "return %s;\n" % macroop.getAllocator(env) 236 return blocks 237}}; |