1 // Copyright (c) 2007-2008 The Hewlett-Packard Development Company
2 // All rights reserved.
4 // The license below extends only to copyright in the software and shall
5 // not be construed as granting a license to any other intellectual
6 // property including but not limited to intellectual property relating
7 // to a hardware implementation of the functionality of the software
8 // licensed hereunder. You may use the software subject to the license
9 // terms below provided that you ensure that this notice is replicated
10 // unmodified and in its entirety in all distributions of the software,
11 // modified or unmodified, in source code or in binary form.
13 // Copyright (c) 2008 The Regents of The University of Michigan
14 // All rights reserved.
16 // Redistribution and use in source and binary forms, with or without
17 // modification, are permitted provided that the following conditions are
18 // met: redistributions of source code must retain the above copyright
19 // notice, this list of conditions and the following disclaimer;
20 // redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution;
23 // neither the name of the copyright holders nor the names of its
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
27 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 // Authors: Gabe Black
41 //////////////////////////////////////////////////////////////////////////
43 // LdStOp Microop templates
45 //////////////////////////////////////////////////////////////////////////
49 def template MicroLeaExecute {{
50 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
51 Trace::InstRecord *traceData) const
53 Fault fault = NoFault;
59 DPRINTF(X86, "%s : %s: The address is %#x\n", instMnem, mnemonic, EA);
71 def template MicroLeaDeclare {{
72 class %(class_name)s : public %(base_class)s
75 %(class_name)s(ExtMachInst _machInst,
76 const char * instMnem, uint64_t setFlags,
77 uint8_t _scale, InstRegIndex _index, InstRegIndex _base,
78 uint64_t _disp, InstRegIndex _segment,
80 uint8_t _dataSize, uint8_t _addressSize,
81 Request::FlagsType _memFlags);
89 def template MicroLoadExecute {{
90 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
91 Trace::InstRecord *traceData) const
93 Fault fault = NoFault;
99 DPRINTF(X86, "%s : %s: The address is %#x\n", instMnem, mnemonic, EA);
101 fault = read(xc, EA, Mem, memFlags);
103 if (fault == NoFault) {
105 } else if (memFlags & Request::PREFETCH) {
106 // For prefetches, ignore any faults/exceptions.
118 def template MicroLoadInitiateAcc {{
119 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc,
120 Trace::InstRecord * traceData) const
122 Fault fault = NoFault;
128 DPRINTF(X86, "%s : %s: The address is %#x\n", instMnem, mnemonic, EA);
130 fault = read(xc, EA, Mem, memFlags);
136 def template MicroLoadCompleteAcc {{
137 Fault %(class_name)s::completeAcc(PacketPtr pkt,
138 %(CPU_exec_context)s * xc,
139 Trace::InstRecord * traceData) const
141 Fault fault = NoFault;
161 def template MicroStoreExecute {{
162 Fault %(class_name)s::execute(%(CPU_exec_context)s * xc,
163 Trace::InstRecord *traceData) const
165 Fault fault = NoFault;
171 DPRINTF(X86, "%s : %s: The address is %#x\n", instMnem, mnemonic, EA);
177 fault = write(xc, Mem, EA, memFlags);
189 def template MicroStoreInitiateAcc {{
190 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc,
191 Trace::InstRecord * traceData) const
193 Fault fault = NoFault;
199 DPRINTF(X86, "%s : %s: The address is %#x\n", instMnem, mnemonic, EA);
205 write(xc, Mem, EA, memFlags);
211 def template MicroStoreCompleteAcc {{
212 Fault %(class_name)s::completeAcc(PacketPtr pkt,
213 %(CPU_exec_context)s * xc, Trace::InstRecord * traceData) const
225 //This delcares the initiateAcc function in memory operations
226 def template InitiateAccDeclare {{
227 Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
230 //This declares the completeAcc function in memory operations
231 def template CompleteAccDeclare {{
232 Fault completeAcc(PacketPtr, %(CPU_exec_context)s *, Trace::InstRecord *) const;
235 def template MicroLdStOpDeclare {{
236 class %(class_name)s : public %(base_class)s
239 %(class_name)s(ExtMachInst _machInst,
240 const char * instMnem, uint64_t setFlags,
241 uint8_t _scale, InstRegIndex _index, InstRegIndex _base,
242 uint64_t _disp, InstRegIndex _segment,
244 uint8_t _dataSize, uint8_t _addressSize,
245 Request::FlagsType _memFlags);
249 %(InitiateAccDeclare)s
251 %(CompleteAccDeclare)s
255 def template MicroLdStOpConstructor {{
256 inline %(class_name)s::%(class_name)s(
257 ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
258 uint8_t _scale, InstRegIndex _index, InstRegIndex _base,
259 uint64_t _disp, InstRegIndex _segment,
261 uint8_t _dataSize, uint8_t _addressSize,
262 Request::FlagsType _memFlags) :
263 %(base_class)s(machInst, "%(mnemonic)s", instMnem, setFlags,
264 _scale, _index, _base,
265 _disp, _segment, _data,
266 _dataSize, _addressSize, _memFlags, %(op_class)s)
273 class LdStOp(X86Microop):
274 def __init__(self, data, segment, addr, disp,
275 dataSize, addressSize, baseFlags, atCPL0, prefetch):
277 [self.scale, self.index, self.base] = addr
279 self.segment = segment
280 self.dataSize = dataSize
281 self.addressSize = addressSize
282 self.memFlags = baseFlags
284 self.memFlags += " | (CPL0FlagBit << FlagShift)"
286 self.memFlags += " | Request::PREFETCH"
287 self.memFlags += " | (machInst.legacy.addr ? " + \
288 "(AddrSizeFlagBit << FlagShift) : 0)"
290 def getAllocator(self, microFlags):
291 allocator = '''new %(class_name)s(machInst, macrocodeBlock,
292 %(flags)s, %(scale)s, %(index)s, %(base)s,
293 %(disp)s, %(segment)s, %(data)s,
294 %(dataSize)s, %(addressSize)s, %(memFlags)s)''' % {
295 "class_name" : self.className,
296 "flags" : self.microFlagsText(microFlags),
297 "scale" : self.scale, "index" : self.index,
300 "segment" : self.segment, "data" : self.data,
301 "dataSize" : self.dataSize, "addressSize" : self.addressSize,
302 "memFlags" : self.memFlags}
308 # Make these empty strings so that concatenating onto
309 # them will always work.
315 EA = bits(SegBase + scale * Index + Base + disp, addressSize * 8 - 1, 0);
318 def defineMicroLoadOp(mnemonic, code, mem_flags="0"):
320 global decoder_output
322 global microopClasses
324 name = mnemonic.lower()
326 # Build up the all register version of this micro op
327 iop = InstObjParams(name, Name, 'X86ISA::LdStOp',
329 "ea_code": calculateEA})
330 header_output += MicroLdStOpDeclare.subst(iop)
331 decoder_output += MicroLdStOpConstructor.subst(iop)
332 exec_output += MicroLoadExecute.subst(iop)
333 exec_output += MicroLoadInitiateAcc.subst(iop)
334 exec_output += MicroLoadCompleteAcc.subst(iop)
336 class LoadOp(LdStOp):
337 def __init__(self, data, segment, addr, disp = 0,
338 dataSize="env.dataSize",
339 addressSize="env.addressSize",
340 atCPL0=False, prefetch=False):
341 super(LoadOp, self).__init__(data, segment, addr,
342 disp, dataSize, addressSize, mem_flags,
344 self.className = Name
347 microopClasses[name] = LoadOp
349 defineMicroLoadOp('Ld', 'Data = merge(Data, Mem, dataSize);')
350 defineMicroLoadOp('Ldst', 'Data = merge(Data, Mem, dataSize);',
351 '(StoreCheck << FlagShift)')
352 defineMicroLoadOp('Ldstl', 'Data = merge(Data, Mem, dataSize);',
353 '(StoreCheck << FlagShift) | Request::LOCKED')
354 defineMicroLoadOp('Ldfp', 'FpData.uqw = Mem;')
356 def defineMicroStoreOp(mnemonic, code, \
357 postCode="", completeCode="", mem_flags="0"):
359 global decoder_output
361 global microopClasses
363 name = mnemonic.lower()
365 # Build up the all register version of this micro op
366 iop = InstObjParams(name, Name, 'X86ISA::LdStOp',
368 "post_code": postCode,
369 "complete_code": completeCode,
370 "ea_code": calculateEA})
371 header_output += MicroLdStOpDeclare.subst(iop)
372 decoder_output += MicroLdStOpConstructor.subst(iop)
373 exec_output += MicroStoreExecute.subst(iop)
374 exec_output += MicroStoreInitiateAcc.subst(iop)
375 exec_output += MicroStoreCompleteAcc.subst(iop)
377 class StoreOp(LdStOp):
378 def __init__(self, data, segment, addr, disp = 0,
379 dataSize="env.dataSize",
380 addressSize="env.addressSize",
382 super(StoreOp, self).__init__(data, segment, addr,
383 disp, dataSize, addressSize, mem_flags, atCPL0, False)
384 self.className = Name
387 microopClasses[name] = StoreOp
389 defineMicroStoreOp('St', 'Mem = pick(Data, 2, dataSize);')
390 defineMicroStoreOp('Stul', 'Mem = pick(Data, 2, dataSize);',
391 mem_flags="Request::LOCKED")
392 defineMicroStoreOp('Stfp', 'Mem = FpData.uqw;')
393 defineMicroStoreOp('Stupd', 'Mem = pick(Data, 2, dataSize);',
394 'Base = merge(Base, EA - SegBase, addressSize);',
395 'Base = merge(Base, pkt->req->getVaddr() - SegBase, addressSize);');
396 defineMicroStoreOp('Cda', 'Mem = 0;', mem_flags="Request::NO_ACCESS")
398 iop = InstObjParams("lea", "Lea", 'X86ISA::LdStOp',
399 {"code": "Data = merge(Data, EA, dataSize);",
401 EA = bits(scale * Index + Base + disp, addressSize * 8 - 1, 0);
403 header_output += MicroLeaDeclare.subst(iop)
404 decoder_output += MicroLdStOpConstructor.subst(iop)
405 exec_output += MicroLeaExecute.subst(iop)
408 def __init__(self, data, segment, addr, disp = 0,
409 dataSize="env.dataSize", addressSize="env.addressSize"):
410 super(LeaOp, self).__init__(data, segment,
411 addr, disp, dataSize, addressSize, "0", False, False)
412 self.className = "Lea"
413 self.mnemonic = "lea"
415 microopClasses["lea"] = LeaOp
418 iop = InstObjParams("tia", "Tia", 'X86ISA::LdStOp',
419 {"code": "xc->demapPage(EA, 0);",
420 "ea_code": calculateEA})
421 header_output += MicroLeaDeclare.subst(iop)
422 decoder_output += MicroLdStOpConstructor.subst(iop)
423 exec_output += MicroLeaExecute.subst(iop)
426 def __init__(self, segment, addr, disp = 0,
427 dataSize="env.dataSize",
428 addressSize="env.addressSize"):
429 super(TiaOp, self).__init__("InstRegIndex(NUM_INTREGS)", segment,
430 addr, disp, dataSize, addressSize, "0", False, False)
431 self.className = "Tia"
432 self.mnemonic = "tia"
434 microopClasses["tia"] = TiaOp
437 def __init__(self, segment, addr, disp = 0,
438 dataSize="env.dataSize",
439 addressSize="env.addressSize", atCPL0=False):
440 super(CdaOp, self).__init__("InstRegIndex(NUM_INTREGS)", segment,
441 addr, disp, dataSize, addressSize, "Request::NO_ACCESS",
443 self.className = "Cda"
444 self.mnemonic = "cda"
446 microopClasses["cda"] = CdaOp