mem.isa revision 2935
12292SN/A// -*- mode:c++ -*-
22329SN/A
32292SN/A// Copyright (c) 2003-2005 The Regents of The University of Michigan
42292SN/A// All rights reserved.
52292SN/A//
62292SN/A// Redistribution and use in source and binary forms, with or without
72292SN/A// modification, are permitted provided that the following conditions are
82292SN/A// met: redistributions of source code must retain the above copyright
92292SN/A// notice, this list of conditions and the following disclaimer;
102292SN/A// redistributions in binary form must reproduce the above copyright
112292SN/A// notice, this list of conditions and the following disclaimer in the
122292SN/A// documentation and/or other materials provided with the distribution;
132292SN/A// neither the name of the copyright holders nor the names of its
142292SN/A// contributors may be used to endorse or promote products derived from
152292SN/A// this software without specific prior written permission.
162292SN/A//
172292SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182292SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192292SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202292SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212292SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222292SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232292SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242292SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252292SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262292SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272689Sktlim@umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282689Sktlim@umich.edu//
292689Sktlim@umich.edu// Authors: Steve Reinhardt
302292SN/A//          Kevin Lim
312292SN/A
322292SN/A////////////////////////////////////////////////////////////////////
332292SN/A//
342292SN/A// Memory-format instructions: LoadAddress, Load, Store
352329SN/A//
362292SN/A
372292SN/Aoutput header {{
382292SN/A    /**
392329SN/A     * Base class for general Alpha memory-format instructions.
403326Sktlim@umich.edu     */
412292SN/A    class Memory : public AlphaStaticInst
422292SN/A    {
432292SN/A      protected:
443348Sbinkertn@umich.edu
452669Sktlim@umich.edu        /// Memory request flags.  See mem_req_base.hh.
462292SN/A        unsigned memAccessFlags;
472292SN/A        /// Pointer to EAComp object.
482329SN/A        const StaticInstPtr eaCompPtr;
492329SN/A        /// Pointer to MemAcc object.
502329SN/A        const StaticInstPtr memAccPtr;
512329SN/A
522329SN/A        /// Constructor
532329SN/A        Memory(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
542329SN/A               StaticInstPtr _eaCompPtr = nullStaticInstPtr,
552329SN/A               StaticInstPtr _memAccPtr = nullStaticInstPtr)
562329SN/A            : AlphaStaticInst(mnem, _machInst, __opClass),
572329SN/A              memAccessFlags(0), eaCompPtr(_eaCompPtr), memAccPtr(_memAccPtr)
582292SN/A        {
592292SN/A        }
602292SN/A
612292SN/A        std::string
622292SN/A        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
632292SN/A
642292SN/A      public:
652733Sktlim@umich.edu
662292SN/A        const StaticInstPtr &eaCompInst() const { return eaCompPtr; }
672292SN/A        const StaticInstPtr &memAccInst() const { return memAccPtr; }
682907Sktlim@umich.edu    };
692292SN/A
702292SN/A    /**
712292SN/A     * Base class for memory-format instructions using a 32-bit
722292SN/A     * displacement (i.e. most of them).
732292SN/A     */
742292SN/A    class MemoryDisp32 : public Memory
752292SN/A    {
764329Sktlim@umich.edu      protected:
774329Sktlim@umich.edu        /// Displacement for EA calculation (signed).
782292SN/A        int32_t disp;
792292SN/A
802292SN/A        /// Constructor.
812292SN/A        MemoryDisp32(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
822727Sktlim@umich.edu                     StaticInstPtr _eaCompPtr = nullStaticInstPtr,
832727Sktlim@umich.edu                     StaticInstPtr _memAccPtr = nullStaticInstPtr)
842727Sktlim@umich.edu            : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr),
852907Sktlim@umich.edu              disp(MEMDISP)
864329Sktlim@umich.edu        {
872907Sktlim@umich.edu        }
882348SN/A    };
892307SN/A
902307SN/A
912348SN/A    /**
922307SN/A     * Base class for a few miscellaneous memory-format insts
932307SN/A     * that don't interpret the disp field: wh64, fetch, fetch_m, ecb.
942348SN/A     * None of these instructions has a destination register either.
952307SN/A     */
962307SN/A    class MemoryNoDisp : public Memory
972292SN/A    {
982292SN/A      protected:
992292SN/A        /// Constructor
1002292SN/A        MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
1012292SN/A                     StaticInstPtr _eaCompPtr = nullStaticInstPtr,
1022292SN/A                     StaticInstPtr _memAccPtr = nullStaticInstPtr)
1032292SN/A            : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr)
1042292SN/A        {
1052292SN/A        }
1062292SN/A
1072292SN/A        std::string
1082292SN/A        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
1092292SN/A    };
1102292SN/A}};
1112292SN/A
1122292SN/A
1132292SN/Aoutput decoder {{
1142329SN/A    std::string
1152292SN/A    Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1162292SN/A    {
1172292SN/A        return csprintf("%-10s %c%d,%d(r%d)", mnemonic,
1182292SN/A                        flags[IsFloating] ? 'f' : 'r', RA, MEMDISP, RB);
1192292SN/A    }
1202292SN/A
1212292SN/A    std::string
1222292SN/A    MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1232292SN/A    {
1242292SN/A        return csprintf("%-10s (r%d)", mnemonic, RB);
1252292SN/A    }
1262292SN/A}};
1272292SN/A
1282292SN/Adef format LoadAddress(code) {{
1292790Sktlim@umich.edu    iop = InstObjParams(name, Name, 'MemoryDisp32', CodeBlock(code))
1302790Sktlim@umich.edu    header_output = BasicDeclare.subst(iop)
1312669Sktlim@umich.edu    decoder_output = BasicConstructor.subst(iop)
1322669Sktlim@umich.edu    decode_block = BasicDecode.subst(iop)
1332292SN/A    exec_output = BasicExecute.subst(iop)
1342292SN/A}};
1352292SN/A
1362292SN/A
1372292SN/Adef template LoadStoreDeclare {{
1382292SN/A    /**
1392292SN/A     * Static instruction class for "%(mnemonic)s".
1402292SN/A     */
1412292SN/A    class %(class_name)s : public %(base_class)s
1422292SN/A    {
1432292SN/A      protected:
1442292SN/A
1452292SN/A        /**
1462292SN/A         * "Fake" effective address computation class for "%(mnemonic)s".
1472292SN/A         */
1482292SN/A        class EAComp : public %(base_class)s
1492292SN/A        {
1502292SN/A          public:
1512292SN/A            /// Constructor
1522292SN/A            EAComp(ExtMachInst machInst);
1532292SN/A
1542292SN/A            %(BasicExecDeclare)s
1552292SN/A        };
1562329SN/A
1572292SN/A        /**
1582292SN/A         * "Fake" memory access instruction class for "%(mnemonic)s".
1592292SN/A         */
1602348SN/A        class MemAcc : public %(base_class)s
1612292SN/A        {
1622292SN/A          public:
1632292SN/A            /// Constructor
1642348SN/A            MemAcc(ExtMachInst machInst);
1652292SN/A
1662292SN/A            %(BasicExecDeclare)s
1672292SN/A        };
1682348SN/A
1692292SN/A      public:
1702292SN/A
1712292SN/A        /// Constructor.
1722292SN/A        %(class_name)s(ExtMachInst machInst);
1732292SN/A
1742292SN/A        %(BasicExecDeclare)s
1752292SN/A
1762292SN/A        %(InitiateAccDeclare)s
1772292SN/A
1782292SN/A        %(CompleteAccDeclare)s
1792292SN/A    };
1802292SN/A}};
1812292SN/A
1822292SN/A
1832292SN/Adef template InitiateAccDeclare {{
1842292SN/A    Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
1852292SN/A}};
1862292SN/A
1872292SN/A
1882292SN/Adef template CompleteAccDeclare {{
1892292SN/A    Fault completeAcc(Packet *, %(CPU_exec_context)s *,
1902292SN/A                      Trace::InstRecord *) const;
1912292SN/A}};
1922292SN/A
1932292SN/A
1942292SN/Adef template LoadStoreConstructor {{
1952292SN/A    /** TODO: change op_class to AddrGenOp or something (requires
1962292SN/A     * creating new member of OpClass enum in op_class.hh, updating
1972292SN/A     * config files, etc.). */
1982292SN/A    inline %(class_name)s::EAComp::EAComp(ExtMachInst machInst)
1992292SN/A        : %(base_class)s("%(mnemonic)s (EAComp)", machInst, IntAluOp)
2002292SN/A    {
2012292SN/A        %(ea_constructor)s;
2022292SN/A    }
2032292SN/A
2042678Sktlim@umich.edu    inline %(class_name)s::MemAcc::MemAcc(ExtMachInst machInst)
2052678Sktlim@umich.edu        : %(base_class)s("%(mnemonic)s (MemAcc)", machInst, %(op_class)s)
2062292SN/A    {
2072907Sktlim@umich.edu        %(memacc_constructor)s;
2082907Sktlim@umich.edu    }
2092907Sktlim@umich.edu
2102292SN/A    inline %(class_name)s::%(class_name)s(ExtMachInst machInst)
2112698Sktlim@umich.edu         : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
2122678Sktlim@umich.edu                          new EAComp(machInst), new MemAcc(machInst))
2132678Sktlim@umich.edu    {
2142698Sktlim@umich.edu        %(constructor)s;
2153349Sbinkertn@umich.edu    }
2162693Sktlim@umich.edu}};
2172292SN/A
2182292SN/A
2192292SN/Adef template EACompExecute {{
2202292SN/A    Fault
2212292SN/A    %(class_name)s::EAComp::execute(%(CPU_exec_context)s *xc,
2222292SN/A                                   Trace::InstRecord *traceData) const
2232292SN/A    {
2242292SN/A        Addr EA;
2252292SN/A        Fault fault = NoFault;
2262292SN/A
2272292SN/A        %(fp_enable_check)s;
2282292SN/A        %(op_decl)s;
2292329SN/A        %(op_rd)s;
2302329SN/A        %(code)s;
2312329SN/A
2322329SN/A        if (fault == NoFault) {
2332292SN/A            %(op_wb)s;
2342292SN/A            xc->setEA(EA);
2352733Sktlim@umich.edu        }
2362292SN/A
2372292SN/A        return fault;
2382292SN/A    }
2392292SN/A}};
2402907Sktlim@umich.edu
2412907Sktlim@umich.edudef template LoadMemAccExecute {{
2422669Sktlim@umich.edu    Fault
2432907Sktlim@umich.edu    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
2442907Sktlim@umich.edu                                   Trace::InstRecord *traceData) const
2452292SN/A    {
2462698Sktlim@umich.edu        Addr EA;
2472678Sktlim@umich.edu        Fault fault = NoFault;
2482678Sktlim@umich.edu
2492678Sktlim@umich.edu        %(fp_enable_check)s;
2502698Sktlim@umich.edu        %(op_decl)s;
2512678Sktlim@umich.edu        %(op_rd)s;
2522678Sktlim@umich.edu        EA = xc->getEA();
2532678Sktlim@umich.edu
2542678Sktlim@umich.edu        if (fault == NoFault) {
2552698Sktlim@umich.edu            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2562678Sktlim@umich.edu            %(code)s;
2572698Sktlim@umich.edu        }
2582678Sktlim@umich.edu
2592698Sktlim@umich.edu        if (fault == NoFault) {
2602678Sktlim@umich.edu            %(op_wb)s;
2612698Sktlim@umich.edu        }
2622678Sktlim@umich.edu
2632678Sktlim@umich.edu        return fault;
2642678Sktlim@umich.edu    }
2652698Sktlim@umich.edu}};
2662678Sktlim@umich.edu
2672678Sktlim@umich.edu
2682678Sktlim@umich.edudef template LoadExecute {{
2692678Sktlim@umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
2702678Sktlim@umich.edu                                  Trace::InstRecord *traceData) const
2712678Sktlim@umich.edu    {
2722678Sktlim@umich.edu        Addr EA;
2732678Sktlim@umich.edu        Fault fault = NoFault;
2742678Sktlim@umich.edu
2752678Sktlim@umich.edu        %(fp_enable_check)s;
2762678Sktlim@umich.edu        %(op_decl)s;
2772678Sktlim@umich.edu        %(op_rd)s;
2782698Sktlim@umich.edu        %(ea_code)s;
2792678Sktlim@umich.edu
2802678Sktlim@umich.edu        if (fault == NoFault) {
2812698Sktlim@umich.edu            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2822678Sktlim@umich.edu            %(memacc_code)s;
2832678Sktlim@umich.edu        }
2842678Sktlim@umich.edu
2852678Sktlim@umich.edu        if (fault == NoFault) {
2862678Sktlim@umich.edu            %(op_wb)s;
2872678Sktlim@umich.edu        }
2882292SN/A
2892292SN/A        return fault;
2902292SN/A    }
2912292SN/A}};
2922292SN/A
2932292SN/A
2942292SN/Adef template LoadInitiateAcc {{
2952292SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
2962292SN/A                                      Trace::InstRecord *traceData) const
2972292SN/A    {
2982292SN/A        Addr EA;
2992292SN/A        Fault fault = NoFault;
3002292SN/A
3012292SN/A        %(fp_enable_check)s;
3022292SN/A        %(op_src_decl)s;
3032292SN/A        %(op_rd)s;
3042669Sktlim@umich.edu        %(ea_code)s;
3052669Sktlim@umich.edu
3062292SN/A        if (fault == NoFault) {
3072292SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t &)Mem, memAccessFlags);
3082292SN/A        }
3092292SN/A
3102292SN/A        return fault;
3112292SN/A    }
3122292SN/A}};
3132292SN/A
3142292SN/A
3152292SN/Adef template LoadCompleteAcc {{
3162292SN/A    Fault %(class_name)s::completeAcc(Packet *pkt,
3172329SN/A                                      %(CPU_exec_context)s *xc,
3182292SN/A                                      Trace::InstRecord *traceData) const
3192292SN/A    {
3202292SN/A        Fault fault = NoFault;
3212292SN/A
3222292SN/A        %(fp_enable_check)s;
3232292SN/A        %(op_decl)s;
3242292SN/A
3252292SN/A        Mem = pkt->get<typeof(Mem)>();
3262292SN/A
3272292SN/A        if (fault == NoFault) {
3282329SN/A            %(memacc_code)s;
3292329SN/A        }
3302329SN/A
3312292SN/A        if (fault == NoFault) {
3322329SN/A            %(op_wb)s;
3332329SN/A        }
3342329SN/A
3352292SN/A        return fault;
3362292SN/A    }
3372292SN/A}};
3382292SN/A
3392329SN/A
3402292SN/Adef template StoreMemAccExecute {{
3412292SN/A    Fault
3422292SN/A    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
3432292SN/A                                   Trace::InstRecord *traceData) const
3442292SN/A    {
3452292SN/A        Addr EA;
3462292SN/A        Fault fault = NoFault;
3472292SN/A        uint64_t write_result = 0;
3482292SN/A
3492292SN/A        %(fp_enable_check)s;
3502292SN/A        %(op_decl)s;
3512329SN/A        %(op_rd)s;
3522329SN/A        EA = xc->getEA();
3532292SN/A
3542292SN/A        if (fault == NoFault) {
3552292SN/A            %(code)s;
3562292SN/A        }
3572292SN/A
3582292SN/A        if (fault == NoFault) {
3592292SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
3602292SN/A                              memAccessFlags, &write_result);
3612292SN/A            if (traceData) { traceData->setData(Mem); }
3622292SN/A        }
3632292SN/A
3642292SN/A        if (fault == NoFault) {
3652348SN/A            %(postacc_code)s;
3662307SN/A        }
3672307SN/A
3682292SN/A        if (fault == NoFault) {
3692292SN/A            %(op_wb)s;
3702292SN/A        }
3712292SN/A
3722292SN/A        return fault;
3732292SN/A    }
3742292SN/A}};
3752292SN/A
3762292SN/A
3772292SN/Adef template StoreExecute {{
3782292SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
3792292SN/A                                  Trace::InstRecord *traceData) const
3802292SN/A    {
3812292SN/A        Addr EA;
3822698Sktlim@umich.edu        Fault fault = NoFault;
3832698Sktlim@umich.edu        uint64_t write_result = 0;
3842693Sktlim@umich.edu
3852698Sktlim@umich.edu        %(fp_enable_check)s;
3862678Sktlim@umich.edu        %(op_decl)s;
3872678Sktlim@umich.edu        %(op_rd)s;
3882329SN/A        %(ea_code)s;
3892292SN/A
3902292SN/A        if (fault == NoFault) {
3912348SN/A            %(memacc_code)s;
3922292SN/A        }
3932292SN/A
3942348SN/A        if (fault == NoFault) {
3952292SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
3962292SN/A                              memAccessFlags, &write_result);
3972292SN/A            if (traceData) { traceData->setData(Mem); }
3982292SN/A        }
3992292SN/A
4002292SN/A        if (fault == NoFault) {
4012292SN/A            %(postacc_code)s;
4022292SN/A        }
4032727Sktlim@umich.edu
4042727Sktlim@umich.edu        if (fault == NoFault) {
4052307SN/A            %(op_wb)s;
4063126Sktlim@umich.edu        }
4073126Sktlim@umich.edu
4083126Sktlim@umich.edu        return fault;
4093126Sktlim@umich.edu    }
4103126Sktlim@umich.edu}};
4113126Sktlim@umich.edu
4123126Sktlim@umich.edudef template StoreInitiateAcc {{
4133126Sktlim@umich.edu    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
4143126Sktlim@umich.edu                                      Trace::InstRecord *traceData) const
4153126Sktlim@umich.edu    {
4163126Sktlim@umich.edu        Addr EA;
4173126Sktlim@umich.edu        Fault fault = NoFault;
4183126Sktlim@umich.edu
4192727Sktlim@umich.edu        %(fp_enable_check)s;
4202727Sktlim@umich.edu        %(op_decl)s;
4212727Sktlim@umich.edu        %(op_rd)s;
4222727Sktlim@umich.edu        %(ea_code)s;
4232727Sktlim@umich.edu
4242727Sktlim@umich.edu        if (fault == NoFault) {
4252727Sktlim@umich.edu            %(memacc_code)s;
4262727Sktlim@umich.edu        }
4272727Sktlim@umich.edu
4282727Sktlim@umich.edu        if (fault == NoFault) {
4292727Sktlim@umich.edu            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
4302727Sktlim@umich.edu                              memAccessFlags, NULL);
4312727Sktlim@umich.edu            if (traceData) { traceData->setData(Mem); }
4322727Sktlim@umich.edu        }
4332727Sktlim@umich.edu
4342292SN/A        return fault;
4352292SN/A    }
4362292SN/A}};
4372669Sktlim@umich.edu
4382292SN/A
4392292SN/Adef template StoreCompleteAcc {{
4402292SN/A    Fault %(class_name)s::completeAcc(Packet *pkt,
4412669Sktlim@umich.edu                                      %(CPU_exec_context)s *xc,
4422292SN/A                                      Trace::InstRecord *traceData) const
4432292SN/A    {
4442292SN/A        Fault fault = NoFault;
4452292SN/A
4462292SN/A        %(fp_enable_check)s;
4472292SN/A        %(op_dest_decl)s;
4482292SN/A
4492292SN/A        if (fault == NoFault) {
4502292SN/A            %(postacc_code)s;
4512292SN/A        }
4522292SN/A
4532292SN/A        if (fault == NoFault) {
4542292SN/A            %(op_wb)s;
4552292SN/A        }
4562292SN/A
4572292SN/A        return fault;
4582292SN/A    }
4592292SN/A}};
4602292SN/A
4612292SN/A
4622292SN/Adef template StoreCondCompleteAcc {{
4632292SN/A    Fault %(class_name)s::completeAcc(Packet *pkt,
4642292SN/A                                      %(CPU_exec_context)s *xc,
4652292SN/A                                      Trace::InstRecord *traceData) const
4662292SN/A    {
4672292SN/A        Fault fault = NoFault;
4682292SN/A
4692292SN/A        %(fp_enable_check)s;
4702292SN/A        %(op_dest_decl)s;
4712292SN/A
4722292SN/A        uint64_t write_result = pkt->req->getScResult();
4732292SN/A
4742292SN/A        if (fault == NoFault) {
4752292SN/A            %(postacc_code)s;
4762669Sktlim@umich.edu        }
4772292SN/A
4782669Sktlim@umich.edu        if (fault == NoFault) {
4792292SN/A            %(op_wb)s;
4802669Sktlim@umich.edu        }
4812669Sktlim@umich.edu
4822669Sktlim@umich.edu        return fault;
4832292SN/A    }
4842292SN/A}};
4852292SN/A
4862292SN/A
4872292SN/Adef template MiscMemAccExecute {{
4883172Sstever@eecs.umich.edu    Fault %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
4892731Sktlim@umich.edu                                          Trace::InstRecord *traceData) const
4902669Sktlim@umich.edu    {
4912727Sktlim@umich.edu        Addr EA;
4924032Sktlim@umich.edu        Fault fault = NoFault;
4934032Sktlim@umich.edu
4944032Sktlim@umich.edu        %(fp_enable_check)s;
4954032Sktlim@umich.edu        %(op_decl)s;
4964032Sktlim@umich.edu        %(op_rd)s;
4972292SN/A        EA = xc->getEA();
4982292SN/A
4992292SN/A        if (fault == NoFault) {
5002292SN/A            %(code)s;
5012669Sktlim@umich.edu        }
5022292SN/A
5032292SN/A        return NoFault;
5042292SN/A    }
5052292SN/A}};
5062292SN/A
5072669Sktlim@umich.edudef template MiscExecute {{
5082292SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
5093172Sstever@eecs.umich.edu                                  Trace::InstRecord *traceData) const
5103326Sktlim@umich.edu    {
5113326Sktlim@umich.edu        Addr EA;
5123326Sktlim@umich.edu        Fault fault = NoFault;
5133326Sktlim@umich.edu
5143326Sktlim@umich.edu        %(fp_enable_check)s;
5153326Sktlim@umich.edu        %(op_decl)s;
5162292SN/A        %(op_rd)s;
5172292SN/A        %(ea_code)s;
5182292SN/A
5192292SN/A        if (fault == NoFault) {
5202292SN/A            %(memacc_code)s;
5212292SN/A        }
5222292SN/A
5232292SN/A        return NoFault;
5242292SN/A    }
5252292SN/A}};
5262292SN/A
5272292SN/Adef template MiscInitiateAcc {{
5282292SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
5292292SN/A                                      Trace::InstRecord *traceData) const
5302292SN/A    {
5312292SN/A        panic("Misc instruction does not support split access method!");
5322292SN/A        return NoFault;
5332292SN/A    }
5344032Sktlim@umich.edu}};
5354032Sktlim@umich.edu
5364032Sktlim@umich.edu
5374032Sktlim@umich.edudef template MiscCompleteAcc {{
5382292SN/A    Fault %(class_name)s::completeAcc(Packet *pkt,
5392292SN/A                                      %(CPU_exec_context)s *xc,
5402292SN/A                                      Trace::InstRecord *traceData) const
5412292SN/A    {
5422669Sktlim@umich.edu        panic("Misc instruction does not support split access method!");
5432292SN/A
5442669Sktlim@umich.edu        return NoFault;
5452669Sktlim@umich.edu    }
5462292SN/A}};
5472669Sktlim@umich.edu
5482292SN/A// load instructions use Ra as dest, so check for
5492292SN/A// Ra == 31 to detect nops
5502669Sktlim@umich.edudef template LoadNopCheckDecode {{
5512669Sktlim@umich.edu {
5522292SN/A     AlphaStaticInst *i = new %(class_name)s(machInst);
5532292SN/A     if (RA == 31) {
5544032Sktlim@umich.edu         i = makeNop(i);
5552329SN/A     }
5562669Sktlim@umich.edu     return i;
5572329SN/A }
5582292SN/A}};
5592292SN/A
5602292SN/A
5612292SN/A// for some load instructions, Ra == 31 indicates a prefetch (not a nop)
5622292SN/Adef template LoadPrefetchCheckDecode {{
5633803Sgblack@eecs.umich.edu {
5643803Sgblack@eecs.umich.edu     if (RA != 31) {
5653803Sgblack@eecs.umich.edu         return new %(class_name)s(machInst);
5663803Sgblack@eecs.umich.edu     }
5673803Sgblack@eecs.umich.edu     else {
5683803Sgblack@eecs.umich.edu         return new %(class_name)sPrefetch(machInst);
5692669Sktlim@umich.edu     }
5702669Sktlim@umich.edu }
5712292SN/A}};
5722669Sktlim@umich.edu
5732292SN/A
5742292SN/Alet {{
5752292SN/Adef LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5762693Sktlim@umich.edu                  postacc_code = '', base_class = 'MemoryDisp32',
5772678Sktlim@umich.edu                  decode_template = BasicDecode, exec_template_base = ''):
5784022Sstever@eecs.umich.edu    # Make sure flags are in lists (convert to lists if not).
5794022Sstever@eecs.umich.edu    mem_flags = makeList(mem_flags)
5802678Sktlim@umich.edu    inst_flags = makeList(inst_flags)
5812678Sktlim@umich.edu
5822678Sktlim@umich.edu    # add hook to get effective addresses into execution trace output.
5832292SN/A    ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n'
5842292SN/A
5852292SN/A    # generate code block objects
5862292SN/A    ea_cblk = CodeBlock(ea_code)
5872292SN/A    memacc_cblk = CodeBlock(memacc_code)
5882678Sktlim@umich.edu    postacc_cblk = CodeBlock(postacc_code)
5892727Sktlim@umich.edu
5902292SN/A    # Some CPU models execute the memory operation as an atomic unit,
5912292SN/A    # while others want to separate them into an effective address
5922292SN/A    # computation and a memory access operation.  As a result, we need
5932292SN/A    # to generate three StaticInst objects.  Note that the latter two
5942292SN/A    # are nested inside the larger "atomic" one.
5952292SN/A
5962292SN/A    # generate InstObjParams for EAComp object
5972292SN/A    ea_iop = InstObjParams(name, Name, base_class, ea_cblk, inst_flags)
5982292SN/A
5992292SN/A    # generate InstObjParams for MemAcc object
6004032Sktlim@umich.edu    memacc_iop = InstObjParams(name, Name, base_class, memacc_cblk, inst_flags)
6012292SN/A    # in the split execution model, the MemAcc portion is responsible
6022292SN/A    # for the post-access code.
6032292SN/A    memacc_iop.postacc_code = postacc_cblk.code
6042292SN/A
6052292SN/A    # generate InstObjParams for InitiateAcc, CompleteAcc object
6062292SN/A    # The code used depends on the template being used
6072292SN/A    if (exec_template_base == 'Load'):
6082669Sktlim@umich.edu        initiateacc_cblk = CodeBlock(ea_code + memacc_code)
6092292SN/A        completeacc_cblk = CodeBlock(memacc_code + postacc_code)
6102292SN/A    elif (exec_template_base.startswith('Store')):
6112292SN/A        initiateacc_cblk = CodeBlock(ea_code + memacc_code)
6122292SN/A        completeacc_cblk = CodeBlock(postacc_code)
6132292SN/A    else:
6142292SN/A        initiateacc_cblk = ''
6152292SN/A        completeacc_cblk = ''
6162292SN/A
6172669Sktlim@umich.edu    initiateacc_iop = InstObjParams(name, Name, base_class, initiateacc_cblk,
6182927Sktlim@umich.edu                                    inst_flags)
6194032Sktlim@umich.edu
6202727Sktlim@umich.edu    completeacc_iop = InstObjParams(name, Name, base_class, completeacc_cblk,
6212292SN/A                                    inst_flags)
6222292SN/A
6232292SN/A    if (exec_template_base == 'Load'):
6242292SN/A        initiateacc_iop.ea_code = ea_cblk.code
6252292SN/A        initiateacc_iop.memacc_code = memacc_cblk.code
6262669Sktlim@umich.edu        completeacc_iop.memacc_code = memacc_cblk.code
6272292SN/A        completeacc_iop.postacc_code = postacc_cblk.code
6284032Sktlim@umich.edu    elif (exec_template_base.startswith('Store')):
6294032Sktlim@umich.edu        initiateacc_iop.ea_code = ea_cblk.code
6304032Sktlim@umich.edu        initiateacc_iop.memacc_code = memacc_cblk.code
6314032Sktlim@umich.edu        completeacc_iop.postacc_code = postacc_cblk.code
6324032Sktlim@umich.edu
6332292SN/A    # generate InstObjParams for unified execution
6342292SN/A    cblk = CodeBlock(ea_code + memacc_code + postacc_code)
6352292SN/A    iop = InstObjParams(name, Name, base_class, cblk, inst_flags)
6362292SN/A
6372292SN/A    iop.ea_constructor = ea_cblk.constructor
6382907Sktlim@umich.edu    iop.ea_code = ea_cblk.code
6392669Sktlim@umich.edu    iop.memacc_constructor = memacc_cblk.constructor
6402292SN/A    iop.memacc_code = memacc_cblk.code
6412669Sktlim@umich.edu    iop.postacc_code = postacc_cblk.code
6422669Sktlim@umich.edu
6432292SN/A    if mem_flags:
6442292SN/A        s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';'
6452292SN/A        iop.constructor += s
6462907Sktlim@umich.edu        memacc_iop.constructor += s
6472907Sktlim@umich.edu
6483228Sktlim@umich.edu    # select templates
6494022Sstever@eecs.umich.edu
6503228Sktlim@umich.edu    # define aliases... most StoreCond templates are the same as the
6513228Sktlim@umich.edu    # corresponding Store templates (only CompleteAcc is different).
6523228Sktlim@umich.edu    StoreCondMemAccExecute = StoreMemAccExecute
6533228Sktlim@umich.edu    StoreCondExecute = StoreExecute
6543228Sktlim@umich.edu    StoreCondInitiateAcc = StoreInitiateAcc
6553228Sktlim@umich.edu
6563228Sktlim@umich.edu    memAccExecTemplate = eval(exec_template_base + 'MemAccExecute')
6573228Sktlim@umich.edu    fullExecTemplate = eval(exec_template_base + 'Execute')
6582907Sktlim@umich.edu    initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
6593228Sktlim@umich.edu    completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
6603228Sktlim@umich.edu
6613228Sktlim@umich.edu    # (header_output, decoder_output, decode_block, exec_output)
6623228Sktlim@umich.edu    return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop),
6633228Sktlim@umich.edu            decode_template.subst(iop),
6644032Sktlim@umich.edu            EACompExecute.subst(ea_iop)
6653228Sktlim@umich.edu            + memAccExecTemplate.subst(memacc_iop)
6663228Sktlim@umich.edu            + fullExecTemplate.subst(iop)
6674032Sktlim@umich.edu            + initiateAccTemplate.subst(initiateacc_iop)
6684032Sktlim@umich.edu            + completeAccTemplate.subst(completeacc_iop))
6693228Sktlim@umich.edu}};
6703221Sktlim@umich.edu
6713221Sktlim@umich.edudef format LoadOrNop(memacc_code, ea_code = {{ EA = Rb + disp; }},
6723221Sktlim@umich.edu                     mem_flags = [], inst_flags = []) {{
6732907Sktlim@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
6742907Sktlim@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6752907Sktlim@umich.edu                      decode_template = LoadNopCheckDecode,
6762907Sktlim@umich.edu                      exec_template_base = 'Load')
6772907Sktlim@umich.edu}};
6782907Sktlim@umich.edu
6792907Sktlim@umich.edu
6802907Sktlim@umich.edu// Note that the flags passed in apply only to the prefetch version
6812907Sktlim@umich.edudef format LoadOrPrefetch(memacc_code, ea_code = {{ EA = Rb + disp; }},
6824032Sktlim@umich.edu                          mem_flags = [], pf_flags = [], inst_flags = []) {{
6834032Sktlim@umich.edu    # declare the load instruction object and generate the decode block
6844032Sktlim@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
6852727Sktlim@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6863014Srdreslin@umich.edu                      decode_template = LoadPrefetchCheckDecode,
6873014Srdreslin@umich.edu                      exec_template_base = 'Load')
6882669Sktlim@umich.edu
6892669Sktlim@umich.edu    # Declare the prefetch instruction object.
6902669Sktlim@umich.edu
6912292SN/A    # Make sure flag args are lists so we can mess with them.
6922669Sktlim@umich.edu    mem_flags = makeList(mem_flags)
6932669Sktlim@umich.edu    pf_flags = makeList(pf_flags)
6942669Sktlim@umich.edu    inst_flags = makeList(inst_flags)
6952669Sktlim@umich.edu
6962669Sktlim@umich.edu    pf_mem_flags = mem_flags + pf_flags + ['NO_FAULT']
6972669Sktlim@umich.edu    pf_inst_flags = inst_flags + ['IsMemRef', 'IsLoad',
6982669Sktlim@umich.edu                                  'IsDataPrefetch', 'MemReadOp']
6992669Sktlim@umich.edu
7002292SN/A    (pf_header_output, pf_decoder_output, _, pf_exec_output) = \
7012292SN/A        LoadStoreBase(name, Name + 'Prefetch', ea_code,
7022669Sktlim@umich.edu                      'xc->prefetch(EA, memAccessFlags);',
7032292SN/A                      pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
7042292SN/A
7052292SN/A    header_output += pf_header_output
7062292SN/A    decoder_output += pf_decoder_output
7072292SN/A    exec_output += pf_exec_output
7082669Sktlim@umich.edu}};
7092292SN/A
7102292SN/A
7112292SN/Adef format Store(memacc_code, ea_code = {{ EA = Rb + disp; }},
7122292SN/A                 mem_flags = [], inst_flags = []) {{
7132292SN/A    (header_output, decoder_output, decode_block, exec_output) = \
7142669Sktlim@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
7152292SN/A                      exec_template_base = 'Store')
7162329SN/A}};
7172292SN/A
7182292SN/A
7192292SN/Adef format StoreCond(memacc_code, postacc_code,
7202329SN/A                     ea_code = {{ EA = Rb + disp; }},
7212292SN/A                     mem_flags = [], inst_flags = []) {{
7222292SN/A    (header_output, decoder_output, decode_block, exec_output) = \
7232292SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
7242292SN/A                      postacc_code, exec_template_base = 'StoreCond')
7252292SN/A}};
7262292SN/A
727
728// Use 'MemoryNoDisp' as base: for wh64, fetch, ecb
729def 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')
734}};
735
736
737