1 // Copyright (c) 2008 The Hewlett-Packard Development Company
2 // All rights reserved.
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.
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.
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.
36 //////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////
43 class MicroDebug : public X86ISA::X86MicroopBase
46 std::shared_ptr<GenericISA::M5DebugFault> fault;
49 MicroDebug(ExtMachInst _machInst, const char *mnem,
50 const char *instMnem, uint64_t setFlags,
51 GenericISA::M5DebugFault *_fault);
54 execute(ExecContext *xc, Trace::InstRecord *traceData) const
60 generateDisassembly(Addr pc, const SymbolTable *symtab) const
62 std::stringstream response;
64 printMnemonic(response, instMnem, mnemonic);
65 response << "\"" << fault->message() << "\"";
67 return response.str();
71 class MicroDebugFlags : public MicroDebug
77 MicroDebugFlags(ExtMachInst _machInst, const char *mnem,
78 const char *instMnem, uint64_t setFlags,
79 GenericISA::M5DebugFault *_fault, uint8_t _cc);
81 Fault execute(ExecContext *, Trace::InstRecord *) const;
86 MicroDebug::MicroDebug(ExtMachInst _machInst, const char *mnem,
87 const char *instMnem, uint64_t setFlags,
88 GenericISA::M5DebugFault *_fault) :
89 X86ISA::X86MicroopBase(_machInst, mnem, instMnem,
90 setFlags, No_OpClass),
95 def template MicroDebugFlagsExecute {{
97 %(class_name)s::execute(ExecContext *xc,
98 Trace::InstRecord *traceData) const
103 return %(base_class)s::execute(xc, traceData);
110 def template MicroDebugFlagsConstructor {{
111 %(class_name)s::%(class_name)s(
112 ExtMachInst machInst, const char *mnem,
113 const char *instMnem, uint64_t setFlags,
114 GenericISA::M5DebugFault *_fault, uint8_t _cc) :
115 %(base_class)s(machInst, mnem, instMnem, setFlags, _fault),
123 iop = InstObjParams("", "MicroDebugFlags", "MicroDebug",
125 "cond_test": "checkCondition(ccFlagBits | cfofBits | \
126 dfBit | ecfBit | ezfBit, cc)"})
127 exec_output = MicroDebugFlagsExecute.subst(iop)
128 decoder_output = MicroDebugFlagsConstructor.subst(iop)
132 class MicroDebug(X86Microop):
133 def __init__(self, name, fault, message, once, flags):
136 self.message = message
139 if flags and not isinstance(flags, (list, tuple)):
140 raise Exception, "flags must be a list or tuple of flags"
142 self.className = "MicroDebugFlags" if flags else "MicroDebug"
144 def getAllocator(self, microFlags):
146 fault_allocator_template = \
147 "new %(fault_type)s(%(token)s, %(message)s)"
149 fault_allocator_template = \
150 "new %(fault_type)s(%(message)s)"
151 fault_allocator = fault_allocator_template % {
152 "fault_type": self.fault,
153 "token": "std::string(\"%s\")" % self.message,
154 "message": "\"%s\"" % self.message
157 args = ["machInst", "\"%s\"" % self.name, "macrocodeBlock",
158 self.microFlagsText(microFlags), fault_allocator]
161 args.append(" | ".join(self.flags))
163 return "new " + self.className + "(" + ", ".join(args) + ")"
165 def buildDebugMicro(name, with_once=False):
166 global microopClasses
168 fault_class = "GenericISA::M5" + name.capitalize() + "Fault"
170 class MicroDebugChild(MicroDebug):
171 def __init__(self, message, flags=None):
172 super(MicroDebugChild, self).__init__(
173 name, fault_class, message, False, flags)
175 microopClasses[name] = MicroDebugChild
179 "GenericISA::M5" + name.capitalize() + "OnceFault"
180 name_once = name + "_once"
182 class MicroDebugOnceChild(MicroDebug):
183 def __init__(self, message, flags=None):
184 super(MicroDebugOnceChild, self).__init__(
185 name_once, fault_once_class, message, True, flags)
187 microopClasses[name_once] = MicroDebugOnceChild
189 buildDebugMicro("panic")
190 buildDebugMicro("fatal")
191 buildDebugMicro("hack", True)
192 buildDebugMicro("inform", True)
193 buildDebugMicro("warn", True)