arch-arm,arch-x86: Added missing overrides
[gem5.git] / src / arch / x86 / isa / microops / debug.isa
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 //////////////////////////////////////////////////////////////////////////
37 //
38 // Debug Microops
39 //
40 //////////////////////////////////////////////////////////////////////////
41
42 output header {{
43 class MicroDebug : public X86ISA::X86MicroopBase
44 {
45 protected:
46 std::shared_ptr<GenericISA::M5DebugFault> fault;
47
48 public:
49 MicroDebug(ExtMachInst _machInst, const char *mnem,
50 const char *instMnem, uint64_t setFlags,
51 GenericISA::M5DebugFault *_fault);
52
53 Fault
54 execute(ExecContext *xc, Trace::InstRecord *traceData) const override
55 {
56 return fault;
57 }
58
59 std::string
60 generateDisassembly(Addr pc,
61 const Loader::SymbolTable *symtab) const override
62 {
63 std::stringstream response;
64
65 printMnemonic(response, instMnem, mnemonic);
66 response << "\"" << fault->message() << "\"";
67
68 return response.str();
69 }
70 };
71
72 class MicroDebugFlags : public MicroDebug
73 {
74 protected:
75 uint8_t cc;
76
77 public:
78 MicroDebugFlags(ExtMachInst _machInst, const char *mnem,
79 const char *instMnem, uint64_t setFlags,
80 GenericISA::M5DebugFault *_fault, uint8_t _cc);
81
82 Fault execute(ExecContext *, Trace::InstRecord *) const override;
83 };
84 }};
85
86 output decoder {{
87 MicroDebug::MicroDebug(ExtMachInst _machInst, const char *mnem,
88 const char *instMnem, uint64_t setFlags,
89 GenericISA::M5DebugFault *_fault) :
90 X86ISA::X86MicroopBase(_machInst, mnem, instMnem,
91 setFlags, No_OpClass),
92 fault(_fault)
93 {}
94 }};
95
96 def template MicroDebugFlagsExecute {{
97 Fault
98 %(class_name)s::execute(ExecContext *xc,
99 Trace::InstRecord *traceData) const
100 {
101 %(op_decl)s
102 %(op_rd)s
103 if (%(cond_test)s) {
104 return %(base_class)s::execute(xc, traceData);
105 } else {
106 return NoFault;
107 }
108 }
109 }};
110
111 def template MicroDebugFlagsConstructor {{
112 %(class_name)s::%(class_name)s(
113 ExtMachInst machInst, const char *mnem,
114 const char *instMnem, uint64_t setFlags,
115 GenericISA::M5DebugFault *_fault, uint8_t _cc) :
116 %(base_class)s(machInst, mnem, instMnem, setFlags, _fault),
117 cc(_cc)
118 {
119 %(constructor)s;
120 }
121 }};
122
123 let {{
124 iop = InstObjParams("", "MicroDebugFlags", "MicroDebug",
125 {"code": "",
126 "cond_test": "checkCondition(ccFlagBits | cfofBits | \
127 dfBit | ecfBit | ezfBit, cc)"})
128 exec_output = MicroDebugFlagsExecute.subst(iop)
129 decoder_output = MicroDebugFlagsConstructor.subst(iop)
130 }};
131
132 let {{
133 class MicroDebug(X86Microop):
134 def __init__(self, name, fault, message, once, flags):
135 self.name = name
136 self.fault = fault
137 self.message = message
138 self.once = once
139 self.flags = flags
140 if flags and not isinstance(flags, (list, tuple)):
141 raise Exception("flags must be a list or tuple of flags")
142
143 self.className = "MicroDebugFlags" if flags else "MicroDebug"
144
145 def getAllocator(self, microFlags):
146 if self.once:
147 fault_allocator_template = \
148 "new %(fault_type)s(%(token)s, %(message)s)"
149 else:
150 fault_allocator_template = \
151 "new %(fault_type)s(%(message)s)"
152 fault_allocator = fault_allocator_template % {
153 "fault_type": self.fault,
154 "token": "std::string(\"%s\")" % self.message,
155 "message": "\"%s\"" % self.message
156 }
157
158 args = ["machInst", "\"%s\"" % self.name, "macrocodeBlock",
159 self.microFlagsText(microFlags), fault_allocator]
160
161 if self.flags:
162 args.append(" | ".join(self.flags))
163
164 return "new " + self.className + "(" + ", ".join(args) + ")"
165
166 def buildDebugMicro(name, with_once=False):
167 global microopClasses
168
169 fault_class = "GenericISA::M5" + name.capitalize() + "Fault"
170
171 class MicroDebugChild(MicroDebug):
172 def __init__(self, message, flags=None):
173 super(MicroDebugChild, self).__init__(
174 name, fault_class, message, False, flags)
175
176 microopClasses[name] = MicroDebugChild
177
178 if with_once:
179 fault_once_class = \
180 "GenericISA::M5" + name.capitalize() + "OnceFault"
181 name_once = name + "_once"
182
183 class MicroDebugOnceChild(MicroDebug):
184 def __init__(self, message, flags=None):
185 super(MicroDebugOnceChild, self).__init__(
186 name_once, fault_once_class, message, True, flags)
187
188 microopClasses[name_once] = MicroDebugOnceChild
189
190 buildDebugMicro("panic")
191 buildDebugMicro("fatal")
192 buildDebugMicro("hack", True)
193 buildDebugMicro("inform", True)
194 buildDebugMicro("warn", True)
195 }};