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
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);
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)
140 : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s)
141 {
142 %(adjust_env)s;
143 %(do_modrm)s;
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
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 = ""
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})
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
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
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"
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
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}};