debug.isa (12236:126ac9da6050) debug.isa (14277:73d5e60b3a7c)
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

--- 28 unchanged lines hidden (view full) ---

37
38//////////////////////////////////////////////////////////////////////////
39//
40// Debug Microops
41//
42//////////////////////////////////////////////////////////////////////////
43
44output header {{
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

--- 28 unchanged lines hidden (view full) ---

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