basicmem.isa revision 3391
13388Sgblack@eecs.umich.edu// Copyright (c) 2006 The Regents of The University of Michigan
23388Sgblack@eecs.umich.edu// All rights reserved.
33388Sgblack@eecs.umich.edu//
43388Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
53388Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are
63388Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright
73388Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
83388Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
93388Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
103388Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution;
113388Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its
123388Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
133388Sgblack@eecs.umich.edu// this software without specific prior written permission.
143388Sgblack@eecs.umich.edu//
153388Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
163388Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
173388Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
183388Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
193388Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
203388Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
213388Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223388Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
233388Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
243388Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
253388Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
263388Sgblack@eecs.umich.edu//
273388Sgblack@eecs.umich.edu// Authors: Ali Saidi
283388Sgblack@eecs.umich.edu//          Gabe Black
293388Sgblack@eecs.umich.edu
302022SN/A////////////////////////////////////////////////////////////////////
312022SN/A//
322022SN/A// Mem instructions
332022SN/A//
342022SN/A
352022SN/Aoutput header {{
362022SN/A        /**
372516SN/A         * Base class for memory operations.
382022SN/A         */
392022SN/A        class Mem : public SparcStaticInst
402022SN/A        {
412224SN/A          protected:
422022SN/A
432224SN/A            // Constructor
442469SN/A            Mem(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
452224SN/A                SparcStaticInst(mnem, _machInst, __opClass)
462224SN/A            {
472224SN/A            }
482022SN/A
492224SN/A            std::string generateDisassembly(Addr pc,
502224SN/A                    const SymbolTable *symtab) const;
512022SN/A        };
522516SN/A
532516SN/A        /**
542516SN/A         * Class for memory operations which use an immediate offset.
552516SN/A         */
562516SN/A        class MemImm : public Mem
572516SN/A        {
582516SN/A          protected:
592516SN/A
602516SN/A            // Constructor
612516SN/A            MemImm(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
623388Sgblack@eecs.umich.edu                Mem(mnem, _machInst, __opClass), imm(sext<13>(SIMM13))
633388Sgblack@eecs.umich.edu            {}
642516SN/A
652516SN/A            std::string generateDisassembly(Addr pc,
662516SN/A                    const SymbolTable *symtab) const;
672516SN/A
683388Sgblack@eecs.umich.edu            const int32_t imm;
692516SN/A        };
702022SN/A}};
712022SN/A
722022SN/Aoutput decoder {{
732516SN/A        std::string Mem::generateDisassembly(Addr pc,
742516SN/A                const SymbolTable *symtab) const
752022SN/A        {
762516SN/A            std::stringstream response;
772526SN/A            bool load = flags[IsLoad];
782561SN/A            bool save = flags[IsStore];
792516SN/A
802516SN/A            printMnemonic(response, mnemonic);
812561SN/A            if(save)
822516SN/A            {
832516SN/A                printReg(response, _srcRegIdx[0]);
842516SN/A                ccprintf(response, ", ");
852516SN/A            }
862516SN/A            ccprintf(response, "[ ");
872561SN/A            printReg(response, _srcRegIdx[!save ? 0 : 1]);
882516SN/A            ccprintf(response, " + ");
892561SN/A            printReg(response, _srcRegIdx[!save ? 1 : 2]);
902516SN/A            ccprintf(response, " ]");
912516SN/A            if(load)
922516SN/A            {
932516SN/A                ccprintf(response, ", ");
942516SN/A                printReg(response, _destRegIdx[0]);
952516SN/A            }
962516SN/A
972516SN/A            return response.str();
982516SN/A        }
992516SN/A
1002516SN/A        std::string MemImm::generateDisassembly(Addr pc,
1012516SN/A                const SymbolTable *symtab) const
1022516SN/A        {
1032516SN/A            std::stringstream response;
1042526SN/A            bool load = flags[IsLoad];
1052561SN/A            bool save = flags[IsStore];
1062516SN/A
1072516SN/A            printMnemonic(response, mnemonic);
1082561SN/A            if(save)
1092516SN/A            {
1102516SN/A                printReg(response, _srcRegIdx[0]);
1112516SN/A                ccprintf(response, ", ");
1122516SN/A            }
1132516SN/A            ccprintf(response, "[ ");
1142561SN/A            printReg(response, _srcRegIdx[!save ? 0 : 1]);
1152591SN/A            if(imm >= 0)
1162591SN/A                ccprintf(response, " + 0x%x ]", imm);
1172591SN/A            else
1182591SN/A                ccprintf(response, " + -0x%x ]", -imm);
1192516SN/A            if(load)
1202516SN/A            {
1212516SN/A                ccprintf(response, ", ");
1222516SN/A                printReg(response, _destRegIdx[0]);
1232516SN/A            }
1242516SN/A
1252516SN/A            return response.str();
1262022SN/A        }
1272022SN/A}};
1282022SN/A
1293385SN/Adef template MemDeclare {{
1303385SN/A        /**
1313385SN/A         * Static instruction class for "%(mnemonic)s".
1323385SN/A         */
1333385SN/A        class %(class_name)s : public %(base_class)s
1343385SN/A        {
1353385SN/A          public:
1363385SN/A
1373385SN/A            /// Constructor.
1383385SN/A            %(class_name)s(ExtMachInst machInst);
1393385SN/A
1403385SN/A            %(BasicExecDeclare)s
1413385SN/A
1423385SN/A            %(InitiateAccDeclare)s
1433385SN/A
1443385SN/A            %(CompleteAccDeclare)s
1453385SN/A        };
1463385SN/A}};
1473385SN/A
1482526SN/Alet {{
1493391Sgblack@eecs.umich.edu    def doMemFormat(code, execute, faultCode, name, Name, opt_flags):
1502516SN/A        addrCalcReg = 'EA = Rs1 + Rs2;'
1512591SN/A        addrCalcImm = 'EA = Rs1 + imm;'
1522526SN/A        iop = InstObjParams(name, Name, 'Mem', code,
1533391Sgblack@eecs.umich.edu                opt_flags, {"fault_check": faultCode, "ea_code": addrCalcReg})
1543388Sgblack@eecs.umich.edu        iop_imm = InstObjParams(name, Name + "Imm", 'MemImm', code,
1553391Sgblack@eecs.umich.edu                opt_flags, {"fault_check": faultCode, "ea_code": addrCalcImm})
1563385SN/A        header_output = MemDeclare.subst(iop) + MemDeclare.subst(iop_imm)
1572516SN/A        decoder_output = BasicConstructor.subst(iop) + BasicConstructor.subst(iop_imm)
1582516SN/A        decode_block = ROrImmDecode.subst(iop)
1593388Sgblack@eecs.umich.edu        exec_output = doSplitExecute(code, addrCalcReg, addrCalcImm, execute,
1603391Sgblack@eecs.umich.edu                faultCode, name, name + "Imm", Name, Name + "Imm", opt_flags)
1612526SN/A        return (header_output, decoder_output, exec_output, decode_block)
1622022SN/A}};
1632526SN/A
1643272SN/Adef format LoadAlt(code, *opt_flags) {{
1653272SN/A        (header_output,
1663272SN/A         decoder_output,
1673272SN/A         exec_output,
1683272SN/A         decode_block) = doMemFormat(code, LoadExecute,
1693391Sgblack@eecs.umich.edu            AlternateAsiPrivFaultCheck, name, Name, opt_flags)
1703272SN/A}};
1713272SN/A
1723272SN/Adef format StoreAlt(code, *opt_flags) {{
1733272SN/A        (header_output,
1743272SN/A         decoder_output,
1753272SN/A         exec_output,
1763272SN/A         decode_block) = doMemFormat(code, StoreExecute,
1773391Sgblack@eecs.umich.edu            AlternateAsiPrivFaultCheck, name, Name, opt_flags)
1783272SN/A}};
1793272SN/A
1803272SN/Adef format Load(code, *opt_flags) {{
1812526SN/A        (header_output,
1822526SN/A         decoder_output,
1832526SN/A         exec_output,
1842526SN/A         decode_block) = doMemFormat(code,
1853272SN/A             LoadExecute, '', name, Name, opt_flags)
1862526SN/A}};
1872526SN/A
1883272SN/Adef format Store(code, *opt_flags) {{
1892526SN/A        (header_output,
1902526SN/A         decoder_output,
1912526SN/A         exec_output,
1922526SN/A         decode_block) = doMemFormat(code,
1933272SN/A             StoreExecute, '', name, Name, opt_flags)
1942526SN/A}};
195