13931Ssaidi@eecs.umich.edu// Copyright (c) 2006-2007 The Regents of The University of Michigan
22632Sstever@eecs.umich.edu// All rights reserved.
32632Sstever@eecs.umich.edu//
42632Sstever@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
52632Sstever@eecs.umich.edu// modification, are permitted provided that the following conditions are
62632Sstever@eecs.umich.edu// met: redistributions of source code must retain the above copyright
72632Sstever@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
82632Sstever@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
92632Sstever@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
102632Sstever@eecs.umich.edu// documentation and/or other materials provided with the distribution;
112632Sstever@eecs.umich.edu// neither the name of the copyright holders nor the names of its
122632Sstever@eecs.umich.edu// contributors may be used to endorse or promote products derived from
132632Sstever@eecs.umich.edu// this software without specific prior written permission.
142632Sstever@eecs.umich.edu//
152632Sstever@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162632Sstever@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172632Sstever@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182632Sstever@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192632Sstever@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202632Sstever@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212632Sstever@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222632Sstever@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232632Sstever@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242632Sstever@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252632Sstever@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262632Sstever@eecs.umich.edu//
272632Sstever@eecs.umich.edu// Authors: Ali Saidi
282632Sstever@eecs.umich.edu//          Gabe Black
292632Sstever@eecs.umich.edu//          Steve Reinhardt
302022SN/A
312022SN/A// Basic instruction class declaration template.
322022SN/Adef template BasicDeclare {{
3312275Sgabeblack@google.com/**
3412275Sgabeblack@google.com * Static instruction class for "%(mnemonic)s".
3512275Sgabeblack@google.com */
3612275Sgabeblack@google.comclass %(class_name)s : public %(base_class)s
3712275Sgabeblack@google.com{
3812275Sgabeblack@google.com  public:
3912275Sgabeblack@google.com    // Constructor.
4012275Sgabeblack@google.com    %(class_name)s(ExtMachInst machInst);
4112616Sgabeblack@google.com    Fault execute(ExecContext *, Trace::InstRecord *) const override;
4212275Sgabeblack@google.com};
432022SN/A}};
442022SN/A
455091Sgblack@eecs.umich.edu// Basic instruction class declaration template.
468621Sgblack@eecs.umich.edudef template FpBasicDeclare {{
4712275Sgabeblack@google.com/**
4812275Sgabeblack@google.com * Static instruction class for "%(mnemonic)s".
4912275Sgabeblack@google.com */
5012275Sgabeblack@google.comclass %(class_name)s : public %(base_class)s
5112275Sgabeblack@google.com{
5212275Sgabeblack@google.com  public:
5312275Sgabeblack@google.com    // Constructor.
5412275Sgabeblack@google.com    %(class_name)s(ExtMachInst machInst);
5512616Sgabeblack@google.com    Fault execute(ExecContext *, Trace::InstRecord *) const override;
5612275Sgabeblack@google.com    Fault doFpOp(ExecContext *, Trace::InstRecord *) const M5_NO_INLINE;
5712275Sgabeblack@google.com};
588621Sgblack@eecs.umich.edu}};
598621Sgblack@eecs.umich.edu
608621Sgblack@eecs.umich.edu// Basic instruction class declaration template.
615091Sgblack@eecs.umich.edudef template BasicDeclareWithMnemonic {{
6212275Sgabeblack@google.com/**
6312275Sgabeblack@google.com * Static instruction class for "%(mnemonic)s".
6412275Sgabeblack@google.com */
6512275Sgabeblack@google.comclass %(class_name)s : public %(base_class)s
6612275Sgabeblack@google.com{
6712275Sgabeblack@google.com  public:
6812275Sgabeblack@google.com    // Constructor.
6912275Sgabeblack@google.com    %(class_name)s(const char *mnemonic, ExtMachInst machInst);
7012616Sgabeblack@google.com    Fault execute(ExecContext *, Trace::InstRecord *) const override;
7112275Sgabeblack@google.com};
725091Sgblack@eecs.umich.edu}};
735091Sgblack@eecs.umich.edu
742022SN/A// Basic instruction class constructor template.
752022SN/Adef template BasicConstructor {{
7612275Sgabeblack@google.com%(class_name)s::%(class_name)s(ExtMachInst machInst) :
7712275Sgabeblack@google.com        %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
7812275Sgabeblack@google.com{
7912275Sgabeblack@google.com    %(constructor)s;
8012275Sgabeblack@google.com}
812022SN/A}};
822022SN/A
835091Sgblack@eecs.umich.edu// Basic instruction class constructor template.
845091Sgblack@eecs.umich.edudef template BasicConstructorWithMnemonic {{
8512275Sgabeblack@google.com%(class_name)s::%(class_name)s(const char *mnemonic, ExtMachInst machInst) :
8612275Sgabeblack@google.com        %(base_class)s(mnemonic, machInst, %(op_class)s)
8712275Sgabeblack@google.com{
8812275Sgabeblack@google.com    %(constructor)s;
8912275Sgabeblack@google.com}
905091Sgblack@eecs.umich.edu}};
915091Sgblack@eecs.umich.edu
922022SN/A// Basic instruction class execute method template.
932022SN/Adef template BasicExecute {{
9412275Sgabeblack@google.comFault
9512275Sgabeblack@google.com%(class_name)s::execute(ExecContext *xc,
9612275Sgabeblack@google.com        Trace::InstRecord *traceData) const
9712275Sgabeblack@google.com{
9812275Sgabeblack@google.com    Fault fault = NoFault;
992022SN/A
10012275Sgabeblack@google.com    %(fp_enable_check)s;
10112275Sgabeblack@google.com    %(op_decl)s;
10212275Sgabeblack@google.com    %(op_rd)s;
10312275Sgabeblack@google.com    %(code)s;
1042022SN/A
10512275Sgabeblack@google.com    if (fault == NoFault) {
10612275Sgabeblack@google.com        %(op_wb)s;
10712275Sgabeblack@google.com    }
10812275Sgabeblack@google.com    return fault;
10912275Sgabeblack@google.com}
1102022SN/A}};
1112022SN/A
1128621Sgblack@eecs.umich.edudef template DoFpOpExecute {{
11312275Sgabeblack@google.comFault
11412275Sgabeblack@google.com%(class_name)s::doFpOp(ExecContext *xc, Trace::InstRecord *traceData) const
11512275Sgabeblack@google.com{
11612275Sgabeblack@google.com    Fault fault = NoFault;
11712275Sgabeblack@google.com    %(op_decl)s;
11812275Sgabeblack@google.com    %(op_rd)s;
11912275Sgabeblack@google.com    %(fp_code)s;
12012275Sgabeblack@google.com    if (fault == NoFault) {
12112275Sgabeblack@google.com        %(op_wb)s;
12212275Sgabeblack@google.com    }
12312275Sgabeblack@google.com    return fault;
12412275Sgabeblack@google.com}
1258621Sgblack@eecs.umich.edu}};
1268621Sgblack@eecs.umich.edu
1272022SN/A// Basic decode template.
1282022SN/Adef template BasicDecode {{
12912275Sgabeblack@google.comreturn new %(class_name)s(machInst);
1302022SN/A}};
1312022SN/A
1323272Sgblack@eecs.umich.edu// Basic decode template, passing mnemonic in as string arg to constructor.
1333272Sgblack@eecs.umich.edudef template BasicDecodeWithMnemonic {{
13412275Sgabeblack@google.comreturn new %(class_name)s("%(mnemonic)s", machInst);
1353272Sgblack@eecs.umich.edu}};
1363272Sgblack@eecs.umich.edu
1372022SN/A// The most basic instruction format... used only for a few misc. insts
1382022SN/Adef format BasicOperate(code, *flags) {{
13912275Sgabeblack@google.com    code = filterDoubles(code)
14012275Sgabeblack@google.com    iop = InstObjParams(name, Name, 'SparcStaticInst', code, flags)
14112275Sgabeblack@google.com    header_output = BasicDeclare.subst(iop)
14212275Sgabeblack@google.com    decoder_output = BasicConstructor.subst(iop)
14312275Sgabeblack@google.com    decode_block = BasicDecode.subst(iop)
14412275Sgabeblack@google.com    exec_output = BasicExecute.subst(iop)
14512275Sgabeblack@google.com
1462022SN/A}};
1474008Ssaidi@eecs.umich.edu
1484008Ssaidi@eecs.umich.edudef format FpBasic(code, *flags) {{
1498621Sgblack@eecs.umich.edu    exec_code = """
1508624Sgblack@eecs.umich.edu    Fsr |= bits(Fsr, 4, 0) << 5;
1518621Sgblack@eecs.umich.edu    Fsr = insertBits(Fsr, 4, 0, 0);
1524394Ssaidi@eecs.umich.edu    int newrnd = M5_FE_TONEAREST;
1534008Ssaidi@eecs.umich.edu    switch (Fsr<31:30>) {
1544394Ssaidi@eecs.umich.edu      case 0: newrnd = M5_FE_TONEAREST; break;
1554394Ssaidi@eecs.umich.edu      case 1: newrnd = M5_FE_TOWARDZERO; break;
1564394Ssaidi@eecs.umich.edu      case 2: newrnd = M5_FE_UPWARD; break;
1574394Ssaidi@eecs.umich.edu      case 3: newrnd = M5_FE_DOWNWARD; break;
1584008Ssaidi@eecs.umich.edu    }
1594394Ssaidi@eecs.umich.edu    int oldrnd = m5_fegetround();
1604394Ssaidi@eecs.umich.edu    m5_fesetround(newrnd);
1618621Sgblack@eecs.umich.edu    __asm__ __volatile__("" ::: "memory");
1628621Sgblack@eecs.umich.edu    fault = doFpOp(xc, traceData);
1638621Sgblack@eecs.umich.edu    __asm__ __volatile__("" ::: "memory");
1648621Sgblack@eecs.umich.edu    m5_fesetround(oldrnd);
1658621Sgblack@eecs.umich.edu    return fault;
1664008Ssaidi@eecs.umich.edu"""
1678621Sgblack@eecs.umich.edu    fp_code = filterDoubles(code)
1688621Sgblack@eecs.umich.edu    iop = InstObjParams(name, Name, 'SparcStaticInst',
16912275Sgabeblack@google.com                        { "code" : exec_code, "fp_code" : fp_code }, flags)
1708621Sgblack@eecs.umich.edu    header_output = FpBasicDeclare.subst(iop)
1718621Sgblack@eecs.umich.edu    decoder_output = BasicConstructor.subst(iop)
1728621Sgblack@eecs.umich.edu    decode_block = BasicDecode.subst(iop)
1738621Sgblack@eecs.umich.edu    exec_output = BasicExecute.subst(iop)
1748621Sgblack@eecs.umich.edu    exec_output += DoFpOpExecute.subst(iop)
1754008Ssaidi@eecs.umich.edu}};
176