3 // Copyright (c) 2003-2005 The Regents of The University of Michigan
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met: redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer;
10 // redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution;
13 // neither the name of the copyright holders nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 // Authors: Steve Reinhardt
32 ////////////////////////////////////////////////////////////////////
34 // Memory-format instructions: LoadAddress, Load, Store
39 * Base class for general Alpha memory-format instructions.
41 class Memory : public AlphaStaticInst
45 /// Memory request flags. See mem_req_base.hh.
46 unsigned memAccessFlags;
47 /// Pointer to EAComp object.
48 const StaticInstPtr eaCompPtr;
49 /// Pointer to MemAcc object.
50 const StaticInstPtr memAccPtr;
53 Memory(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
54 StaticInstPtr _eaCompPtr = nullStaticInstPtr,
55 StaticInstPtr _memAccPtr = nullStaticInstPtr)
56 : AlphaStaticInst(mnem, _machInst, __opClass),
57 memAccessFlags(0), eaCompPtr(_eaCompPtr), memAccPtr(_memAccPtr)
62 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
66 const StaticInstPtr &eaCompInst() const { return eaCompPtr; }
67 const StaticInstPtr &memAccInst() const { return memAccPtr; }
71 * Base class for memory-format instructions using a 32-bit
72 * displacement (i.e. most of them).
74 class MemoryDisp32 : public Memory
77 /// Displacement for EA calculation (signed).
81 MemoryDisp32(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
82 StaticInstPtr _eaCompPtr = nullStaticInstPtr,
83 StaticInstPtr _memAccPtr = nullStaticInstPtr)
84 : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr),
92 * Base class for a few miscellaneous memory-format insts
93 * that don't interpret the disp field: wh64, fetch, fetch_m, ecb.
94 * None of these instructions has a destination register either.
96 class MemoryNoDisp : public Memory
100 MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
101 StaticInstPtr _eaCompPtr = nullStaticInstPtr,
102 StaticInstPtr _memAccPtr = nullStaticInstPtr)
103 : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr)
108 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
115 Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
117 return csprintf("%-10s %c%d,%d(r%d)", mnemonic,
118 flags[IsFloating] ? 'f' : 'r', RA, MEMDISP, RB);
122 MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
124 return csprintf("%-10s (r%d)", mnemonic, RB);
128 def format LoadAddress(code) {{
129 iop = InstObjParams(name, Name, 'MemoryDisp32', CodeBlock(code))
130 header_output = BasicDeclare.subst(iop)
131 decoder_output = BasicConstructor.subst(iop)
132 decode_block = BasicDecode.subst(iop)
133 exec_output = BasicExecute.subst(iop)
137 def template LoadStoreDeclare {{
139 * Static instruction class for "%(mnemonic)s".
141 class %(class_name)s : public %(base_class)s
146 * "Fake" effective address computation class for "%(mnemonic)s".
148 class EAComp : public %(base_class)s
152 EAComp(ExtMachInst machInst);
158 * "Fake" memory access instruction class for "%(mnemonic)s".
160 class MemAcc : public %(base_class)s
164 MemAcc(ExtMachInst machInst);
172 %(class_name)s(ExtMachInst machInst);
176 %(InitiateAccDeclare)s
178 %(CompleteAccDeclare)s
183 def template InitiateAccDeclare {{
184 Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
188 def template CompleteAccDeclare {{
189 Fault completeAcc(Packet *, %(CPU_exec_context)s *,
190 Trace::InstRecord *) const;
194 def template LoadStoreConstructor {{
195 /** TODO: change op_class to AddrGenOp or something (requires
196 * creating new member of OpClass enum in op_class.hh, updating
197 * config files, etc.). */
198 inline %(class_name)s::EAComp::EAComp(ExtMachInst machInst)
199 : %(base_class)s("%(mnemonic)s (EAComp)", machInst, IntAluOp)
204 inline %(class_name)s::MemAcc::MemAcc(ExtMachInst machInst)
205 : %(base_class)s("%(mnemonic)s (MemAcc)", machInst, %(op_class)s)
207 %(memacc_constructor)s;
210 inline %(class_name)s::%(class_name)s(ExtMachInst machInst)
211 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
212 new EAComp(machInst), new MemAcc(machInst))
219 def template EACompExecute {{
221 %(class_name)s::EAComp::execute(%(CPU_exec_context)s *xc,
222 Trace::InstRecord *traceData) const
225 Fault fault = NoFault;
232 if (fault == NoFault) {
241 def template LoadMemAccExecute {{
243 %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
244 Trace::InstRecord *traceData) const
247 Fault fault = NoFault;
254 if (fault == NoFault) {
255 fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
259 if (fault == NoFault) {
268 def template LoadExecute {{
269 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
270 Trace::InstRecord *traceData) const
273 Fault fault = NoFault;
280 if (fault == NoFault) {
281 fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
285 if (fault == NoFault) {
294 def template LoadInitiateAcc {{
295 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
296 Trace::InstRecord *traceData) const
299 Fault fault = NoFault;
306 if (fault == NoFault) {
307 fault = xc->read(EA, (uint%(mem_acc_size)d_t &)Mem, memAccessFlags);
315 def template LoadCompleteAcc {{
316 Fault %(class_name)s::completeAcc(Packet *pkt,
317 %(CPU_exec_context)s *xc,
318 Trace::InstRecord *traceData) const
320 Fault fault = NoFault;
325 Mem = pkt->get<typeof(Mem)>();
327 if (fault == NoFault) {
331 if (fault == NoFault) {
340 def template StoreMemAccExecute {{
342 %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
343 Trace::InstRecord *traceData) const
346 Fault fault = NoFault;
347 uint64_t write_result = 0;
354 if (fault == NoFault) {
358 if (fault == NoFault) {
359 fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
360 memAccessFlags, &write_result);
361 if (traceData) { traceData->setData(Mem); }
364 if (fault == NoFault) {
368 if (fault == NoFault) {
377 def template StoreExecute {{
378 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
379 Trace::InstRecord *traceData) const
382 Fault fault = NoFault;
383 uint64_t write_result = 0;
390 if (fault == NoFault) {
394 if (fault == NoFault) {
395 fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
396 memAccessFlags, &write_result);
397 if (traceData) { traceData->setData(Mem); }
400 if (fault == NoFault) {
404 if (fault == NoFault) {
412 def template StoreInitiateAcc {{
413 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
414 Trace::InstRecord *traceData) const
417 Fault fault = NoFault;
424 if (fault == NoFault) {
428 if (fault == NoFault) {
429 fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
430 memAccessFlags, NULL);
431 if (traceData) { traceData->setData(Mem); }
439 def template StoreCompleteAcc {{
440 Fault %(class_name)s::completeAcc(Packet *pkt,
441 %(CPU_exec_context)s *xc,
442 Trace::InstRecord *traceData) const
444 Fault fault = NoFault;
449 if (fault == NoFault) {
453 if (fault == NoFault) {
462 def template StoreCondCompleteAcc {{
463 Fault %(class_name)s::completeAcc(Packet *pkt,
464 %(CPU_exec_context)s *xc,
465 Trace::InstRecord *traceData) const
467 Fault fault = NoFault;
472 uint64_t write_result = pkt->req->getScResult();
474 if (fault == NoFault) {
478 if (fault == NoFault) {
487 def template MiscMemAccExecute {{
488 Fault %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
489 Trace::InstRecord *traceData) const
492 Fault fault = NoFault;
499 if (fault == NoFault) {
507 def template MiscExecute {{
508 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
509 Trace::InstRecord *traceData) const
512 Fault fault = NoFault;
519 if (fault == NoFault) {
527 def template MiscInitiateAcc {{
528 Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
529 Trace::InstRecord *traceData) const
531 warn("Misc instruction does not support split access method!");
537 def template MiscCompleteAcc {{
538 Fault %(class_name)s::completeAcc(Packet *pkt,
539 %(CPU_exec_context)s *xc,
540 Trace::InstRecord *traceData) const
542 warn("Misc instruction does not support split access method!");
548 // load instructions use Ra as dest, so check for
549 // Ra == 31 to detect nops
550 def template LoadNopCheckDecode {{
552 AlphaStaticInst *i = new %(class_name)s(machInst);
561 // for some load instructions, Ra == 31 indicates a prefetch (not a nop)
562 def template LoadPrefetchCheckDecode {{
565 return new %(class_name)s(machInst);
568 return new %(class_name)sPrefetch(machInst);
575 def LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
576 postacc_code = '', base_class = 'MemoryDisp32',
577 decode_template = BasicDecode, exec_template_base = ''):
578 # Make sure flags are in lists (convert to lists if not).
579 mem_flags = makeList(mem_flags)
580 inst_flags = makeList(inst_flags)
582 # add hook to get effective addresses into execution trace output.
583 ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n'
585 # generate code block objects
586 ea_cblk = CodeBlock(ea_code)
587 memacc_cblk = CodeBlock(memacc_code)
588 postacc_cblk = CodeBlock(postacc_code)
590 # Some CPU models execute the memory operation as an atomic unit,
591 # while others want to separate them into an effective address
592 # computation and a memory access operation. As a result, we need
593 # to generate three StaticInst objects. Note that the latter two
594 # are nested inside the larger "atomic" one.
596 # generate InstObjParams for EAComp object
597 ea_iop = InstObjParams(name, Name, base_class, ea_cblk, inst_flags)
599 # generate InstObjParams for MemAcc object
600 memacc_iop = InstObjParams(name, Name, base_class, memacc_cblk, inst_flags)
601 # in the split execution model, the MemAcc portion is responsible
602 # for the post-access code.
603 memacc_iop.postacc_code = postacc_cblk.code
605 # generate InstObjParams for InitiateAcc, CompleteAcc object
606 # The code used depends on the template being used
607 if (exec_template_base == 'Load'):
608 initiateacc_cblk = CodeBlock(ea_code + memacc_code)
609 completeacc_cblk = CodeBlock(memacc_code + postacc_code)
610 elif (exec_template_base.startswith('Store')):
611 initiateacc_cblk = CodeBlock(ea_code + memacc_code)
612 completeacc_cblk = CodeBlock(postacc_code)
614 initiateacc_cblk = ''
615 completeacc_cblk = ''
617 initiateacc_iop = InstObjParams(name, Name, base_class, initiateacc_cblk,
620 completeacc_iop = InstObjParams(name, Name, base_class, completeacc_cblk,
623 if (exec_template_base == 'Load'):
624 initiateacc_iop.ea_code = ea_cblk.code
625 initiateacc_iop.memacc_code = memacc_cblk.code
626 completeacc_iop.memacc_code = memacc_cblk.code
627 completeacc_iop.postacc_code = postacc_cblk.code
628 elif (exec_template_base.startswith('Store')):
629 initiateacc_iop.ea_code = ea_cblk.code
630 initiateacc_iop.memacc_code = memacc_cblk.code
631 completeacc_iop.postacc_code = postacc_cblk.code
633 # generate InstObjParams for unified execution
634 cblk = CodeBlock(ea_code + memacc_code + postacc_code)
635 iop = InstObjParams(name, Name, base_class, cblk, inst_flags)
637 iop.ea_constructor = ea_cblk.constructor
638 iop.ea_code = ea_cblk.code
639 iop.memacc_constructor = memacc_cblk.constructor
640 iop.memacc_code = memacc_cblk.code
641 iop.postacc_code = postacc_cblk.code
644 s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';'
646 memacc_iop.constructor += s
650 # define aliases... most StoreCond templates are the same as the
651 # corresponding Store templates (only CompleteAcc is different).
652 StoreCondMemAccExecute = StoreMemAccExecute
653 StoreCondExecute = StoreExecute
654 StoreCondInitiateAcc = StoreInitiateAcc
656 memAccExecTemplate = eval(exec_template_base + 'MemAccExecute')
657 fullExecTemplate = eval(exec_template_base + 'Execute')
658 initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
659 completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
661 # (header_output, decoder_output, decode_block, exec_output)
662 return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop),
663 decode_template.subst(iop),
664 EACompExecute.subst(ea_iop)
665 + memAccExecTemplate.subst(memacc_iop)
666 + fullExecTemplate.subst(iop)
667 + initiateAccTemplate.subst(initiateacc_iop)
668 + completeAccTemplate.subst(completeacc_iop))
671 def format LoadOrNop(memacc_code, ea_code = {{ EA = Rb + disp; }},
672 mem_flags = [], inst_flags = []) {{
673 (header_output, decoder_output, decode_block, exec_output) = \
674 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
675 decode_template = LoadNopCheckDecode,
676 exec_template_base = 'Load')
680 // Note that the flags passed in apply only to the prefetch version
681 def format LoadOrPrefetch(memacc_code, ea_code = {{ EA = Rb + disp; }},
682 mem_flags = [], pf_flags = [], inst_flags = []) {{
683 # declare the load instruction object and generate the decode block
684 (header_output, decoder_output, decode_block, exec_output) = \
685 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
686 decode_template = LoadPrefetchCheckDecode,
687 exec_template_base = 'Load')
689 # Declare the prefetch instruction object.
691 # Make sure flag args are lists so we can mess with them.
692 mem_flags = makeList(mem_flags)
693 pf_flags = makeList(pf_flags)
694 inst_flags = makeList(inst_flags)
696 pf_mem_flags = mem_flags + pf_flags + ['NO_FAULT']
697 pf_inst_flags = inst_flags + ['IsMemRef', 'IsLoad',
698 'IsDataPrefetch', 'MemReadOp']
700 (pf_header_output, pf_decoder_output, _, pf_exec_output) = \
701 LoadStoreBase(name, Name + 'Prefetch', ea_code,
702 'xc->prefetch(EA, memAccessFlags);',
703 pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
705 header_output += pf_header_output
706 decoder_output += pf_decoder_output
707 exec_output += pf_exec_output
711 def format Store(memacc_code, ea_code = {{ EA = Rb + disp; }},
712 mem_flags = [], inst_flags = []) {{
713 (header_output, decoder_output, decode_block, exec_output) = \
714 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
715 exec_template_base = 'Store')
719 def format StoreCond(memacc_code, postacc_code,
720 ea_code = {{ EA = Rb + disp; }},
721 mem_flags = [], inst_flags = []) {{
722 (header_output, decoder_output, decode_block, exec_output) = \
723 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
724 postacc_code, exec_template_base = 'StoreCond')
728 // Use 'MemoryNoDisp' as base: for wh64, fetch, ecb
729 def format MiscPrefetch(ea_code, memacc_code,
730 mem_flags = [], inst_flags = []) {{
731 (header_output, decoder_output, decode_block, exec_output) = \
732 LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
733 base_class = 'MemoryNoDisp', exec_template_base = 'Misc')