trap.isa revision 3995
15664Sgblack@eecs.umich.edu// Copyright (c) 2006-2007 The Regents of The University of Michigan
25664Sgblack@eecs.umich.edu// All rights reserved.
35664Sgblack@eecs.umich.edu//
45664Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
55664Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are
65664Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright
75664Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
85664Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
95664Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
105664Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution;
115664Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its
125664Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
135664Sgblack@eecs.umich.edu// this software without specific prior written permission.
145664Sgblack@eecs.umich.edu//
155664Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
165664Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
175664Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
185664Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
195664Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205664Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
215664Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
225664Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
235664Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
245664Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
255664Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265664Sgblack@eecs.umich.edu//
275664Sgblack@eecs.umich.edu// Authors: Gabe Black
285664Sgblack@eecs.umich.edu//          Steve Reinhardt
295664Sgblack@eecs.umich.edu
305664Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////
315664Sgblack@eecs.umich.edu//
325664Sgblack@eecs.umich.edu// Trap instructions
335664Sgblack@eecs.umich.edu//
345664Sgblack@eecs.umich.edu
355664Sgblack@eecs.umich.eduoutput header {{
365664Sgblack@eecs.umich.edu        /**
375664Sgblack@eecs.umich.edu         * Base class for trap instructions,
385664Sgblack@eecs.umich.edu         * or instructions that always fault.
395664Sgblack@eecs.umich.edu         */
405664Sgblack@eecs.umich.edu        class Trap : public SparcStaticInst
415664Sgblack@eecs.umich.edu        {
42          protected:
43
44            // Constructor
45            Trap(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
46                SparcStaticInst(mnem, _machInst, __opClass), trapNum(SW_TRAP)
47            {
48            }
49
50            std::string generateDisassembly(Addr pc,
51                    const SymbolTable *symtab) const;
52
53            int trapNum;
54        };
55}};
56
57output decoder {{
58        std::string Trap::generateDisassembly(Addr pc,
59                const SymbolTable *symtab) const
60        {
61            std::stringstream response;
62
63            printMnemonic(response, mnemonic);
64            ccprintf(response, " ");
65            printReg(response, _srcRegIdx[0]);
66            ccprintf(response, ", 0x%x", trapNum);
67            ccprintf(response, ", or ");
68            printReg(response, _srcRegIdx[1]);
69            return response.str();
70        }
71}};
72
73def template TrapExecute {{
74        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
75                Trace::InstRecord *traceData) const
76        {
77            Fault fault = NoFault;
78            %(op_decl)s;
79            %(op_rd)s;
80            %(code)s
81            return fault;
82        }
83}};
84
85def format Trap(code, *opt_flags) {{
86        iop = InstObjParams(name, Name, 'Trap', code, opt_flags)
87        header_output = BasicDeclare.subst(iop)
88        decoder_output = BasicConstructor.subst(iop)
89        decode_block = BasicDecode.subst(iop)
90        exec_output = TrapExecute.subst(iop)
91}};
92
93output header {{
94        class FpUnimpl : public SparcStaticInst
95        {
96          protected:
97            FpUnimpl(const char *mnem,
98                    ExtMachInst _machInst, OpClass __opClass)
99                : SparcStaticInst(mnem, _machInst, __opClass)
100            {
101            }
102
103            std::string generateDisassembly(Addr pc,
104                    const SymbolTable *symtab) const
105            {
106                return mnemonic;
107            }
108        };
109}};
110
111def format FpUnimpl(*flags) {{
112        fpunimpl_code = '''
113            Fsr = insertBits(Fsr, 16, 14, 3);
114            fault = new FpExceptionOther;
115            '''
116        iop = InstObjParams(name, Name, 'FpUnimpl', fpunimpl_code, flags)
117        header_output = BasicDeclare.subst(iop)
118        decoder_output = BasicConstructor.subst(iop)
119        decode_block = BasicDecode.subst(iop)
120        exec_output = TrapExecute.subst(iop)
121}};
122