debug.isa revision 7087:fb8d5786ff30
1// Copyright (c) 2008 The Hewlett-Packard Development Company 2// All rights reserved. 3// 4// The license below extends only to copyright in the software and shall 5// not be construed as granting a license to any other intellectual 6// property including but not limited to intellectual property relating 7// to a hardware implementation of the functionality of the software 8// licensed hereunder. You may use the software subject to the license 9// terms below provided that you ensure that this notice is replicated 10// unmodified and in its entirety in all distributions of the software, 11// modified or unmodified, in source code or in binary form. 12// 13// Redistribution and use in source and binary forms, with or without 14// modification, are permitted provided that the following conditions are 15// met: redistributions of source code must retain the above copyright 16// notice, this list of conditions and the following disclaimer; 17// redistributions in binary form must reproduce the above copyright 18// notice, this list of conditions and the following disclaimer in the 19// documentation and/or other materials provided with the distribution; 20// neither the name of the copyright holders nor the names of its 21// contributors may be used to endorse or promote products derived from 22// this software without specific prior written permission. 23// 24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35// 36// Authors: Gabe Black 37 38////////////////////////////////////////////////////////////////////////// 39// 40// Debug Microops 41// 42////////////////////////////////////////////////////////////////////////// 43 44output header {{ 45 class MicroDebugBase : public X86ISA::X86MicroopBase 46 { 47 protected: 48 std::string message; 49 uint8_t cc; 50 51 public: 52 MicroDebugBase(ExtMachInst _machInst, const char * mnem, 53 const char * instMnem, 54 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 55 std::string _message, uint8_t _cc); 56 57 MicroDebugBase(ExtMachInst _machInst, const char * mnem, 58 const char * instMnem, std::string _message, uint8_t _cc); 59 60 std::string generateDisassembly(Addr pc, 61 const SymbolTable *symtab) const; 62 }; 63}}; 64 65def template MicroDebugDeclare {{ 66 class %(class_name)s : public %(base_class)s 67 { 68 private: 69 void buildMe(); 70 public: 71 %(class_name)s(ExtMachInst _machInst, const char * instMnem, 72 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 73 std::string _message, uint8_t _cc); 74 75 %(class_name)s(ExtMachInst _machInst, const char * instMnem, 76 std::string _message, uint8_t _cc); 77 78 %(BasicExecDeclare)s 79 }; 80}}; 81 82def template MicroDebugExecute {{ 83 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 84 Trace::InstRecord *traceData) const 85 { 86 %(op_decl)s 87 %(op_rd)s 88 if (%(cond_test)s) { 89 %(func)s("%s\n", message); 90 } 91 return NoFault; 92 } 93}}; 94 95output decoder {{ 96 inline MicroDebugBase::MicroDebugBase( 97 ExtMachInst machInst, const char * mnem, const char * instMnem, 98 std::string _message, uint8_t _cc) : 99 X86MicroopBase(machInst, mnem, instMnem, 100 false, false, false, false, No_OpClass), 101 message(_message), cc(_cc) 102 { 103 } 104 105 inline MicroDebugBase::MicroDebugBase( 106 ExtMachInst machInst, const char * mnem, const char * instMnem, 107 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 108 std::string _message, uint8_t _cc) : 109 X86MicroopBase(machInst, mnem, instMnem, 110 isMicro, isDelayed, isFirst, isLast, No_OpClass), 111 message(_message), cc(_cc) 112 { 113 } 114}}; 115 116def template MicroDebugConstructor {{ 117 118 inline void %(class_name)s::buildMe() 119 { 120 %(constructor)s; 121 } 122 123 inline %(class_name)s::%(class_name)s( 124 ExtMachInst machInst, const char * instMnem, 125 std::string _message, uint8_t _cc) : 126 %(base_class)s(machInst, "%(func)s", instMnem, _message, _cc) 127 { 128 buildMe(); 129 } 130 131 inline %(class_name)s::%(class_name)s( 132 ExtMachInst machInst, const char * instMnem, 133 bool isMicro, bool isDelayed, bool isFirst, bool isLast, 134 std::string _message, uint8_t _cc) : 135 %(base_class)s(machInst, "%(func)s", instMnem, 136 isMicro, isDelayed, isFirst, isLast, _message, _cc) 137 { 138 buildMe(); 139 } 140}}; 141 142output decoder {{ 143 std::string MicroDebugBase::generateDisassembly(Addr pc, 144 const SymbolTable *symtab) const 145 { 146 std::stringstream response; 147 148 printMnemonic(response, instMnem, mnemonic); 149 response << "\"" << message << "\""; 150 151 return response.str(); 152 } 153}}; 154 155let {{ 156 class MicroDebug(X86Microop): 157 def __init__(self, message, flags=None): 158 self.message = message 159 if flags: 160 if not isinstance(flags, (list, tuple)): 161 raise Exception, "flags must be a list or tuple of flags" 162 self.cond = " | ".join(flags) 163 self.className += "Flags" 164 else: 165 self.cond = "0" 166 167 def getAllocator(self, *microFlags): 168 allocator = '''new %(class_name)s(machInst, macrocodeBlock 169 %(flags)s, "%(message)s", %(cc)s)''' % { 170 "class_name" : self.className, 171 "flags" : self.microFlagsText(microFlags), 172 "message" : self.message, 173 "cc" : self.cond} 174 return allocator 175 176 exec_output = "" 177 header_output = "" 178 decoder_output = "" 179 180 def buildDebugMicro(func): 181 global exec_output, header_output, decoder_output 182 183 iop = InstObjParams(func, "Micro%sFlags" % func.capitalize(), 184 "MicroDebugBase", 185 {"code": "", 186 "func": func, 187 "cond_test": "checkCondition(ccFlagBits, cc)"}) 188 exec_output += MicroDebugExecute.subst(iop) 189 header_output += MicroDebugDeclare.subst(iop) 190 decoder_output += MicroDebugConstructor.subst(iop) 191 192 iop = InstObjParams(func, "Micro%s" % func.capitalize(), 193 "MicroDebugBase", 194 {"code": "", 195 "func": func, 196 "cond_test": "true"}) 197 exec_output += MicroDebugExecute.subst(iop) 198 header_output += MicroDebugDeclare.subst(iop) 199 decoder_output += MicroDebugConstructor.subst(iop) 200 201 class MicroDebugChild(MicroDebug): 202 className = "Micro%s" % func.capitalize() 203 204 global microopClasses 205 microopClasses[func] = MicroDebugChild 206 207 buildDebugMicro("panic") 208 buildDebugMicro("fatal") 209 buildDebugMicro("warn") 210 buildDebugMicro("warn_once") 211}}; 212