trap.isa revision 10474
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 502022SN/A std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 512022SN/A }; 525222Sksewell@umich.edu class TrapImm : public MipsStaticInst 535222Sksewell@umich.edu { 545222Sksewell@umich.edu protected: 555222Sksewell@umich.edu 565222Sksewell@umich.edu int16_t imm; 575222Sksewell@umich.edu 585222Sksewell@umich.edu /// Constructor 595222Sksewell@umich.edu TrapImm(const char *mnem, MachInst _machInst, OpClass __opClass) : 605222Sksewell@umich.edu MipsStaticInst(mnem, _machInst, __opClass),imm(INTIMM) 615222Sksewell@umich.edu { 625222Sksewell@umich.edu } 635222Sksewell@umich.edu 645222Sksewell@umich.edu std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 655222Sksewell@umich.edu 665222Sksewell@umich.edu 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 8410196SCurtis.Dunham@arm.com Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc, Trace::InstRecord *traceData) const 852022SN/A { 862022SN/A //Write the resulting state to the execution context 872022SN/A %(op_wb)s; 882022SN/A 892686Sksewell@umich.edu //Call into the trap handler with the appropriate fault 902022SN/A return No_Fault; 912022SN/A } 922022SN/A}}; 935222Sksewell@umich.edudef format Trap(code, *flags) {{ 942022SN/A 955222Sksewell@umich.edu code ='bool cond;\n' + code 965222Sksewell@umich.edu code += 'if (cond) {\n' 9710474Sandreas.hansson@arm.com code += 'fault = std::make_shared<TrapFault>();\n};' 985222Sksewell@umich.edu 993951Sgblack@eecs.umich.edu iop = InstObjParams(name, Name, 'MipsStaticInst', code, flags) 1002022SN/A header_output = BasicDeclare.subst(iop) 1012022SN/A decoder_output = BasicConstructor.subst(iop) 1022239SN/A decode_block = BasicDecode.subst(iop) 1032239SN/A exec_output = BasicExecute.subst(iop) 1042022SN/A}}; 1055222Sksewell@umich.edudef format TrapImm(code, *flags) {{ 1065222Sksewell@umich.edu 1075222Sksewell@umich.edu code ='bool cond;\n' + code 1085222Sksewell@umich.edu code += 'if (cond) {\n' 10910474Sandreas.hansson@arm.com code += 'fault = std::make_shared<TrapFault>();\n};' 1105222Sksewell@umich.edu iop = InstObjParams(name, Name, 'MipsStaticInst', code, flags) 1115222Sksewell@umich.edu header_output = BasicDeclare.subst(iop) 1125222Sksewell@umich.edu decoder_output = BasicConstructor.subst(iop) 1135222Sksewell@umich.edu decode_block = BasicDecode.subst(iop) 1145222Sksewell@umich.edu exec_output = BasicExecute.subst(iop) 1155222Sksewell@umich.edu}}; 116