debug.isa (7620:3d8a23caa1ef) debug.isa (7626:bdd926760470)
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, uint64_t setFlags,
54 std::string _message, uint8_t _cc);
55
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, uint64_t setFlags,
54 std::string _message, uint8_t _cc);
55
56 MicroDebugBase(ExtMachInst _machInst, const char * mnem,
57 const char * instMnem, std::string _message, uint8_t _cc);
58
59 std::string generateDisassembly(Addr pc,
60 const SymbolTable *symtab) const;
61 };
62}};
63
64def template MicroDebugDeclare {{
65 class %(class_name)s : public %(base_class)s
66 {
56 std::string generateDisassembly(Addr pc,
57 const SymbolTable *symtab) const;
58 };
59}};
60
61def template MicroDebugDeclare {{
62 class %(class_name)s : public %(base_class)s
63 {
67 private:
68 void buildMe();
69 public:
70 %(class_name)s(ExtMachInst _machInst, const char * instMnem,
71 uint64_t setFlags, std::string _message, uint8_t _cc);
72
64 public:
65 %(class_name)s(ExtMachInst _machInst, const char * instMnem,
66 uint64_t setFlags, std::string _message, uint8_t _cc);
67
73 %(class_name)s(ExtMachInst _machInst, const char * instMnem,
74 std::string _message, uint8_t _cc);
75
76 %(BasicExecDeclare)s
77 };
78}};
79
80def template MicroDebugExecute {{
81 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
82 Trace::InstRecord *traceData) const
83 {
84 %(op_decl)s
85 %(op_rd)s
86 if (%(cond_test)s) {
87 %(func)s("%s\n", message);
88 }
89 return NoFault;
90 }
91}};
92
93output decoder {{
94 inline MicroDebugBase::MicroDebugBase(
95 ExtMachInst machInst, const char * mnem, const char * instMnem,
68 %(BasicExecDeclare)s
69 };
70}};
71
72def template MicroDebugExecute {{
73 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
74 Trace::InstRecord *traceData) const
75 {
76 %(op_decl)s
77 %(op_rd)s
78 if (%(cond_test)s) {
79 %(func)s("%s\n", message);
80 }
81 return NoFault;
82 }
83}};
84
85output decoder {{
86 inline MicroDebugBase::MicroDebugBase(
87 ExtMachInst machInst, const char * mnem, const char * instMnem,
96 std::string _message, uint8_t _cc) :
97 X86MicroopBase(machInst, mnem, instMnem, 0, No_OpClass),
98 message(_message), cc(_cc)
99 {
100 }
101
102 inline MicroDebugBase::MicroDebugBase(
103 ExtMachInst machInst, const char * mnem, const char * instMnem,
104 uint64_t setFlags, std::string _message, uint8_t _cc) :
105 X86MicroopBase(machInst, mnem, instMnem,
106 setFlags, No_OpClass),
107 message(_message), cc(_cc)
108 {
109 }
110}};
111
112def template MicroDebugConstructor {{
88 uint64_t setFlags, std::string _message, uint8_t _cc) :
89 X86MicroopBase(machInst, mnem, instMnem,
90 setFlags, No_OpClass),
91 message(_message), cc(_cc)
92 {
93 }
94}};
95
96def template MicroDebugConstructor {{
113
114 inline void %(class_name)s::buildMe()
115 {
116 %(constructor)s;
117 }
118
119 inline %(class_name)s::%(class_name)s(
97 inline %(class_name)s::%(class_name)s(
120 ExtMachInst machInst, const char * instMnem,
121 std::string _message, uint8_t _cc) :
122 %(base_class)s(machInst, "%(func)s", instMnem, _message, _cc)
123 {
124 buildMe();
125 }
126
127 inline %(class_name)s::%(class_name)s(
128 ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
129 std::string _message, uint8_t _cc) :
130 %(base_class)s(machInst, "%(func)s", instMnem,
131 setFlags, _message, _cc)
132 {
98 ExtMachInst machInst, const char * instMnem, uint64_t setFlags,
99 std::string _message, uint8_t _cc) :
100 %(base_class)s(machInst, "%(func)s", instMnem,
101 setFlags, _message, _cc)
102 {
133 buildMe();
103 %(constructor)s;
134 }
135}};
136
137output decoder {{
138 std::string MicroDebugBase::generateDisassembly(Addr pc,
139 const SymbolTable *symtab) const
140 {
141 std::stringstream response;
142
143 printMnemonic(response, instMnem, mnemonic);
144 response << "\"" << message << "\"";
145
146 return response.str();
147 }
148}};
149
150let {{
151 class MicroDebug(X86Microop):
152 def __init__(self, message, flags=None):
153 self.message = message
154 if flags:
155 if not isinstance(flags, (list, tuple)):
156 raise Exception, "flags must be a list or tuple of flags"
157 self.cond = " | ".join(flags)
158 self.className += "Flags"
159 else:
160 self.cond = "0"
161
162 def getAllocator(self, microFlags):
163 allocator = '''new %(class_name)s(machInst, macrocodeBlock,
164 %(flags)s, "%(message)s", %(cc)s)''' % {
165 "class_name" : self.className,
166 "flags" : self.microFlagsText(microFlags),
167 "message" : self.message,
168 "cc" : self.cond}
169 return allocator
170
171 exec_output = ""
172 header_output = ""
173 decoder_output = ""
174
175 def buildDebugMicro(func):
176 global exec_output, header_output, decoder_output
177
178 iop = InstObjParams(func, "Micro%sFlags" % func.capitalize(),
179 "MicroDebugBase",
180 {"code": "",
181 "func": func,
182 "cond_test": "checkCondition(ccFlagBits, cc)"})
183 exec_output += MicroDebugExecute.subst(iop)
184 header_output += MicroDebugDeclare.subst(iop)
185 decoder_output += MicroDebugConstructor.subst(iop)
186
187 iop = InstObjParams(func, "Micro%s" % func.capitalize(),
188 "MicroDebugBase",
189 {"code": "",
190 "func": func,
191 "cond_test": "true"})
192 exec_output += MicroDebugExecute.subst(iop)
193 header_output += MicroDebugDeclare.subst(iop)
194 decoder_output += MicroDebugConstructor.subst(iop)
195
196 class MicroDebugChild(MicroDebug):
197 className = "Micro%s" % func.capitalize()
198
199 global microopClasses
200 microopClasses[func] = MicroDebugChild
201
202 buildDebugMicro("panic")
203 buildDebugMicro("fatal")
204 buildDebugMicro("warn")
205 buildDebugMicro("warn_once")
206}};
104 }
105}};
106
107output decoder {{
108 std::string MicroDebugBase::generateDisassembly(Addr pc,
109 const SymbolTable *symtab) const
110 {
111 std::stringstream response;
112
113 printMnemonic(response, instMnem, mnemonic);
114 response << "\"" << message << "\"";
115
116 return response.str();
117 }
118}};
119
120let {{
121 class MicroDebug(X86Microop):
122 def __init__(self, message, flags=None):
123 self.message = message
124 if flags:
125 if not isinstance(flags, (list, tuple)):
126 raise Exception, "flags must be a list or tuple of flags"
127 self.cond = " | ".join(flags)
128 self.className += "Flags"
129 else:
130 self.cond = "0"
131
132 def getAllocator(self, microFlags):
133 allocator = '''new %(class_name)s(machInst, macrocodeBlock,
134 %(flags)s, "%(message)s", %(cc)s)''' % {
135 "class_name" : self.className,
136 "flags" : self.microFlagsText(microFlags),
137 "message" : self.message,
138 "cc" : self.cond}
139 return allocator
140
141 exec_output = ""
142 header_output = ""
143 decoder_output = ""
144
145 def buildDebugMicro(func):
146 global exec_output, header_output, decoder_output
147
148 iop = InstObjParams(func, "Micro%sFlags" % func.capitalize(),
149 "MicroDebugBase",
150 {"code": "",
151 "func": func,
152 "cond_test": "checkCondition(ccFlagBits, cc)"})
153 exec_output += MicroDebugExecute.subst(iop)
154 header_output += MicroDebugDeclare.subst(iop)
155 decoder_output += MicroDebugConstructor.subst(iop)
156
157 iop = InstObjParams(func, "Micro%s" % func.capitalize(),
158 "MicroDebugBase",
159 {"code": "",
160 "func": func,
161 "cond_test": "true"})
162 exec_output += MicroDebugExecute.subst(iop)
163 header_output += MicroDebugDeclare.subst(iop)
164 decoder_output += MicroDebugConstructor.subst(iop)
165
166 class MicroDebugChild(MicroDebug):
167 className = "Micro%s" % func.capitalize()
168
169 global microopClasses
170 microopClasses[func] = MicroDebugChild
171
172 buildDebugMicro("panic")
173 buildDebugMicro("fatal")
174 buildDebugMicro("warn")
175 buildDebugMicro("warn_once")
176}};