debug.isa revision 5591
15425Sgblack@eecs.umich.edu// Copyright (c) 2008 The Hewlett-Packard Development Company 25425Sgblack@eecs.umich.edu// All rights reserved. 35425Sgblack@eecs.umich.edu// 45425Sgblack@eecs.umich.edu// Redistribution and use of this software in source and binary forms, 55425Sgblack@eecs.umich.edu// with or without modification, are permitted provided that the 65425Sgblack@eecs.umich.edu// following conditions are met: 75425Sgblack@eecs.umich.edu// 85425Sgblack@eecs.umich.edu// The software must be used only for Non-Commercial Use which means any 95425Sgblack@eecs.umich.edu// use which is NOT directed to receiving any direct monetary 105425Sgblack@eecs.umich.edu// compensation for, or commercial advantage from such use. Illustrative 115425Sgblack@eecs.umich.edu// examples of non-commercial use are academic research, personal study, 125425Sgblack@eecs.umich.edu// teaching, education and corporate research & development. 135425Sgblack@eecs.umich.edu// Illustrative examples of commercial use are distributing products for 145425Sgblack@eecs.umich.edu// commercial advantage and providing services using the software for 155425Sgblack@eecs.umich.edu// commercial advantage. 165425Sgblack@eecs.umich.edu// 175425Sgblack@eecs.umich.edu// If you wish to use this software or functionality therein that may be 185425Sgblack@eecs.umich.edu// covered by patents for commercial use, please contact: 195425Sgblack@eecs.umich.edu// Director of Intellectual Property Licensing 205425Sgblack@eecs.umich.edu// Office of Strategy and Technology 215425Sgblack@eecs.umich.edu// Hewlett-Packard Company 225425Sgblack@eecs.umich.edu// 1501 Page Mill Road 235425Sgblack@eecs.umich.edu// Palo Alto, California 94304 245425Sgblack@eecs.umich.edu// 255425Sgblack@eecs.umich.edu// Redistributions of source code must retain the above copyright notice, 265425Sgblack@eecs.umich.edu// this list of conditions and the following disclaimer. Redistributions 275425Sgblack@eecs.umich.edu// in binary form must reproduce the above copyright notice, this list of 285425Sgblack@eecs.umich.edu// conditions and the following disclaimer in the documentation and/or 295425Sgblack@eecs.umich.edu// other materials provided with the distribution. Neither the name of 305425Sgblack@eecs.umich.edu// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 315425Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from 325425Sgblack@eecs.umich.edu// this software without specific prior written permission. No right of 335425Sgblack@eecs.umich.edu// sublicense is granted herewith. Derivatives of the software and 345425Sgblack@eecs.umich.edu// output created using the software may be prepared, but only for 355425Sgblack@eecs.umich.edu// Non-Commercial Uses. Derivatives of the software may be shared with 365425Sgblack@eecs.umich.edu// others provided: (i) the others agree to abide by the list of 375425Sgblack@eecs.umich.edu// conditions herein which includes the Non-Commercial Use restrictions; 385425Sgblack@eecs.umich.edu// and (ii) such Derivatives of the software include the above copyright 395425Sgblack@eecs.umich.edu// notice to acknowledge the contribution from this software where 405425Sgblack@eecs.umich.edu// applicable, this list of conditions and the disclaimer below. 415425Sgblack@eecs.umich.edu// 425425Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 435425Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 445425Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 455425Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 465425Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 475425Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 485425Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 495425Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 505425Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 515425Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 525425Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 535425Sgblack@eecs.umich.edu// 545425Sgblack@eecs.umich.edu// Authors: Gabe Black 555425Sgblack@eecs.umich.edu 565425Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////////// 575425Sgblack@eecs.umich.edu// 585425Sgblack@eecs.umich.edu// Debug Microops 595425Sgblack@eecs.umich.edu// 605425Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////////// 615425Sgblack@eecs.umich.edu 625425Sgblack@eecs.umich.eduoutput header {{ 635425Sgblack@eecs.umich.edu class MicroDebugBase : public X86ISA::X86MicroopBase 645425Sgblack@eecs.umich.edu { 655425Sgblack@eecs.umich.edu protected: 665425Sgblack@eecs.umich.edu std::string message; 675425Sgblack@eecs.umich.edu uint8_t cc; 685425Sgblack@eecs.umich.edu 695425Sgblack@eecs.umich.edu public: 705425Sgblack@eecs.umich.edu MicroDebugBase(ExtMachInst _machInst, const char * mnem, 715425Sgblack@eecs.umich.edu const char * instMnem, 725425Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 735425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc); 745425Sgblack@eecs.umich.edu 755425Sgblack@eecs.umich.edu MicroDebugBase(ExtMachInst _machInst, const char * mnem, 765425Sgblack@eecs.umich.edu const char * instMnem, std::string _message, uint8_t _cc); 775425Sgblack@eecs.umich.edu 785425Sgblack@eecs.umich.edu std::string generateDisassembly(Addr pc, 795425Sgblack@eecs.umich.edu const SymbolTable *symtab) const; 805425Sgblack@eecs.umich.edu }; 815425Sgblack@eecs.umich.edu}}; 825425Sgblack@eecs.umich.edu 835425Sgblack@eecs.umich.edudef template MicroDebugDeclare {{ 845425Sgblack@eecs.umich.edu class %(class_name)s : public %(base_class)s 855425Sgblack@eecs.umich.edu { 865425Sgblack@eecs.umich.edu private: 875425Sgblack@eecs.umich.edu void buildMe(); 885425Sgblack@eecs.umich.edu public: 895425Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, const char * instMnem, 905425Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 915425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc); 925425Sgblack@eecs.umich.edu 935425Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, const char * instMnem, 945425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc); 955425Sgblack@eecs.umich.edu 965425Sgblack@eecs.umich.edu %(BasicExecDeclare)s 975425Sgblack@eecs.umich.edu }; 985425Sgblack@eecs.umich.edu}}; 995425Sgblack@eecs.umich.edu 1005425Sgblack@eecs.umich.edudef template MicroDebugExecute {{ 1015425Sgblack@eecs.umich.edu Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 1025425Sgblack@eecs.umich.edu Trace::InstRecord *traceData) const 1035425Sgblack@eecs.umich.edu { 1045425Sgblack@eecs.umich.edu %(op_decl)s 1055425Sgblack@eecs.umich.edu %(op_rd)s 1065425Sgblack@eecs.umich.edu if (%(cond_test)s) { 1075591Sgblack@eecs.umich.edu %(func)s("%s\n", message); 1085425Sgblack@eecs.umich.edu } 1095425Sgblack@eecs.umich.edu return NoFault; 1105425Sgblack@eecs.umich.edu } 1115425Sgblack@eecs.umich.edu}}; 1125425Sgblack@eecs.umich.edu 1135425Sgblack@eecs.umich.eduoutput decoder {{ 1145425Sgblack@eecs.umich.edu inline MicroDebugBase::MicroDebugBase( 1155425Sgblack@eecs.umich.edu ExtMachInst machInst, const char * mnem, const char * instMnem, 1165425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc) : 1175425Sgblack@eecs.umich.edu X86MicroopBase(machInst, mnem, instMnem, 1185425Sgblack@eecs.umich.edu false, false, false, false, No_OpClass), 1195425Sgblack@eecs.umich.edu message(_message), cc(_cc) 1205425Sgblack@eecs.umich.edu { 1215425Sgblack@eecs.umich.edu } 1225425Sgblack@eecs.umich.edu 1235425Sgblack@eecs.umich.edu inline MicroDebugBase::MicroDebugBase( 1245425Sgblack@eecs.umich.edu ExtMachInst machInst, const char * mnem, const char * instMnem, 1255425Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 1265425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc) : 1275425Sgblack@eecs.umich.edu X86MicroopBase(machInst, mnem, instMnem, 1285425Sgblack@eecs.umich.edu isMicro, isDelayed, isFirst, isLast, No_OpClass), 1295425Sgblack@eecs.umich.edu message(_message), cc(_cc) 1305425Sgblack@eecs.umich.edu { 1315425Sgblack@eecs.umich.edu } 1325425Sgblack@eecs.umich.edu}}; 1335425Sgblack@eecs.umich.edu 1345425Sgblack@eecs.umich.edudef template MicroDebugConstructor {{ 1355425Sgblack@eecs.umich.edu 1365425Sgblack@eecs.umich.edu inline void %(class_name)s::buildMe() 1375425Sgblack@eecs.umich.edu { 1385425Sgblack@eecs.umich.edu %(constructor)s; 1395425Sgblack@eecs.umich.edu } 1405425Sgblack@eecs.umich.edu 1415425Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 1425425Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 1435425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc) : 1445425Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(func)s", instMnem, _message, _cc) 1455425Sgblack@eecs.umich.edu { 1465425Sgblack@eecs.umich.edu buildMe(); 1475425Sgblack@eecs.umich.edu } 1485425Sgblack@eecs.umich.edu 1495425Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 1505425Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 1515425Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 1525425Sgblack@eecs.umich.edu std::string _message, uint8_t _cc) : 1535425Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(func)s", instMnem, 1545425Sgblack@eecs.umich.edu isMicro, isDelayed, isFirst, isLast, _message, _cc) 1555425Sgblack@eecs.umich.edu { 1565425Sgblack@eecs.umich.edu buildMe(); 1575425Sgblack@eecs.umich.edu } 1585425Sgblack@eecs.umich.edu}}; 1595425Sgblack@eecs.umich.edu 1605425Sgblack@eecs.umich.eduoutput decoder {{ 1615425Sgblack@eecs.umich.edu std::string MicroDebugBase::generateDisassembly(Addr pc, 1625425Sgblack@eecs.umich.edu const SymbolTable *symtab) const 1635425Sgblack@eecs.umich.edu { 1645425Sgblack@eecs.umich.edu std::stringstream response; 1655425Sgblack@eecs.umich.edu 1665425Sgblack@eecs.umich.edu printMnemonic(response, instMnem, mnemonic); 1675425Sgblack@eecs.umich.edu response << "\"" << message << "\""; 1685425Sgblack@eecs.umich.edu 1695425Sgblack@eecs.umich.edu return response.str(); 1705425Sgblack@eecs.umich.edu } 1715425Sgblack@eecs.umich.edu}}; 1725425Sgblack@eecs.umich.edu 1735425Sgblack@eecs.umich.edulet {{ 1745425Sgblack@eecs.umich.edu class MicroDebug(X86Microop): 1755425Sgblack@eecs.umich.edu def __init__(self, message, flags=None): 1765425Sgblack@eecs.umich.edu self.message = message 1775425Sgblack@eecs.umich.edu if flags: 1785425Sgblack@eecs.umich.edu if not isinstance(flags, (list, tuple)): 1795425Sgblack@eecs.umich.edu raise Exception, "flags must be a list or tuple of flags" 1805425Sgblack@eecs.umich.edu self.cond = " | ".join(flags) 1815425Sgblack@eecs.umich.edu self.className += "Flags" 1825425Sgblack@eecs.umich.edu else: 1835425Sgblack@eecs.umich.edu self.cond = "0" 1845425Sgblack@eecs.umich.edu 1855425Sgblack@eecs.umich.edu def getAllocator(self, *microFlags): 1865425Sgblack@eecs.umich.edu allocator = '''new %(class_name)s(machInst, mnemonic 1875425Sgblack@eecs.umich.edu %(flags)s, "%(message)s", %(cc)s)''' % { 1885425Sgblack@eecs.umich.edu "class_name" : self.className, 1895425Sgblack@eecs.umich.edu "flags" : self.microFlagsText(microFlags), 1905425Sgblack@eecs.umich.edu "message" : self.message, 1915425Sgblack@eecs.umich.edu "cc" : self.cond} 1925425Sgblack@eecs.umich.edu return allocator 1935425Sgblack@eecs.umich.edu 1945425Sgblack@eecs.umich.edu exec_output = "" 1955425Sgblack@eecs.umich.edu header_output = "" 1965425Sgblack@eecs.umich.edu decoder_output = "" 1975425Sgblack@eecs.umich.edu 1985425Sgblack@eecs.umich.edu def buildDebugMicro(func): 1995425Sgblack@eecs.umich.edu global exec_output, header_output, decoder_output 2005425Sgblack@eecs.umich.edu 2015425Sgblack@eecs.umich.edu iop = InstObjParams(func, "Micro%sFlags" % func.capitalize(), 2025425Sgblack@eecs.umich.edu "MicroDebugBase", 2035425Sgblack@eecs.umich.edu {"code": "", 2045425Sgblack@eecs.umich.edu "func": func, 2055425Sgblack@eecs.umich.edu "cond_test": "checkCondition(ccFlagBits, cc)"}) 2065425Sgblack@eecs.umich.edu exec_output += MicroDebugExecute.subst(iop) 2075425Sgblack@eecs.umich.edu header_output += MicroDebugDeclare.subst(iop) 2085425Sgblack@eecs.umich.edu decoder_output += MicroDebugConstructor.subst(iop) 2095425Sgblack@eecs.umich.edu 2105425Sgblack@eecs.umich.edu iop = InstObjParams(func, "Micro%s" % func.capitalize(), 2115425Sgblack@eecs.umich.edu "MicroDebugBase", 2125425Sgblack@eecs.umich.edu {"code": "", 2135425Sgblack@eecs.umich.edu "func": func, 2145425Sgblack@eecs.umich.edu "cond_test": "true"}) 2155425Sgblack@eecs.umich.edu exec_output += MicroDebugExecute.subst(iop) 2165425Sgblack@eecs.umich.edu header_output += MicroDebugDeclare.subst(iop) 2175425Sgblack@eecs.umich.edu decoder_output += MicroDebugConstructor.subst(iop) 2185425Sgblack@eecs.umich.edu 2195425Sgblack@eecs.umich.edu class MicroDebugChild(MicroDebug): 2205425Sgblack@eecs.umich.edu className = "Micro%s" % func.capitalize() 2215425Sgblack@eecs.umich.edu 2225425Sgblack@eecs.umich.edu global microopClasses 2235425Sgblack@eecs.umich.edu microopClasses[func] = MicroDebugChild 2245425Sgblack@eecs.umich.edu 2255425Sgblack@eecs.umich.edu buildDebugMicro("panic") 2265425Sgblack@eecs.umich.edu buildDebugMicro("fatal") 2275425Sgblack@eecs.umich.edu buildDebugMicro("warn") 2285425Sgblack@eecs.umich.edu buildDebugMicro("warn_once") 2295425Sgblack@eecs.umich.edu}}; 230