dsp.isa revision 4661
14661Sksewell@umich.edu// -*- mode:c++ -*-
24661Sksewell@umich.edu
34661Sksewell@umich.edu// Copyright (c) 2006 The Regents of The University of Michigan
44661Sksewell@umich.edu// All rights reserved.
54661Sksewell@umich.edu//
64661Sksewell@umich.edu// Redistribution and use in source and binary forms, with or without
74661Sksewell@umich.edu// modification, are permitted provided that the following conditions are
84661Sksewell@umich.edu// met: redistributions of source code must retain the above copyright
94661Sksewell@umich.edu// notice, this list of conditions and the following disclaimer;
104661Sksewell@umich.edu// redistributions in binary form must reproduce the above copyright
114661Sksewell@umich.edu// notice, this list of conditions and the following disclaimer in the
124661Sksewell@umich.edu// documentation and/or other materials provided with the distribution;
134661Sksewell@umich.edu// neither the name of the copyright holders nor the names of its
144661Sksewell@umich.edu// contributors may be used to endorse or promote products derived from
154661Sksewell@umich.edu// this software without specific prior written permission.
164661Sksewell@umich.edu//
174661Sksewell@umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184661Sksewell@umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194661Sksewell@umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204661Sksewell@umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214661Sksewell@umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224661Sksewell@umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234661Sksewell@umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244661Sksewell@umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254661Sksewell@umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264661Sksewell@umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274661Sksewell@umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284661Sksewell@umich.edu//
294661Sksewell@umich.edu// Authors: Korey Sewell
304661Sksewell@umich.edu
314661Sksewell@umich.edu////////////////////////////////////////////////////////////////////
324661Sksewell@umich.edu//
334661Sksewell@umich.edu// DSP integer operate instructions
344661Sksewell@umich.edu//
354661Sksewell@umich.eduoutput header {{
364661Sksewell@umich.edu#include <iostream>
374661Sksewell@umich.edu    using namespace std;
384661Sksewell@umich.edu    /**
394661Sksewell@umich.edu     * Base class for integer operations.
404661Sksewell@umich.edu     */
414661Sksewell@umich.edu    class DspIntOp : public MipsStaticInst
424661Sksewell@umich.edu    {
434661Sksewell@umich.edu      protected:
444661Sksewell@umich.edu
454661Sksewell@umich.edu        /// Constructor
464661Sksewell@umich.edu        DspIntOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
474661Sksewell@umich.edu            MipsStaticInst(mnem, _machInst, __opClass)
484661Sksewell@umich.edu        {
494661Sksewell@umich.edu        }
504661Sksewell@umich.edu    };
514661Sksewell@umich.edu
524661Sksewell@umich.edu    class DspHiLoOp : public MipsStaticInst
534661Sksewell@umich.edu    {
544661Sksewell@umich.edu      protected:
554661Sksewell@umich.edu
564661Sksewell@umich.edu        /// Constructor
574661Sksewell@umich.edu        DspHiLoOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
584661Sksewell@umich.edu            MipsStaticInst(mnem, _machInst, __opClass)
594661Sksewell@umich.edu        {
604661Sksewell@umich.edu        }
614661Sksewell@umich.edu    };
624661Sksewell@umich.edu}};
634661Sksewell@umich.edu
644661Sksewell@umich.edu// Dsp instruction class execute method template.
654661Sksewell@umich.edudef template DspExecute {{
664661Sksewell@umich.edu        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
674661Sksewell@umich.edu        {
684661Sksewell@umich.edu                Fault fault = NoFault;
694661Sksewell@umich.edu
704661Sksewell@umich.edu                %(op_decl)s;
714661Sksewell@umich.edu
724661Sksewell@umich.edu                if (isDspPresent(xc))
734661Sksewell@umich.edu                {
744661Sksewell@umich.edu                    if (isDspEnabled(xc))
754661Sksewell@umich.edu                    {
764661Sksewell@umich.edu                        %(op_rd)s;
774661Sksewell@umich.edu                        %(code)s;
784661Sksewell@umich.edu                    }
794661Sksewell@umich.edu                    else
804661Sksewell@umich.edu                    {
814661Sksewell@umich.edu                        fault = new DspStateDisabledFault();
824661Sksewell@umich.edu                    }
834661Sksewell@umich.edu                }
844661Sksewell@umich.edu                else
854661Sksewell@umich.edu                {
864661Sksewell@umich.edu                    fault = new ReservedInstructionFault();
874661Sksewell@umich.edu                }
884661Sksewell@umich.edu
894661Sksewell@umich.edu                if(fault == NoFault)
904661Sksewell@umich.edu                {
914661Sksewell@umich.edu                    %(op_wb)s;
924661Sksewell@umich.edu                }
934661Sksewell@umich.edu                return fault;
944661Sksewell@umich.edu        }
954661Sksewell@umich.edu}};
964661Sksewell@umich.edu
974661Sksewell@umich.edu// DspHiLo instruction class execute method template.
984661Sksewell@umich.edudef template DspHiLoExecute {{
994661Sksewell@umich.edu        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
1004661Sksewell@umich.edu        {
1014661Sksewell@umich.edu                Fault fault = NoFault;
1024661Sksewell@umich.edu
1034661Sksewell@umich.edu                %(op_decl)s;
1044661Sksewell@umich.edu
1054661Sksewell@umich.edu                if (isDspPresent(xc))
1064661Sksewell@umich.edu                {
1074661Sksewell@umich.edu                    if (isDspEnabled(xc))
1084661Sksewell@umich.edu                    {
1094661Sksewell@umich.edu                        %(op_rd)s;
1104661Sksewell@umich.edu                        %(code)s;
1114661Sksewell@umich.edu                    }
1124661Sksewell@umich.edu                    else
1134661Sksewell@umich.edu                    {
1144661Sksewell@umich.edu                        fault = new DspStateDisabledFault();
1154661Sksewell@umich.edu                    }
1164661Sksewell@umich.edu                }
1174661Sksewell@umich.edu                else
1184661Sksewell@umich.edu                {
1194661Sksewell@umich.edu                    fault = new ReservedInstructionFault();
1204661Sksewell@umich.edu                }
1214661Sksewell@umich.edu
1224661Sksewell@umich.edu                if(fault == NoFault)
1234661Sksewell@umich.edu                {
1244661Sksewell@umich.edu                    %(op_wb)s;
1254661Sksewell@umich.edu                    //If there are 2 Destination Registers then
1264661Sksewell@umich.edu                    //concatenate the values for the traceData
1274661Sksewell@umich.edu                    if(traceData && _numDestRegs == 2) {
1284661Sksewell@umich.edu                        // FIXME - set the trace value correctly here
1294661Sksewell@umich.edu                        //uint64_t hilo_final_val = (uint64_t)HI_RD_SEL << 32 | LO_RD_SEL;
1304661Sksewell@umich.edu                        //traceData->setData(hilo_final_val);
1314661Sksewell@umich.edu                    }
1324661Sksewell@umich.edu                }
1334661Sksewell@umich.edu                return fault;
1344661Sksewell@umich.edu        }
1354661Sksewell@umich.edu}};
1364661Sksewell@umich.edu
1374661Sksewell@umich.edu//Outputs to decoder.cc
1384661Sksewell@umich.eduoutput decoder {{
1394661Sksewell@umich.edu}};
1404661Sksewell@umich.edu
1414661Sksewell@umich.eduoutput exec {{
1424661Sksewell@umich.edu    bool isDspEnabled(%(CPU_exec_context)s *xc)
1434661Sksewell@umich.edu    {
1444661Sksewell@umich.edu#if FULL_SYSTEM
1454661Sksewell@umich.edu        if( bits( xc->readMiscReg(MipsISA::Status), 24, 24 ) == 0 )
1464661Sksewell@umich.edu            return false;
1474661Sksewell@umich.edu#else
1484661Sksewell@umich.edu        //printf("Syscall Emulation Mode: isDspEnabled() check defaults to TRUE\n");
1494661Sksewell@umich.edu#endif
1504661Sksewell@umich.edu        return true;
1514661Sksewell@umich.edu    }
1524661Sksewell@umich.edu}};
1534661Sksewell@umich.edu
1544661Sksewell@umich.eduoutput exec {{
1554661Sksewell@umich.edu    bool isDspPresent(%(CPU_exec_context)s *xc)
1564661Sksewell@umich.edu    {
1574661Sksewell@umich.edu#if FULL_SYSTEM
1584661Sksewell@umich.edu        if( bits( xc->readMiscReg(MipsISA::Config3), 10, 10 ) == 0 )
1594661Sksewell@umich.edu            return false;
1604661Sksewell@umich.edu#else
1614661Sksewell@umich.edu        //printf("Syscall Emulation Mode: isDspPresent() check defaults to TRUE\n");
1624661Sksewell@umich.edu#endif
1634661Sksewell@umich.edu        return true;
1644661Sksewell@umich.edu    }
1654661Sksewell@umich.edu}};
1664661Sksewell@umich.edu
1674661Sksewell@umich.edu// add code to fetch the DSPControl register
1684661Sksewell@umich.edu// and write it back after execution, giving
1694661Sksewell@umich.edu// the instruction the opportunity to modify
1704661Sksewell@umich.edu// it if necessary
1714661Sksewell@umich.edudef format DspIntOp(code, *opt_flags) {{
1724661Sksewell@umich.edu
1734661Sksewell@umich.edu    decl_code = 'uint32_t dspctl;\n'
1744661Sksewell@umich.edu    decl_code += 'dspctl = DSPControl;\n'
1754661Sksewell@umich.edu
1764661Sksewell@umich.edu    write_code = 'DSPControl = dspctl;\n'
1774661Sksewell@umich.edu
1784661Sksewell@umich.edu    code = decl_code + code + write_code
1794661Sksewell@umich.edu
1804661Sksewell@umich.edu    iop = InstObjParams(name, Name, 'DspIntOp', code, opt_flags)
1814661Sksewell@umich.edu    header_output = BasicDeclare.subst(iop)
1824661Sksewell@umich.edu    decoder_output = BasicConstructor.subst(iop)
1834661Sksewell@umich.edu    decode_block = BasicDecode.subst(iop)
1844661Sksewell@umich.edu    exec_output = DspExecute.subst(iop)
1854661Sksewell@umich.edu}};
1864661Sksewell@umich.edu
1874661Sksewell@umich.edu// add code to fetch the DSPControl register
1884661Sksewell@umich.edu// and write it back after execution, giving
1894661Sksewell@umich.edu// the instruction the opportunity to modify
1904661Sksewell@umich.edu// it if necessary; also, fetch the appropriate
1914661Sksewell@umich.edu// HI/LO register pair, based on the AC
1924661Sksewell@umich.edu// instruction field.
1934661Sksewell@umich.edu
1944661Sksewell@umich.edudef format DspHiLoOp(code, *opt_flags) {{
1954661Sksewell@umich.edu
1964661Sksewell@umich.edu    decl_code = 'int64_t dspac;\n'
1974661Sksewell@umich.edu    decl_code += 'uint32_t dspctl;\n'
1984661Sksewell@umich.edu
1994661Sksewell@umich.edu    fetch_code = 'dspctl = DSPControl;\n'
2004661Sksewell@umich.edu    fetch_code += 'dspac = HI_RD_SEL;\n'
2014661Sksewell@umich.edu    fetch_code += 'dspac = dspac << 32 | LO_RD_SEL;\n'
2024661Sksewell@umich.edu
2034661Sksewell@umich.edu    write_code = 'DSPControl = dspctl;\n'
2044661Sksewell@umich.edu    write_code += 'HI_RD_SEL = dspac<63:32>;\n'
2054661Sksewell@umich.edu    write_code += 'LO_RD_SEL = dspac<31:0>;\n'
2064661Sksewell@umich.edu
2074661Sksewell@umich.edu    code = decl_code + fetch_code + code + write_code
2084661Sksewell@umich.edu
2094661Sksewell@umich.edu    iop = InstObjParams(name, Name, 'DspHiLoOp', code, opt_flags)
2104661Sksewell@umich.edu    header_output = BasicDeclare.subst(iop)
2114661Sksewell@umich.edu    decoder_output = BasicConstructor.subst(iop)
2124661Sksewell@umich.edu    decode_block = BasicDecode.subst(iop)
2134661Sksewell@umich.edu    exec_output = DspHiLoExecute.subst(iop)
2144661Sksewell@umich.edu
2154661Sksewell@umich.edu}};
2164661Sksewell@umich.edu
2174661Sksewell@umich.edu
2184661Sksewell@umich.edu
219