mem.isa revision 3953
12124SN/A// -*- mode:c++ -*-
22124SN/A
32754Sksewell@umich.edu// Copyright (c) 2006 The Regents of The University of Michigan
42124SN/A// All rights reserved.
52022SN/A//
62124SN/A// Redistribution and use in source and binary forms, with or without
72124SN/A// modification, are permitted provided that the following conditions are
82124SN/A// met: redistributions of source code must retain the above copyright
92124SN/A// notice, this list of conditions and the following disclaimer;
102124SN/A// redistributions in binary form must reproduce the above copyright
112124SN/A// notice, this list of conditions and the following disclaimer in the
122124SN/A// documentation and/or other materials provided with the distribution;
132124SN/A// neither the name of the copyright holders nor the names of its
142124SN/A// contributors may be used to endorse or promote products derived from
152124SN/A// this software without specific prior written permission.
162022SN/A//
172124SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182124SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192124SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202124SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212124SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222124SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232124SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242124SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252124SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262124SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272124SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu//
292935Sksewell@umich.edu// Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu//          Korey Sewell
312022SN/A
322649Ssaidi@eecs.umich.edu////////////////////////////////////////////////////////////////////
332649Ssaidi@eecs.umich.edu//
342706Sksewell@umich.edu// Memory-format instructions
352649Ssaidi@eecs.umich.edu//
362649Ssaidi@eecs.umich.edu
372022SN/Aoutput header {{
382124SN/A    /**
392124SN/A     * Base class for general Mips memory-format instructions.
402124SN/A     */
412124SN/A    class Memory : public MipsStaticInst
422124SN/A    {
432124SN/A      protected:
442124SN/A
452124SN/A        /// Memory request flags.  See mem_req_base.hh.
462124SN/A        unsigned memAccessFlags;
472124SN/A        /// Pointer to EAComp object.
482124SN/A        const StaticInstPtr eaCompPtr;
492124SN/A        /// Pointer to MemAcc object.
502124SN/A        const StaticInstPtr memAccPtr;
512239SN/A
522124SN/A        /// Displacement for EA calculation (signed).
532124SN/A        int32_t disp;
542124SN/A
552124SN/A        /// Constructor
562124SN/A        Memory(const char *mnem, MachInst _machInst, OpClass __opClass,
572124SN/A               StaticInstPtr _eaCompPtr = nullStaticInstPtr,
582124SN/A               StaticInstPtr _memAccPtr = nullStaticInstPtr)
592124SN/A            : MipsStaticInst(mnem, _machInst, __opClass),
602124SN/A              memAccessFlags(0), eaCompPtr(_eaCompPtr), memAccPtr(_memAccPtr),
612742Sksewell@umich.edu              disp(sext<16>(OFFSET))
622022SN/A        {
632124SN/A        }
642022SN/A
652124SN/A        std::string
662124SN/A        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
672022SN/A
682124SN/A      public:
692124SN/A
702124SN/A        const StaticInstPtr &eaCompInst() const { return eaCompPtr; }
712124SN/A        const StaticInstPtr &memAccInst() const { return memAccPtr; }
722124SN/A    };
732124SN/A
742742Sksewell@umich.edu     /**
752742Sksewell@umich.edu     * Base class for a few miscellaneous memory-format insts
762742Sksewell@umich.edu     * that don't interpret the disp field
772742Sksewell@umich.edu     */
782742Sksewell@umich.edu    class MemoryNoDisp : public Memory
792742Sksewell@umich.edu    {
802742Sksewell@umich.edu      protected:
812742Sksewell@umich.edu        /// Constructor
822742Sksewell@umich.edu        MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
832742Sksewell@umich.edu                     StaticInstPtr _eaCompPtr = nullStaticInstPtr,
842742Sksewell@umich.edu                     StaticInstPtr _memAccPtr = nullStaticInstPtr)
852742Sksewell@umich.edu            : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr)
862742Sksewell@umich.edu        {
872742Sksewell@umich.edu        }
882742Sksewell@umich.edu
892742Sksewell@umich.edu        std::string
902742Sksewell@umich.edu        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
912742Sksewell@umich.edu    };
922022SN/A}};
932022SN/A
942124SN/A
952022SN/Aoutput decoder {{
962124SN/A    std::string
972124SN/A    Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
982124SN/A    {
992742Sksewell@umich.edu        return csprintf("%-10s %c%d, %d(r%d)", mnemonic,
1002239SN/A                        flags[IsFloating] ? 'f' : 'r', RT, disp, RS);
1012124SN/A    }
1022124SN/A
1032742Sksewell@umich.edu    std::string
1042742Sksewell@umich.edu    MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1052742Sksewell@umich.edu    {
1062742Sksewell@umich.edu        return csprintf("%-10s %c%d, r%d(r%d)", mnemonic,
1072742Sksewell@umich.edu                        flags[IsFloating] ? 'f' : 'r',
1082742Sksewell@umich.edu                        flags[IsFloating] ? FD : RD,
1092742Sksewell@umich.edu                        RS, RT);
1102742Sksewell@umich.edu    }
1112022SN/A}};
1122022SN/A
1132124SN/Adef template LoadStoreDeclare {{
1142124SN/A    /**
1152124SN/A     * Static instruction class for "%(mnemonic)s".
1162124SN/A     */
1172124SN/A    class %(class_name)s : public %(base_class)s
1182124SN/A    {
1192124SN/A      protected:
1202124SN/A
1212124SN/A        /**
1222124SN/A         * "Fake" effective address computation class for "%(mnemonic)s".
1232124SN/A         */
1242124SN/A        class EAComp : public %(base_class)s
1252124SN/A        {
1262124SN/A          public:
1272124SN/A            /// Constructor
1282124SN/A            EAComp(MachInst machInst);
1292124SN/A
1302124SN/A            %(BasicExecDeclare)s
1312124SN/A        };
1322124SN/A
1332124SN/A        /**
1342124SN/A         * "Fake" memory access instruction class for "%(mnemonic)s".
1352124SN/A         */
1362124SN/A        class MemAcc : public %(base_class)s
1372124SN/A        {
1382124SN/A          public:
1392124SN/A            /// Constructor
1402124SN/A            MemAcc(MachInst machInst);
1412124SN/A
1422124SN/A            %(BasicExecDeclare)s
1432124SN/A        };
1442124SN/A
1452124SN/A      public:
1462124SN/A
1472124SN/A        /// Constructor.
1482124SN/A        %(class_name)s(MachInst machInst);
1492124SN/A
1502124SN/A        %(BasicExecDeclare)s
1512124SN/A
1522124SN/A        %(InitiateAccDeclare)s
1532124SN/A
1542124SN/A        %(CompleteAccDeclare)s
1552124SN/A    };
1562022SN/A}};
1572022SN/A
1582124SN/A
1592124SN/Adef template InitiateAccDeclare {{
1602132SN/A    Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
1612022SN/A}};
1622124SN/A
1632124SN/A
1642124SN/Adef template CompleteAccDeclare {{
1653349Sbinkertn@umich.edu    Fault completeAcc(PacketPtr, %(CPU_exec_context)s *, Trace::InstRecord *) const;
1662124SN/A}};
1672124SN/A
1682124SN/A
1693953Sstever@eecs.umich.edudef template EACompConstructor {{
1702124SN/A    /** TODO: change op_class to AddrGenOp or something (requires
1712124SN/A     * creating new member of OpClass enum in op_class.hh, updating
1722124SN/A     * config files, etc.). */
1732124SN/A    inline %(class_name)s::EAComp::EAComp(MachInst machInst)
1742124SN/A        : %(base_class)s("%(mnemonic)s (EAComp)", machInst, IntAluOp)
1752124SN/A    {
1763953Sstever@eecs.umich.edu        %(constructor)s;
1772124SN/A    }
1783953Sstever@eecs.umich.edu}};
1792124SN/A
1803953Sstever@eecs.umich.edu
1813953Sstever@eecs.umich.edudef template MemAccConstructor {{
1822124SN/A    inline %(class_name)s::MemAcc::MemAcc(MachInst machInst)
1832124SN/A        : %(base_class)s("%(mnemonic)s (MemAcc)", machInst, %(op_class)s)
1842124SN/A    {
1853953Sstever@eecs.umich.edu        %(constructor)s;
1862124SN/A    }
1873953Sstever@eecs.umich.edu}};
1882124SN/A
1893953Sstever@eecs.umich.edu
1903953Sstever@eecs.umich.edudef template LoadStoreConstructor {{
1912124SN/A    inline %(class_name)s::%(class_name)s(MachInst machInst)
1922124SN/A         : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
1932124SN/A                          new EAComp(machInst), new MemAcc(machInst))
1942124SN/A    {
1952124SN/A        %(constructor)s;
1962124SN/A    }
1972124SN/A}};
1982124SN/A
1992124SN/A
2002124SN/Adef template EACompExecute {{
2012132SN/A    Fault
2022124SN/A    %(class_name)s::EAComp::execute(%(CPU_exec_context)s *xc,
2032124SN/A                                   Trace::InstRecord *traceData) const
2042124SN/A    {
2052124SN/A        Addr EA;
2062132SN/A        Fault fault = NoFault;
2072124SN/A
2082124SN/A        %(fp_enable_check)s;
2092124SN/A        %(op_decl)s;
2102124SN/A        %(op_rd)s;
2113953Sstever@eecs.umich.edu        %(ea_code)s;
2122124SN/A
2132124SN/A        if (fault == NoFault) {
2142124SN/A            %(op_wb)s;
2152124SN/A            xc->setEA(EA);
2162124SN/A        }
2172124SN/A
2182124SN/A        return fault;
2192124SN/A    }
2202124SN/A}};
2212124SN/A
2222124SN/Adef template LoadMemAccExecute {{
2232132SN/A    Fault
2242124SN/A    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
2252124SN/A                                   Trace::InstRecord *traceData) const
2262124SN/A    {
2272239SN/A        Addr EA;
2282132SN/A        Fault fault = NoFault;
2292239SN/A
2302239SN/A        %(fp_enable_check)s;
2312239SN/A        %(op_decl)s;
2322239SN/A        %(op_rd)s;
2332239SN/A        EA = xc->getEA();
2342239SN/A
2352239SN/A        if (fault == NoFault) {
2362239SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2373953Sstever@eecs.umich.edu            %(memacc_code)s;
2382239SN/A        }
2392239SN/A
2402239SN/A        if (fault == NoFault) {
2412239SN/A            %(op_wb)s;
2422239SN/A        }
2432239SN/A
2442124SN/A        return fault;
2452124SN/A    }
2462124SN/A}};
2472124SN/A
2482124SN/A
2492124SN/Adef template LoadExecute {{
2502132SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
2512124SN/A                                  Trace::InstRecord *traceData) const
2522124SN/A    {
2532124SN/A        Addr EA;
2542132SN/A        Fault fault = NoFault;
2552124SN/A
2562124SN/A        %(fp_enable_check)s;
2572124SN/A        %(op_decl)s;
2582124SN/A        %(op_rd)s;
2592124SN/A        %(ea_code)s;
2602124SN/A
2612124SN/A        if (fault == NoFault) {
2622124SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2632124SN/A            %(memacc_code)s;
2642124SN/A        }
2652124SN/A
2662124SN/A        if (fault == NoFault) {
2672124SN/A            %(op_wb)s;
2682124SN/A        }
2692124SN/A
2702124SN/A        return fault;
2712124SN/A    }
2722124SN/A}};
2732124SN/A
2742124SN/A
2752124SN/Adef template LoadInitiateAcc {{
2762132SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
2772124SN/A                                      Trace::InstRecord *traceData) const
2782124SN/A    {
2792239SN/A        Addr EA;
2802132SN/A        Fault fault = NoFault;
2812239SN/A
2822239SN/A        %(fp_enable_check)s;
2832239SN/A        %(op_src_decl)s;
2842239SN/A        %(op_rd)s;
2852239SN/A        %(ea_code)s;
2862239SN/A
2872239SN/A        if (fault == NoFault) {
2882239SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t &)Mem, memAccessFlags);
2892239SN/A        }
2902239SN/A
2912124SN/A        return fault;
2922124SN/A    }
2932124SN/A}};
2942124SN/A
2952124SN/A
2962124SN/Adef template LoadCompleteAcc {{
2973349Sbinkertn@umich.edu    Fault %(class_name)s::completeAcc(PacketPtr pkt,
2982124SN/A                                      %(CPU_exec_context)s *xc,
2992124SN/A                                      Trace::InstRecord *traceData) const
3002124SN/A    {
3012132SN/A        Fault fault = NoFault;
3022239SN/A
3032239SN/A        %(fp_enable_check)s;
3042506SN/A        %(op_decl)s;
3052239SN/A
3062935Sksewell@umich.edu        Mem = pkt->get<typeof(Mem)>();
3072239SN/A
3082239SN/A        if (fault == NoFault) {
3092239SN/A            %(memacc_code)s;
3102239SN/A        }
3112239SN/A
3122239SN/A        if (fault == NoFault) {
3132239SN/A            %(op_wb)s;
3142239SN/A        }
3152239SN/A
3162124SN/A        return fault;
3172124SN/A    }
3182124SN/A}};
3192124SN/A
3202124SN/A
3212124SN/Adef template StoreMemAccExecute {{
3222132SN/A    Fault
3232124SN/A    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
3242124SN/A                                   Trace::InstRecord *traceData) const
3252124SN/A    {
3262239SN/A        Addr EA;
3272132SN/A        Fault fault = NoFault;
3282239SN/A        uint64_t write_result = 0;
3292239SN/A
3302239SN/A        %(fp_enable_check)s;
3312239SN/A        %(op_decl)s;
3322239SN/A        %(op_rd)s;
3332239SN/A        EA = xc->getEA();
3342239SN/A
3352239SN/A        if (fault == NoFault) {
3363953Sstever@eecs.umich.edu            %(memacc_code)s;
3372239SN/A        }
3382239SN/A
3392239SN/A        if (fault == NoFault) {
3402239SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
3412239SN/A                              memAccessFlags, &write_result);
3422239SN/A            if (traceData) { traceData->setData(Mem); }
3432239SN/A        }
3442239SN/A
3452239SN/A        if (fault == NoFault) {
3462239SN/A            %(postacc_code)s;
3472239SN/A        }
3482239SN/A
3492239SN/A        if (fault == NoFault) {
3502239SN/A            %(op_wb)s;
3512239SN/A        }
3522239SN/A
3532124SN/A        return fault;
3542124SN/A    }
3552124SN/A}};
3562124SN/A
3572124SN/A
3582124SN/Adef template StoreExecute {{
3592132SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
3602124SN/A                                  Trace::InstRecord *traceData) const
3612124SN/A    {
3622124SN/A        Addr EA;
3632132SN/A        Fault fault = NoFault;
3642124SN/A        uint64_t write_result = 0;
3652124SN/A
3662124SN/A        %(fp_enable_check)s;
3672124SN/A        %(op_decl)s;
3682124SN/A        %(op_rd)s;
3692124SN/A        %(ea_code)s;
3702124SN/A
3712124SN/A        if (fault == NoFault) {
3722124SN/A            %(memacc_code)s;
3732124SN/A        }
3742124SN/A
3752124SN/A        if (fault == NoFault) {
3762124SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
3772124SN/A                              memAccessFlags, &write_result);
3782124SN/A            if (traceData) { traceData->setData(Mem); }
3792124SN/A        }
3802124SN/A
3812124SN/A        if (fault == NoFault) {
3822124SN/A            %(postacc_code)s;
3832124SN/A        }
3842124SN/A
3852124SN/A        if (fault == NoFault) {
3862124SN/A            %(op_wb)s;
3872124SN/A        }
3882124SN/A
3892124SN/A        return fault;
3902124SN/A    }
3912124SN/A}};
3922124SN/A
3932124SN/Adef template StoreInitiateAcc {{
3942132SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
3952124SN/A                                      Trace::InstRecord *traceData) const
3962124SN/A    {
3972239SN/A        Addr EA;
3982132SN/A        Fault fault = NoFault;
3992239SN/A
4002239SN/A        %(fp_enable_check)s;
4012506SN/A        %(op_decl)s;
4022239SN/A        %(op_rd)s;
4032239SN/A        %(ea_code)s;
4042239SN/A
4052239SN/A        if (fault == NoFault) {
4062239SN/A            %(memacc_code)s;
4072239SN/A        }
4082239SN/A
4092239SN/A        if (fault == NoFault) {
4102239SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
4112935Sksewell@umich.edu                              memAccessFlags, NULL);
4122239SN/A            if (traceData) { traceData->setData(Mem); }
4132239SN/A        }
4142239SN/A
4152124SN/A        return fault;
4162124SN/A    }
4172124SN/A}};
4182124SN/A
4192124SN/A
4202124SN/Adef template StoreCompleteAcc {{
4213349Sbinkertn@umich.edu    Fault %(class_name)s::completeAcc(PacketPtr pkt,
4222124SN/A                                      %(CPU_exec_context)s *xc,
4232124SN/A                                      Trace::InstRecord *traceData) const
4242124SN/A    {
4252132SN/A        Fault fault = NoFault;
4262239SN/A
4272239SN/A        %(fp_enable_check)s;
4282239SN/A        %(op_dest_decl)s;
4292239SN/A
4302935Sksewell@umich.edu        if (fault == NoFault) {
4312935Sksewell@umich.edu            %(postacc_code)s;
4322935Sksewell@umich.edu        }
4332935Sksewell@umich.edu
4342935Sksewell@umich.edu        if (fault == NoFault) {
4352935Sksewell@umich.edu            %(op_wb)s;
4362935Sksewell@umich.edu        }
4372935Sksewell@umich.edu
4382935Sksewell@umich.edu        return fault;
4392935Sksewell@umich.edu    }
4402935Sksewell@umich.edu}};
4412935Sksewell@umich.edu
4422935Sksewell@umich.edudef template StoreCondCompleteAcc {{
4433349Sbinkertn@umich.edu    Fault %(class_name)s::completeAcc(PacketPtr pkt,
4442935Sksewell@umich.edu                                      %(CPU_exec_context)s *xc,
4452935Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
4462935Sksewell@umich.edu    {
4472935Sksewell@umich.edu        Fault fault = NoFault;
4482935Sksewell@umich.edu
4492935Sksewell@umich.edu        %(fp_enable_check)s;
4502935Sksewell@umich.edu        %(op_dest_decl)s;
4512935Sksewell@umich.edu
4522935Sksewell@umich.edu        uint64_t write_result = pkt->req->getScResult();
4532239SN/A
4542239SN/A        if (fault == NoFault) {
4552239SN/A            %(postacc_code)s;
4562239SN/A        }
4572239SN/A
4582239SN/A        if (fault == NoFault) {
4592239SN/A            %(op_wb)s;
4602239SN/A        }
4612239SN/A
4622124SN/A        return fault;
4632124SN/A    }
4642124SN/A}};
4652124SN/A
4662686Sksewell@umich.edu
4672686Sksewell@umich.edudef template MiscMemAccExecute {{
4682686Sksewell@umich.edu    Fault %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
4692686Sksewell@umich.edu                                          Trace::InstRecord *traceData) const
4702686Sksewell@umich.edu    {
4712686Sksewell@umich.edu        Addr EA;
4722686Sksewell@umich.edu        Fault fault = NoFault;
4732686Sksewell@umich.edu
4742686Sksewell@umich.edu        %(fp_enable_check)s;
4752686Sksewell@umich.edu        %(op_decl)s;
4762686Sksewell@umich.edu        %(op_rd)s;
4772686Sksewell@umich.edu        EA = xc->getEA();
4782686Sksewell@umich.edu
4792686Sksewell@umich.edu        if (fault == NoFault) {
4803953Sstever@eecs.umich.edu            %(memacc_code)s;
4812686Sksewell@umich.edu        }
4822686Sksewell@umich.edu
4832686Sksewell@umich.edu        return NoFault;
4842686Sksewell@umich.edu    }
4852686Sksewell@umich.edu}};
4862686Sksewell@umich.edu
4872686Sksewell@umich.edudef template MiscExecute {{
4882686Sksewell@umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
4892686Sksewell@umich.edu                                  Trace::InstRecord *traceData) const
4902686Sksewell@umich.edu    {
4912686Sksewell@umich.edu        Addr EA;
4922686Sksewell@umich.edu        Fault fault = NoFault;
4932686Sksewell@umich.edu
4942686Sksewell@umich.edu        %(fp_enable_check)s;
4952686Sksewell@umich.edu        %(op_decl)s;
4962686Sksewell@umich.edu        %(op_rd)s;
4972686Sksewell@umich.edu        %(ea_code)s;
4982686Sksewell@umich.edu
4992686Sksewell@umich.edu        if (fault == NoFault) {
5002686Sksewell@umich.edu            %(memacc_code)s;
5012686Sksewell@umich.edu        }
5022686Sksewell@umich.edu
5032686Sksewell@umich.edu        return NoFault;
5042686Sksewell@umich.edu    }
5052686Sksewell@umich.edu}};
5062686Sksewell@umich.edu
5072686Sksewell@umich.edudef template MiscInitiateAcc {{
5082686Sksewell@umich.edu    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
5092686Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
5102686Sksewell@umich.edu    {
5112686Sksewell@umich.edu        panic("Misc instruction does not support split access method!");
5122686Sksewell@umich.edu        return NoFault;
5132686Sksewell@umich.edu    }
5142686Sksewell@umich.edu}};
5152686Sksewell@umich.edu
5162686Sksewell@umich.edu
5172686Sksewell@umich.edudef template MiscCompleteAcc {{
5183349Sbinkertn@umich.edu    Fault %(class_name)s::completeAcc(PacketPtr pkt,
5192686Sksewell@umich.edu                                      %(CPU_exec_context)s *xc,
5202686Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
5212686Sksewell@umich.edu    {
5222686Sksewell@umich.edu        panic("Misc instruction does not support split access method!");
5232686Sksewell@umich.edu
5242686Sksewell@umich.edu        return NoFault;
5252686Sksewell@umich.edu    }
5262686Sksewell@umich.edu}};
5272686Sksewell@umich.edu
5282124SN/Adef format LoadMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
5292124SN/A                     mem_flags = [], inst_flags = []) {{
5302124SN/A    (header_output, decoder_output, decode_block, exec_output) = \
5312124SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5322750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
5332124SN/A                      exec_template_base = 'Load')
5342124SN/A}};
5352124SN/A
5362124SN/Adef format StoreMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
5372124SN/A                     mem_flags = [], inst_flags = []) {{
5382124SN/A    (header_output, decoder_output, decode_block, exec_output) = \
5392124SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5402124SN/A                      exec_template_base = 'Store')
5412124SN/A}};
5422124SN/A
5432686Sksewell@umich.edudef format LoadIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
5442573SN/A                     mem_flags = [], inst_flags = []) {{
5452573SN/A    (header_output, decoder_output, decode_block, exec_output) = \
5462573SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5472750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
5482573SN/A                      exec_template_base = 'Load')
5492573SN/A}};
5502573SN/A
5512686Sksewell@umich.edudef format StoreIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
5522573SN/A                     mem_flags = [], inst_flags = []) {{
5532573SN/A    (header_output, decoder_output, decode_block, exec_output) = \
5542573SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5552573SN/A                      exec_template_base = 'Store')
5562573SN/A}};
5572573SN/A
5582686Sksewell@umich.edudef format LoadUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
5592686Sksewell@umich.edu                     mem_flags = [], inst_flags = []) {{
5602686Sksewell@umich.edu    decl_code = 'uint32_t mem_word = Mem.uw;\n'
5612686Sksewell@umich.edu    decl_code += 'uint32_t unalign_addr = Rs + disp;\n'
5622686Sksewell@umich.edu    decl_code += 'uint32_t byte_offset = unalign_addr & 3;\n'
5632686Sksewell@umich.edu    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
5642686Sksewell@umich.edu    decl_code += '\tbyte_offset ^= 3;\n'
5652686Sksewell@umich.edu    decl_code += '#endif\n'
5662573SN/A
5672686Sksewell@umich.edu    memacc_code = decl_code + memacc_code
5682686Sksewell@umich.edu
5692686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
5702686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5712750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
5722686Sksewell@umich.edu                      exec_template_base = 'Load')
5732686Sksewell@umich.edu}};
5742686Sksewell@umich.edu
5752686Sksewell@umich.edudef format StoreUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
5762686Sksewell@umich.edu                     mem_flags = [], inst_flags = []) {{
5772686Sksewell@umich.edu    decl_code = 'uint32_t mem_word = 0;\n'
5782686Sksewell@umich.edu    decl_code += 'uint32_t unaligned_addr = Rs + disp;\n'
5792686Sksewell@umich.edu    decl_code += 'uint32_t byte_offset = unaligned_addr & 3;\n'
5802686Sksewell@umich.edu    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
5812686Sksewell@umich.edu    decl_code += '\tbyte_offset ^= 3;\n'
5822686Sksewell@umich.edu    decl_code += '#endif\n'
5832686Sksewell@umich.edu    decl_code += 'fault = xc->read(EA, (uint32_t&)mem_word, memAccessFlags);\n'
5842686Sksewell@umich.edu    memacc_code = decl_code + memacc_code + '\nMem = mem_word;\n'
5852686Sksewell@umich.edu
5862686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
5872686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
5882686Sksewell@umich.edu                      exec_template_base = 'Store')
5892686Sksewell@umich.edu}};
5902686Sksewell@umich.edu
5912686Sksewell@umich.edudef format Prefetch(ea_code = {{ EA = Rs + disp; }},
5922686Sksewell@umich.edu                          mem_flags = [], pf_flags = [], inst_flags = []) {{
5932686Sksewell@umich.edu    pf_mem_flags = mem_flags + pf_flags + ['NO_FAULT']
5942686Sksewell@umich.edu    pf_inst_flags = inst_flags + ['IsMemRef', 'IsLoad',
5952686Sksewell@umich.edu                                  'IsDataPrefetch', 'MemReadOp']
5962686Sksewell@umich.edu
5972686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
5982686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code,
5992686Sksewell@umich.edu                      'xc->prefetch(EA, memAccessFlags);',
6002686Sksewell@umich.edu                      pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
6012686Sksewell@umich.edu
6022686Sksewell@umich.edu}};
6032686Sksewell@umich.edu
6042686Sksewell@umich.edudef format StoreCond(memacc_code, postacc_code,
6052686Sksewell@umich.edu                     ea_code = {{ EA = Rs + disp; }},
6062495SN/A                     mem_flags = [], inst_flags = []) {{
6072495SN/A    (header_output, decoder_output, decode_block, exec_output) = \
6082495SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6092935Sksewell@umich.edu                      postacc_code, exec_template_base = 'StoreCond')
6102495SN/A}};
611