mem.isa revision 4661
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; }
724661Sksewell@umich.edu
734661Sksewell@umich.edu        unsigned memAccFlags() { return memAccessFlags; }
742124SN/A    };
752124SN/A
762742Sksewell@umich.edu     /**
772742Sksewell@umich.edu     * Base class for a few miscellaneous memory-format insts
782742Sksewell@umich.edu     * that don't interpret the disp field
792742Sksewell@umich.edu     */
802742Sksewell@umich.edu    class MemoryNoDisp : public Memory
812742Sksewell@umich.edu    {
822742Sksewell@umich.edu      protected:
832742Sksewell@umich.edu        /// Constructor
842742Sksewell@umich.edu        MemoryNoDisp(const char *mnem, ExtMachInst _machInst, OpClass __opClass,
852742Sksewell@umich.edu                     StaticInstPtr _eaCompPtr = nullStaticInstPtr,
862742Sksewell@umich.edu                     StaticInstPtr _memAccPtr = nullStaticInstPtr)
872742Sksewell@umich.edu            : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr)
882742Sksewell@umich.edu        {
892742Sksewell@umich.edu        }
902742Sksewell@umich.edu
912742Sksewell@umich.edu        std::string
922742Sksewell@umich.edu        generateDisassembly(Addr pc, const SymbolTable *symtab) const;
932742Sksewell@umich.edu    };
942022SN/A}};
952022SN/A
962124SN/A
972022SN/Aoutput decoder {{
982124SN/A    std::string
992124SN/A    Memory::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1002124SN/A    {
1012742Sksewell@umich.edu        return csprintf("%-10s %c%d, %d(r%d)", mnemonic,
1022239SN/A                        flags[IsFloating] ? 'f' : 'r', RT, disp, RS);
1032124SN/A    }
1042124SN/A
1052742Sksewell@umich.edu    std::string
1062742Sksewell@umich.edu    MemoryNoDisp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
1072742Sksewell@umich.edu    {
1082742Sksewell@umich.edu        return csprintf("%-10s %c%d, r%d(r%d)", mnemonic,
1092742Sksewell@umich.edu                        flags[IsFloating] ? 'f' : 'r',
1102742Sksewell@umich.edu                        flags[IsFloating] ? FD : RD,
1112742Sksewell@umich.edu                        RS, RT);
1122742Sksewell@umich.edu    }
1134661Sksewell@umich.edu
1144661Sksewell@umich.edu}};
1154661Sksewell@umich.edu
1164661Sksewell@umich.eduoutput exec {{
1174661Sksewell@umich.edu    /** return data in cases where there the size of data is only
1184661Sksewell@umich.edu        known in the packet
1194661Sksewell@umich.edu    */
1204661Sksewell@umich.edu    uint64_t getStoreData(Packet *packet) {
1214661Sksewell@umich.edu        switch (packet->getSize())
1224661Sksewell@umich.edu        {
1234661Sksewell@umich.edu          case 8:
1244661Sksewell@umich.edu            return packet->get<uint8_t>();
1254661Sksewell@umich.edu
1264661Sksewell@umich.edu          case 16:
1274661Sksewell@umich.edu            return packet->get<uint16_t>();
1284661Sksewell@umich.edu
1294661Sksewell@umich.edu          case 32:
1304661Sksewell@umich.edu            return packet->get<uint32_t>();
1314661Sksewell@umich.edu
1324661Sksewell@umich.edu          case 864:
1334661Sksewell@umich.edu            return packet->get<uint64_t>();
1344661Sksewell@umich.edu
1354661Sksewell@umich.edu          default:
1364661Sksewell@umich.edu            std::cerr << "bad store data size = " << packet->getSize() << std::endl;
1374661Sksewell@umich.edu
1384661Sksewell@umich.edu            assert(0);
1394661Sksewell@umich.edu            return 0;
1404661Sksewell@umich.edu        }
1414661Sksewell@umich.edu    }
1424661Sksewell@umich.edu
1434661Sksewell@umich.edu
1442022SN/A}};
1452022SN/A
1462124SN/Adef template LoadStoreDeclare {{
1472124SN/A    /**
1482124SN/A     * Static instruction class for "%(mnemonic)s".
1492124SN/A     */
1502124SN/A    class %(class_name)s : public %(base_class)s
1512124SN/A    {
1522124SN/A      protected:
1532124SN/A
1542124SN/A        /**
1552124SN/A         * "Fake" effective address computation class for "%(mnemonic)s".
1562124SN/A         */
1572124SN/A        class EAComp : public %(base_class)s
1582124SN/A        {
1592124SN/A          public:
1602124SN/A            /// Constructor
1614661Sksewell@umich.edu            EAComp(ExtMachInst machInst);
1622124SN/A
1632124SN/A            %(BasicExecDeclare)s
1642124SN/A        };
1652124SN/A
1662124SN/A        /**
1672124SN/A         * "Fake" memory access instruction class for "%(mnemonic)s".
1682124SN/A         */
1692124SN/A        class MemAcc : public %(base_class)s
1702124SN/A        {
1712124SN/A          public:
1722124SN/A            /// Constructor
1734661Sksewell@umich.edu            MemAcc(ExtMachInst machInst);
1742124SN/A
1752124SN/A            %(BasicExecDeclare)s
1762124SN/A        };
1772124SN/A
1782124SN/A      public:
1792124SN/A
1802124SN/A        /// Constructor.
1814661Sksewell@umich.edu        %(class_name)s(ExtMachInst machInst);
1822124SN/A
1832124SN/A        %(BasicExecDeclare)s
1842124SN/A
1852124SN/A        %(InitiateAccDeclare)s
1862124SN/A
1872124SN/A        %(CompleteAccDeclare)s
1884661Sksewell@umich.edu
1894661Sksewell@umich.edu        %(MemAccSizeDeclare)s
1902124SN/A    };
1912022SN/A}};
1922022SN/A
1932124SN/A
1942124SN/Adef template InitiateAccDeclare {{
1952132SN/A    Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;
1962022SN/A}};
1972124SN/A
1982124SN/A
1992124SN/Adef template CompleteAccDeclare {{
2004661Sksewell@umich.edu    Fault completeAcc(Packet *, %(CPU_exec_context)s *, Trace::InstRecord *) const;
2012124SN/A}};
2022124SN/A
2034661Sksewell@umich.edudef template MemAccSizeDeclare {{
2044661Sksewell@umich.edu    int memAccSize(%(CPU_exec_context)s *xc);
2054661Sksewell@umich.edu}};
2062124SN/A
2073953Sstever@eecs.umich.edudef template EACompConstructor {{
2082124SN/A    /** TODO: change op_class to AddrGenOp or something (requires
2092124SN/A     * creating new member of OpClass enum in op_class.hh, updating
2102124SN/A     * config files, etc.). */
2114661Sksewell@umich.edu    inline %(class_name)s::EAComp::EAComp(ExtMachInst machInst)
2122124SN/A        : %(base_class)s("%(mnemonic)s (EAComp)", machInst, IntAluOp)
2132124SN/A    {
2143953Sstever@eecs.umich.edu        %(constructor)s;
2152124SN/A    }
2163953Sstever@eecs.umich.edu}};
2172124SN/A
2183953Sstever@eecs.umich.edu
2193953Sstever@eecs.umich.edudef template MemAccConstructor {{
2204661Sksewell@umich.edu    inline %(class_name)s::MemAcc::MemAcc(ExtMachInst machInst)
2212124SN/A        : %(base_class)s("%(mnemonic)s (MemAcc)", machInst, %(op_class)s)
2222124SN/A    {
2233953Sstever@eecs.umich.edu        %(constructor)s;
2242124SN/A    }
2253953Sstever@eecs.umich.edu}};
2262124SN/A
2273953Sstever@eecs.umich.edu
2283953Sstever@eecs.umich.edudef template LoadStoreConstructor {{
2294661Sksewell@umich.edu    inline %(class_name)s::%(class_name)s(ExtMachInst machInst)
2302124SN/A         : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
2312124SN/A                          new EAComp(machInst), new MemAcc(machInst))
2322124SN/A    {
2332124SN/A        %(constructor)s;
2342124SN/A    }
2352124SN/A}};
2362124SN/A
2372124SN/A
2382124SN/Adef template EACompExecute {{
2392132SN/A    Fault
2402124SN/A    %(class_name)s::EAComp::execute(%(CPU_exec_context)s *xc,
2412124SN/A                                   Trace::InstRecord *traceData) const
2422124SN/A    {
2432124SN/A        Addr EA;
2442132SN/A        Fault fault = NoFault;
2452124SN/A
2462124SN/A        %(fp_enable_check)s;
2472124SN/A        %(op_decl)s;
2482124SN/A        %(op_rd)s;
2493953Sstever@eecs.umich.edu        %(ea_code)s;
2502124SN/A
2514661Sksewell@umich.edu        // NOTE: Trace Data is written using execute or completeAcc templates
2522124SN/A        if (fault == NoFault) {
2532124SN/A            xc->setEA(EA);
2542124SN/A        }
2552124SN/A
2562124SN/A        return fault;
2572124SN/A    }
2582124SN/A}};
2592124SN/A
2602124SN/Adef template LoadMemAccExecute {{
2612132SN/A    Fault
2622124SN/A    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
2632124SN/A                                   Trace::InstRecord *traceData) const
2642124SN/A    {
2652239SN/A        Addr EA;
2662132SN/A        Fault fault = NoFault;
2672239SN/A
2682239SN/A        %(op_decl)s;
2692239SN/A        %(op_rd)s;
2704661Sksewell@umich.edu
2712239SN/A        EA = xc->getEA();
2722239SN/A
2734661Sksewell@umich.edu        fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2742239SN/A
2754661Sksewell@umich.edu        %(memacc_code)s;
2764661Sksewell@umich.edu
2774661Sksewell@umich.edu        // NOTE: Write back data using execute or completeAcc templates
2782239SN/A
2792124SN/A        return fault;
2802124SN/A    }
2812124SN/A}};
2822124SN/A
2832124SN/A
2842124SN/Adef template LoadExecute {{
2852132SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
2862124SN/A                                  Trace::InstRecord *traceData) const
2872124SN/A    {
2882124SN/A        Addr EA;
2892132SN/A        Fault fault = NoFault;
2902124SN/A
2912124SN/A        %(fp_enable_check)s;
2922124SN/A        %(op_decl)s;
2932124SN/A        %(op_rd)s;
2942124SN/A        %(ea_code)s;
2952124SN/A
2962124SN/A        if (fault == NoFault) {
2972124SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t&)Mem, memAccessFlags);
2982124SN/A            %(memacc_code)s;
2992124SN/A        }
3002124SN/A
3012124SN/A        if (fault == NoFault) {
3022124SN/A            %(op_wb)s;
3032124SN/A        }
3042124SN/A
3052124SN/A        return fault;
3062124SN/A    }
3072124SN/A}};
3082124SN/A
3092124SN/A
3102124SN/Adef template LoadInitiateAcc {{
3112132SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
3122124SN/A                                      Trace::InstRecord *traceData) const
3132124SN/A    {
3142239SN/A        Addr EA;
3152132SN/A        Fault fault = NoFault;
3162239SN/A
3172239SN/A        %(fp_enable_check)s;
3182239SN/A        %(op_src_decl)s;
3192239SN/A        %(op_rd)s;
3202239SN/A        %(ea_code)s;
3212239SN/A
3222239SN/A        if (fault == NoFault) {
3232239SN/A            fault = xc->read(EA, (uint%(mem_acc_size)d_t &)Mem, memAccessFlags);
3242239SN/A        }
3252239SN/A
3262124SN/A        return fault;
3272124SN/A    }
3282124SN/A}};
3292124SN/A
3302124SN/Adef template LoadCompleteAcc {{
3314661Sksewell@umich.edu    Fault %(class_name)s::completeAcc(Packet *pkt,
3322124SN/A                                      %(CPU_exec_context)s *xc,
3332124SN/A                                      Trace::InstRecord *traceData) const
3342124SN/A    {
3352132SN/A        Fault fault = NoFault;
3362239SN/A
3372239SN/A        %(fp_enable_check)s;
3382506SN/A        %(op_decl)s;
3394661Sksewell@umich.edu        %(op_rd)s;
3402239SN/A
3412935Sksewell@umich.edu        Mem = pkt->get<typeof(Mem)>();
3422239SN/A
3432239SN/A        if (fault == NoFault) {
3442239SN/A            %(memacc_code)s;
3452239SN/A        }
3462239SN/A
3472239SN/A        if (fault == NoFault) {
3482239SN/A            %(op_wb)s;
3492239SN/A        }
3502239SN/A
3512124SN/A        return fault;
3522124SN/A    }
3532124SN/A}};
3542124SN/A
3552124SN/A
3564661Sksewell@umich.edu
3574661Sksewell@umich.edudef template LoadStoreMemAccSize {{
3584661Sksewell@umich.edu    int %(class_name)s::memAccSize(%(CPU_exec_context)s *xc)
3594661Sksewell@umich.edu    {
3604661Sksewell@umich.edu        // Return the memory access size in bytes
3614661Sksewell@umich.edu        return (%(mem_acc_size)d / 8);
3624661Sksewell@umich.edu    }
3634661Sksewell@umich.edu}};
3644661Sksewell@umich.edu
3652124SN/Adef template StoreMemAccExecute {{
3662132SN/A    Fault
3672124SN/A    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
3682124SN/A                                   Trace::InstRecord *traceData) const
3692124SN/A    {
3702239SN/A        Addr EA;
3712132SN/A        Fault fault = NoFault;
3724661Sksewell@umich.edu        uint64_t write_result = 0;
3734056Sstever@eecs.umich.edu
3744056Sstever@eecs.umich.edu        %(fp_enable_check)s;
3754056Sstever@eecs.umich.edu        %(op_decl)s;
3764056Sstever@eecs.umich.edu        %(op_rd)s;
3774661Sksewell@umich.edu
3784056Sstever@eecs.umich.edu        EA = xc->getEA();
3794056Sstever@eecs.umich.edu
3804056Sstever@eecs.umich.edu        if (fault == NoFault) {
3814056Sstever@eecs.umich.edu            %(memacc_code)s;
3824056Sstever@eecs.umich.edu        }
3834056Sstever@eecs.umich.edu
3844056Sstever@eecs.umich.edu        if (fault == NoFault) {
3854056Sstever@eecs.umich.edu            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
3864661Sksewell@umich.edu                              memAccessFlags, &write_result);
3874661Sksewell@umich.edu            // @NOTE: Need to Call Complete Access to Set Trace Data
3884661Sksewell@umich.edu            //if (traceData) { traceData->setData(Mem); }
3894056Sstever@eecs.umich.edu        }
3904056Sstever@eecs.umich.edu
3914056Sstever@eecs.umich.edu        return fault;
3924056Sstever@eecs.umich.edu    }
3934056Sstever@eecs.umich.edu}};
3944056Sstever@eecs.umich.edu
3954056Sstever@eecs.umich.edudef template StoreCondMemAccExecute {{
3964056Sstever@eecs.umich.edu    Fault
3974056Sstever@eecs.umich.edu    %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
3984056Sstever@eecs.umich.edu                                   Trace::InstRecord *traceData) const
3994056Sstever@eecs.umich.edu    {
4004056Sstever@eecs.umich.edu        Addr EA;
4014056Sstever@eecs.umich.edu        Fault fault = NoFault;
4022239SN/A        uint64_t write_result = 0;
4032239SN/A
4042239SN/A        %(fp_enable_check)s;
4052239SN/A        %(op_decl)s;
4062239SN/A        %(op_rd)s;
4072239SN/A        EA = xc->getEA();
4082239SN/A
4092239SN/A        if (fault == NoFault) {
4103953Sstever@eecs.umich.edu            %(memacc_code)s;
4112239SN/A        }
4122239SN/A
4132239SN/A        if (fault == NoFault) {
4142239SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
4152239SN/A                              memAccessFlags, &write_result);
4162239SN/A            if (traceData) { traceData->setData(Mem); }
4172239SN/A        }
4182239SN/A
4192239SN/A        if (fault == NoFault) {
4202239SN/A            %(postacc_code)s;
4212239SN/A        }
4222239SN/A
4232239SN/A        if (fault == NoFault) {
4242239SN/A            %(op_wb)s;
4252239SN/A        }
4262239SN/A
4272124SN/A        return fault;
4282124SN/A    }
4292124SN/A}};
4302124SN/A
4312124SN/Adef template StoreExecute {{
4322132SN/A    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
4332124SN/A                                  Trace::InstRecord *traceData) const
4342124SN/A    {
4352124SN/A        Addr EA;
4362132SN/A        Fault fault = NoFault;
4374661Sksewell@umich.edu        uint64_t write_result = 0;
4384056Sstever@eecs.umich.edu
4394056Sstever@eecs.umich.edu        %(fp_enable_check)s;
4404056Sstever@eecs.umich.edu        %(op_decl)s;
4414056Sstever@eecs.umich.edu        %(op_rd)s;
4424056Sstever@eecs.umich.edu        %(ea_code)s;
4434056Sstever@eecs.umich.edu
4444056Sstever@eecs.umich.edu        if (fault == NoFault) {
4454056Sstever@eecs.umich.edu            %(memacc_code)s;
4464056Sstever@eecs.umich.edu        }
4474056Sstever@eecs.umich.edu
4484056Sstever@eecs.umich.edu        if (fault == NoFault) {
4494056Sstever@eecs.umich.edu            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
4504661Sksewell@umich.edu                              memAccessFlags, &write_result);
4514056Sstever@eecs.umich.edu            if (traceData) { traceData->setData(Mem); }
4524056Sstever@eecs.umich.edu        }
4534056Sstever@eecs.umich.edu
4544056Sstever@eecs.umich.edu        if (fault == NoFault) {
4554056Sstever@eecs.umich.edu            %(postacc_code)s;
4564056Sstever@eecs.umich.edu        }
4574056Sstever@eecs.umich.edu
4584056Sstever@eecs.umich.edu        if (fault == NoFault) {
4594056Sstever@eecs.umich.edu            %(op_wb)s;
4604056Sstever@eecs.umich.edu        }
4614056Sstever@eecs.umich.edu
4624056Sstever@eecs.umich.edu        return fault;
4634056Sstever@eecs.umich.edu    }
4644056Sstever@eecs.umich.edu}};
4654056Sstever@eecs.umich.edu
4664056Sstever@eecs.umich.edudef template StoreCondExecute {{
4674056Sstever@eecs.umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
4684056Sstever@eecs.umich.edu                                  Trace::InstRecord *traceData) const
4694056Sstever@eecs.umich.edu    {
4704056Sstever@eecs.umich.edu        Addr EA;
4714056Sstever@eecs.umich.edu        Fault fault = NoFault;
4722124SN/A        uint64_t write_result = 0;
4732124SN/A
4742124SN/A        %(fp_enable_check)s;
4752124SN/A        %(op_decl)s;
4762124SN/A        %(op_rd)s;
4772124SN/A        %(ea_code)s;
4782124SN/A
4792124SN/A        if (fault == NoFault) {
4802124SN/A            %(memacc_code)s;
4812124SN/A        }
4822124SN/A
4832124SN/A        if (fault == NoFault) {
4842124SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
4852124SN/A                              memAccessFlags, &write_result);
4862124SN/A            if (traceData) { traceData->setData(Mem); }
4872124SN/A        }
4882124SN/A
4892124SN/A        if (fault == NoFault) {
4902124SN/A            %(postacc_code)s;
4912124SN/A        }
4922124SN/A
4932124SN/A        if (fault == NoFault) {
4942124SN/A            %(op_wb)s;
4952124SN/A        }
4962124SN/A
4972124SN/A        return fault;
4982124SN/A    }
4992124SN/A}};
5002124SN/A
5012124SN/Adef template StoreInitiateAcc {{
5022132SN/A    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
5032124SN/A                                      Trace::InstRecord *traceData) const
5042124SN/A    {
5052239SN/A        Addr EA;
5062132SN/A        Fault fault = NoFault;
5072239SN/A
5082239SN/A        %(fp_enable_check)s;
5092506SN/A        %(op_decl)s;
5102239SN/A        %(op_rd)s;
5112239SN/A        %(ea_code)s;
5122239SN/A
5132239SN/A        if (fault == NoFault) {
5142239SN/A            %(memacc_code)s;
5152239SN/A        }
5162239SN/A
5172239SN/A        if (fault == NoFault) {
5182239SN/A            fault = xc->write((uint%(mem_acc_size)d_t&)Mem, EA,
5192935Sksewell@umich.edu                              memAccessFlags, NULL);
5202239SN/A            if (traceData) { traceData->setData(Mem); }
5212239SN/A        }
5222239SN/A
5232124SN/A        return fault;
5242124SN/A    }
5252124SN/A}};
5262124SN/A
5272124SN/A
5282124SN/Adef template StoreCompleteAcc {{
5294661Sksewell@umich.edu    Fault %(class_name)s::completeAcc(Packet *pkt,
5302124SN/A                                      %(CPU_exec_context)s *xc,
5312124SN/A                                      Trace::InstRecord *traceData) const
5322124SN/A    {
5332132SN/A        Fault fault = NoFault;
5342239SN/A
5352239SN/A        %(fp_enable_check)s;
5362239SN/A        %(op_dest_decl)s;
5372239SN/A
5382935Sksewell@umich.edu        if (fault == NoFault) {
5392935Sksewell@umich.edu            %(postacc_code)s;
5402935Sksewell@umich.edu        }
5412935Sksewell@umich.edu
5422935Sksewell@umich.edu        if (fault == NoFault) {
5432935Sksewell@umich.edu            %(op_wb)s;
5444661Sksewell@umich.edu
5454661Sksewell@umich.edu            if (traceData) { traceData->setData(getStoreData(pkt)); }
5462935Sksewell@umich.edu        }
5472935Sksewell@umich.edu
5482935Sksewell@umich.edu        return fault;
5492935Sksewell@umich.edu    }
5502935Sksewell@umich.edu}};
5512935Sksewell@umich.edu
5522935Sksewell@umich.edudef template StoreCondCompleteAcc {{
5534661Sksewell@umich.edu    Fault %(class_name)s::completeAcc(Packet *pkt,
5542935Sksewell@umich.edu                                      %(CPU_exec_context)s *xc,
5552935Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
5562935Sksewell@umich.edu    {
5572935Sksewell@umich.edu        Fault fault = NoFault;
5582935Sksewell@umich.edu
5592935Sksewell@umich.edu        %(fp_enable_check)s;
5602935Sksewell@umich.edu        %(op_dest_decl)s;
5612935Sksewell@umich.edu
5624055Ssaidi@eecs.umich.edu        uint64_t write_result = pkt->req->getExtraData();
5632239SN/A
5642239SN/A        if (fault == NoFault) {
5652239SN/A            %(postacc_code)s;
5662239SN/A        }
5672239SN/A
5682239SN/A        if (fault == NoFault) {
5692239SN/A            %(op_wb)s;
5702239SN/A        }
5712239SN/A
5722124SN/A        return fault;
5732124SN/A    }
5742124SN/A}};
5752124SN/A
5762686Sksewell@umich.edu
5772686Sksewell@umich.edudef template MiscMemAccExecute {{
5782686Sksewell@umich.edu    Fault %(class_name)s::MemAcc::execute(%(CPU_exec_context)s *xc,
5792686Sksewell@umich.edu                                          Trace::InstRecord *traceData) const
5802686Sksewell@umich.edu    {
5812686Sksewell@umich.edu        Addr EA;
5822686Sksewell@umich.edu        Fault fault = NoFault;
5832686Sksewell@umich.edu
5842686Sksewell@umich.edu        %(fp_enable_check)s;
5852686Sksewell@umich.edu        %(op_decl)s;
5862686Sksewell@umich.edu        %(op_rd)s;
5872686Sksewell@umich.edu        EA = xc->getEA();
5882686Sksewell@umich.edu
5892686Sksewell@umich.edu        if (fault == NoFault) {
5903953Sstever@eecs.umich.edu            %(memacc_code)s;
5912686Sksewell@umich.edu        }
5922686Sksewell@umich.edu
5932686Sksewell@umich.edu        return NoFault;
5942686Sksewell@umich.edu    }
5952686Sksewell@umich.edu}};
5962686Sksewell@umich.edu
5972686Sksewell@umich.edudef template MiscExecute {{
5982686Sksewell@umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
5992686Sksewell@umich.edu                                  Trace::InstRecord *traceData) const
6002686Sksewell@umich.edu    {
6012686Sksewell@umich.edu        Addr EA;
6022686Sksewell@umich.edu        Fault fault = NoFault;
6032686Sksewell@umich.edu
6042686Sksewell@umich.edu        %(fp_enable_check)s;
6052686Sksewell@umich.edu        %(op_decl)s;
6062686Sksewell@umich.edu        %(op_rd)s;
6072686Sksewell@umich.edu        %(ea_code)s;
6082686Sksewell@umich.edu
6092686Sksewell@umich.edu        if (fault == NoFault) {
6102686Sksewell@umich.edu            %(memacc_code)s;
6112686Sksewell@umich.edu        }
6122686Sksewell@umich.edu
6132686Sksewell@umich.edu        return NoFault;
6142686Sksewell@umich.edu    }
6152686Sksewell@umich.edu}};
6162686Sksewell@umich.edu
6172686Sksewell@umich.edudef template MiscInitiateAcc {{
6182686Sksewell@umich.edu    Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s *xc,
6192686Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
6202686Sksewell@umich.edu    {
6212686Sksewell@umich.edu        panic("Misc instruction does not support split access method!");
6222686Sksewell@umich.edu        return NoFault;
6232686Sksewell@umich.edu    }
6242686Sksewell@umich.edu}};
6252686Sksewell@umich.edu
6262686Sksewell@umich.edu
6272686Sksewell@umich.edudef template MiscCompleteAcc {{
6284661Sksewell@umich.edu    Fault %(class_name)s::completeAcc(Packet *pkt,
6292686Sksewell@umich.edu                                      %(CPU_exec_context)s *xc,
6302686Sksewell@umich.edu                                      Trace::InstRecord *traceData) const
6312686Sksewell@umich.edu    {
6322686Sksewell@umich.edu        panic("Misc instruction does not support split access method!");
6332686Sksewell@umich.edu
6342686Sksewell@umich.edu        return NoFault;
6352686Sksewell@umich.edu    }
6362686Sksewell@umich.edu}};
6372686Sksewell@umich.edu
6384661Sksewell@umich.edu
6394661Sksewell@umich.edudef template MiscMemAccSize {{
6404661Sksewell@umich.edu    int %(class_name)s::memAccSize(%(CPU_exec_context)s *xc)
6414661Sksewell@umich.edu    {
6424661Sksewell@umich.edu        panic("Misc instruction does not support split access method!");
6434661Sksewell@umich.edu        return 0;
6444661Sksewell@umich.edu    }
6454661Sksewell@umich.edu}};
6464661Sksewell@umich.edu
6472124SN/Adef format LoadMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
6482124SN/A                     mem_flags = [], inst_flags = []) {{
6492124SN/A    (header_output, decoder_output, decode_block, exec_output) = \
6502124SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6512750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
6522124SN/A                      exec_template_base = 'Load')
6532124SN/A}};
6542124SN/A
6552124SN/Adef format StoreMemory(memacc_code, ea_code = {{ EA = Rs + disp; }},
6562124SN/A                     mem_flags = [], inst_flags = []) {{
6572124SN/A    (header_output, decoder_output, decode_block, exec_output) = \
6582124SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6592124SN/A                      exec_template_base = 'Store')
6602124SN/A}};
6612124SN/A
6622686Sksewell@umich.edudef format LoadIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
6632573SN/A                     mem_flags = [], inst_flags = []) {{
6642573SN/A    (header_output, decoder_output, decode_block, exec_output) = \
6652573SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6662750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
6672573SN/A                      exec_template_base = 'Load')
6682573SN/A}};
6692573SN/A
6702686Sksewell@umich.edudef format StoreIndexedMemory(memacc_code, ea_code = {{ EA = Rs + Rt; }},
6712573SN/A                     mem_flags = [], inst_flags = []) {{
6722573SN/A    (header_output, decoder_output, decode_block, exec_output) = \
6732573SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6742573SN/A                      exec_template_base = 'Store')
6752573SN/A}};
6762573SN/A
6772686Sksewell@umich.edudef format LoadUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
6782686Sksewell@umich.edu                     mem_flags = [], inst_flags = []) {{
6792686Sksewell@umich.edu    decl_code = 'uint32_t mem_word = Mem.uw;\n'
6802686Sksewell@umich.edu    decl_code += 'uint32_t unalign_addr = Rs + disp;\n'
6812686Sksewell@umich.edu    decl_code += 'uint32_t byte_offset = unalign_addr & 3;\n'
6822686Sksewell@umich.edu    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
6832686Sksewell@umich.edu    decl_code += '\tbyte_offset ^= 3;\n'
6842686Sksewell@umich.edu    decl_code += '#endif\n'
6852573SN/A
6862686Sksewell@umich.edu    memacc_code = decl_code + memacc_code
6872686Sksewell@umich.edu
6882686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
6892686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
6902750Sksewell@umich.edu                      decode_template = ImmNopCheckDecode,
6912686Sksewell@umich.edu                      exec_template_base = 'Load')
6922686Sksewell@umich.edu}};
6932686Sksewell@umich.edu
6942686Sksewell@umich.edudef format StoreUnalignedMemory(memacc_code, ea_code = {{ EA = (Rs + disp) & ~3; }},
6952686Sksewell@umich.edu                     mem_flags = [], inst_flags = []) {{
6962686Sksewell@umich.edu    decl_code = 'uint32_t mem_word = 0;\n'
6972686Sksewell@umich.edu    decl_code += 'uint32_t unaligned_addr = Rs + disp;\n'
6982686Sksewell@umich.edu    decl_code += 'uint32_t byte_offset = unaligned_addr & 3;\n'
6992686Sksewell@umich.edu    decl_code += '#if BYTE_ORDER == BIG_ENDIAN\n'
7002686Sksewell@umich.edu    decl_code += '\tbyte_offset ^= 3;\n'
7012686Sksewell@umich.edu    decl_code += '#endif\n'
7022686Sksewell@umich.edu    decl_code += 'fault = xc->read(EA, (uint32_t&)mem_word, memAccessFlags);\n'
7034661Sksewell@umich.edu    #decl_code += 'xc->readFunctional(EA,(uint32_t&)mem_word);'
7042686Sksewell@umich.edu    memacc_code = decl_code + memacc_code + '\nMem = mem_word;\n'
7052686Sksewell@umich.edu
7062686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
7072686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
7082686Sksewell@umich.edu                      exec_template_base = 'Store')
7092686Sksewell@umich.edu}};
7102686Sksewell@umich.edu
7112686Sksewell@umich.edudef format Prefetch(ea_code = {{ EA = Rs + disp; }},
7122686Sksewell@umich.edu                          mem_flags = [], pf_flags = [], inst_flags = []) {{
7132686Sksewell@umich.edu    pf_mem_flags = mem_flags + pf_flags + ['NO_FAULT']
7142686Sksewell@umich.edu    pf_inst_flags = inst_flags + ['IsMemRef', 'IsLoad',
7152686Sksewell@umich.edu                                  'IsDataPrefetch', 'MemReadOp']
7162686Sksewell@umich.edu
7172686Sksewell@umich.edu    (header_output, decoder_output, decode_block, exec_output) = \
7182686Sksewell@umich.edu        LoadStoreBase(name, Name, ea_code,
7192686Sksewell@umich.edu                      'xc->prefetch(EA, memAccessFlags);',
7202686Sksewell@umich.edu                      pf_mem_flags, pf_inst_flags, exec_template_base = 'Misc')
7212686Sksewell@umich.edu
7222686Sksewell@umich.edu}};
7232686Sksewell@umich.edu
7242686Sksewell@umich.edudef format StoreCond(memacc_code, postacc_code,
7252686Sksewell@umich.edu                     ea_code = {{ EA = Rs + disp; }},
7262495SN/A                     mem_flags = [], inst_flags = []) {{
7272495SN/A    (header_output, decoder_output, decode_block, exec_output) = \
7282495SN/A        LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
7292935Sksewell@umich.edu                      postacc_code, exec_template_base = 'StoreCond')
7302495SN/A}};
731