debug.isa revision 10196:be0e1724eb39
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        typedef GenericISA::M5DebugFault::DebugFunc DebugFunc;
49        DebugFunc func;
50        std::string message;
51        uint8_t cc;
52
53      public:
54        MicroDebugBase(ExtMachInst machInst, const char * mnem,
55                const char * instMnem, uint64_t setFlags,
56                DebugFunc _func, std::string _message, uint8_t _cc) :
57            X86MicroopBase(machInst, mnem, instMnem, setFlags, No_OpClass),
58                    func(_func), message(_message), cc(_cc)
59        {}
60
61        std::string
62        generateDisassembly(Addr pc, const SymbolTable *symtab) const
63        {
64            std::stringstream response;
65
66            printMnemonic(response, instMnem, mnemonic);
67            response << "\"" << message << "\"";
68
69            return response.str();
70        }
71    };
72}};
73
74def template MicroDebugDeclare {{
75    class %(class_name)s : public %(base_class)s
76    {
77      public:
78        %(class_name)s(ExtMachInst _machInst, const char * instMnem,
79                uint64_t setFlags, std::string _message, uint8_t _cc);
80
81        %(BasicExecDeclare)s
82    };
83}};
84
85def template MicroDebugExecute {{
86        Fault
87        %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
88                Trace::InstRecord *traceData) const
89        {
90            %(op_decl)s
91            %(op_rd)s
92            if (%(cond_test)s) {
93                return new GenericISA::M5DebugFault(func, message);
94            } else {
95                return NoFault;
96            }
97        }
98}};
99
100def template MicroDebugConstructor {{
101    %(class_name)s::%(class_name)s(
102            ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
103            std::string _message, uint8_t _cc) :
104        %(base_class)s(machInst, "%(func)s", instMnem,
105                setFlags, %(func_num)s, _message, _cc)
106    {
107        %(constructor)s;
108    }
109}};
110
111let {{
112    class MicroDebug(X86Microop):
113        def __init__(self, message, flags=None):
114            self.message = message
115            if flags:
116                if not isinstance(flags, (list, tuple)):
117                    raise Exception, "flags must be a list or tuple of flags"
118                self.cond = " | ".join(flags)
119                self.className += "Flags"
120            else:
121                self.cond = "0"
122
123        def getAllocator(self, microFlags):
124            allocator = '''new %(class_name)s(machInst, macrocodeBlock,
125                    %(flags)s, "%(message)s", %(cc)s)''' % {
126                "class_name" : self.className,
127                "flags" : self.microFlagsText(microFlags),
128                "message" : self.message,
129                "cc" : self.cond}
130            return allocator
131
132    exec_output = ""
133    header_output = ""
134    decoder_output = ""
135
136    def buildDebugMicro(func, func_num):
137        global exec_output, header_output, decoder_output
138
139        iop = InstObjParams(func, "Micro%sFlags" % func.capitalize(),
140                "MicroDebugBase",
141                {"code": "",
142                 "func": func,
143                 "func_num": "GenericISA::M5DebugFault::%s" % func_num,
144                 "cond_test": "checkCondition(ccFlagBits | cfofBits | \
145                                              dfBit | ecfBit | ezfBit, cc)"})
146        exec_output += MicroDebugExecute.subst(iop)
147        header_output += MicroDebugDeclare.subst(iop)
148        decoder_output += MicroDebugConstructor.subst(iop)
149
150        iop = InstObjParams(func, "Micro%s" % func.capitalize(),
151                "MicroDebugBase",
152                {"code": "",
153                 "func": func,
154                 "func_num": "GenericISA::M5DebugFault::%s" % func_num,
155                 "cond_test": "true"})
156        exec_output += MicroDebugExecute.subst(iop)
157        header_output += MicroDebugDeclare.subst(iop)
158        decoder_output += MicroDebugConstructor.subst(iop)
159
160        class MicroDebugChild(MicroDebug):
161            className = "Micro%s" % func.capitalize()
162
163        global microopClasses
164        microopClasses[func] = MicroDebugChild
165
166    buildDebugMicro("panic", "PanicFunc")
167    buildDebugMicro("fatal", "FatalFunc")
168    buildDebugMicro("warn", "WarnFunc")
169    buildDebugMicro("warn_once", "WarnOnceFunc")
170}};
171