12686Sksewell@umich.edu// -*- mode:c++ -*- 22686Sksewell@umich.edu 35268Sksewell@umich.edu// Copyright (c) 2007 MIPS Technologies, Inc. 45268Sksewell@umich.edu// All rights reserved. 55268Sksewell@umich.edu// 65268Sksewell@umich.edu// Redistribution and use in source and binary forms, with or without 75268Sksewell@umich.edu// modification, are permitted provided that the following conditions are 85268Sksewell@umich.edu// met: redistributions of source code must retain the above copyright 95268Sksewell@umich.edu// notice, this list of conditions and the following disclaimer; 105268Sksewell@umich.edu// redistributions in binary form must reproduce the above copyright 115268Sksewell@umich.edu// notice, this list of conditions and the following disclaimer in the 125268Sksewell@umich.edu// documentation and/or other materials provided with the distribution; 135268Sksewell@umich.edu// neither the name of the copyright holders nor the names of its 145268Sksewell@umich.edu// contributors may be used to endorse or promote products derived from 155268Sksewell@umich.edu// this software without specific prior written permission. 165268Sksewell@umich.edu// 175268Sksewell@umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185268Sksewell@umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195268Sksewell@umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205268Sksewell@umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215268Sksewell@umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225268Sksewell@umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235268Sksewell@umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245268Sksewell@umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255268Sksewell@umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265268Sksewell@umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275268Sksewell@umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 285268Sksewell@umich.edu// 295268Sksewell@umich.edu// Authors: Korey Sewell 305268Sksewell@umich.edu// Jaidev Patwardhan 312706Sksewell@umich.edu 322022SN/A//////////////////////////////////////////////////////////////////// 332022SN/A// 342022SN/A// Trap instructions 352022SN/A// 362022SN/A 372022SN/Aoutput header {{ 382022SN/A /** 392022SN/A * Base class for integer operations. 402022SN/A */ 412028SN/A class Trap : public MipsStaticInst 422022SN/A { 432022SN/A protected: 442022SN/A 452022SN/A /// Constructor 462028SN/A Trap(const char *mnem, MachInst _machInst, OpClass __opClass) : MipsStaticInst(mnem, _machInst, __opClass) 472022SN/A { 482022SN/A } 492022SN/A 5012616Sgabeblack@google.com std::string generateDisassembly( 5112616Sgabeblack@google.com Addr pc, const SymbolTable *symtab) const override; 522022SN/A }; 535222Sksewell@umich.edu class TrapImm : public MipsStaticInst 545222Sksewell@umich.edu { 555222Sksewell@umich.edu protected: 565222Sksewell@umich.edu 575222Sksewell@umich.edu int16_t imm; 585222Sksewell@umich.edu 595222Sksewell@umich.edu /// Constructor 605222Sksewell@umich.edu TrapImm(const char *mnem, MachInst _machInst, OpClass __opClass) : 615222Sksewell@umich.edu MipsStaticInst(mnem, _machInst, __opClass),imm(INTIMM) 625222Sksewell@umich.edu { 635222Sksewell@umich.edu } 645222Sksewell@umich.edu 6512616Sgabeblack@google.com std::string generateDisassembly( 6612616Sgabeblack@google.com Addr pc, const SymbolTable *symtab) const override; 675222Sksewell@umich.edu }; 685222Sksewell@umich.edu 692022SN/A}}; 702022SN/A 712022SN/Aoutput decoder {{ 722022SN/A std::string Trap::generateDisassembly(Addr pc, const SymbolTable *symtab) const 732022SN/A { 742686Sksewell@umich.edu return "Disassembly of trap instruction\n"; 752022SN/A } 765222Sksewell@umich.edu std::string TrapImm::generateDisassembly(Addr pc, const SymbolTable *symtab) const 775222Sksewell@umich.edu { 785222Sksewell@umich.edu return "Disassembly of trap instruction\n"; 795222Sksewell@umich.edu } 802022SN/A}}; 812022SN/A 822022SN/Adef template TrapExecute {{ 832686Sksewell@umich.edu //Edit This Template When Traps Are Implemented 8412234Sgabeblack@google.com Fault %(class_name)s::execute( 8512234Sgabeblack@google.com ExecContext *xc, Trace::InstRecord *traceData) const 862022SN/A { 872022SN/A //Write the resulting state to the execution context 882022SN/A %(op_wb)s; 892022SN/A 902686Sksewell@umich.edu //Call into the trap handler with the appropriate fault 912022SN/A return No_Fault; 922022SN/A } 932022SN/A}}; 945222Sksewell@umich.edudef format Trap(code, *flags) {{ 952022SN/A 965222Sksewell@umich.edu code ='bool cond;\n' + code 975222Sksewell@umich.edu code += 'if (cond) {\n' 9810474Sandreas.hansson@arm.com code += 'fault = std::make_shared<TrapFault>();\n};' 995222Sksewell@umich.edu 1003951Sgblack@eecs.umich.edu iop = InstObjParams(name, Name, 'MipsStaticInst', code, flags) 1012022SN/A header_output = BasicDeclare.subst(iop) 1022022SN/A decoder_output = BasicConstructor.subst(iop) 1032239SN/A decode_block = BasicDecode.subst(iop) 1042239SN/A exec_output = BasicExecute.subst(iop) 1052022SN/A}}; 1065222Sksewell@umich.edudef format TrapImm(code, *flags) {{ 1075222Sksewell@umich.edu 1085222Sksewell@umich.edu code ='bool cond;\n' + code 1095222Sksewell@umich.edu code += 'if (cond) {\n' 11010474Sandreas.hansson@arm.com code += 'fault = std::make_shared<TrapFault>();\n};' 1115222Sksewell@umich.edu iop = InstObjParams(name, Name, 'MipsStaticInst', code, flags) 1125222Sksewell@umich.edu header_output = BasicDeclare.subst(iop) 1135222Sksewell@umich.edu decoder_output = BasicConstructor.subst(iop) 1145222Sksewell@umich.edu decode_block = BasicDecode.subst(iop) 1155222Sksewell@umich.edu exec_output = BasicExecute.subst(iop) 1165222Sksewell@umich.edu}}; 117