Deleted Added
sdiff udiff text old ( 4587:2c9a2534a489 ) 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:

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

106 {
107 return mnemonic;
108 }
109
110 %(MacroExecPanic)s
111 };
112}};
113
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.
125 %(class_name)s(ExtMachInst machInst, EmulEnv env);
126 };
127 };
128}};
129
130// Basic instruction class constructor template.
131def template MacroConstructor {{
132 inline X86Macroop::%(class_name)s::%(class_name)s(ExtMachInst machInst, EmulEnv env)
133 : %(base_class)s("%(mnemonic)s", machInst, %(num_microops)s)
134 {
135 %(adjust_env)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
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 = ""
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,
183 "adjust_env" : self.adjust_env})
184 return MacroConstructor.subst(iop);
185}};
186
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"
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 {{
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:
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}};