2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
37 #include "arch/regfile.hh"
38 #include "base/loader/symtab.hh"
39 #include "cpu/base.hh"
40 #include "cpu/exetrace.hh"
41 #include "cpu/static_inst.hh"
42 #include "sim/param.hh"
43 #include "sim/system.hh"
45 //XXX This is temporary
46 #include "arch/isa_specific.hh"
49 using namespace TheISA
;
51 ////////////////////////////////////////////////////////////////////////
53 // Methods for the InstRecord object
58 Trace::InstRecord::dump(ostream
&outs
)
60 if (flags
[PRINT_REG_DELTA
])
62 #if THE_ISA == SPARC_ISA
63 //Don't print what happens for each micro-op, just print out
64 //once at the last op, and for regular instructions.
65 if(!staticInst
->isMicroOp() || staticInst
->isLastMicroOp())
67 static uint64_t regs
[32] = {
68 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, 0, 0, 0, 0};
72 static uint64_t ccr
= 0;
73 static uint64_t y
= 0;
74 static uint64_t floats
[32];
76 static const char * prefixes
[4] = {"G", "O", "L", "I"};
79 sprintf(buf
, "PC = 0x%016llx", thread
->readNextPC());
81 sprintf(buf
, " NPC = 0x%016llx", thread
->readNextNPC());
83 newVal
= thread
->readMiscReg(SparcISA::MISCREG_CCR
);
86 sprintf(buf
, " CCR = 0x%016llx", newVal
);
90 newVal
= thread
->readMiscReg(SparcISA::MISCREG_Y
);
93 sprintf(buf
, " Y = 0x%016llx", newVal
);
97 for(int y
= 0; y
< 4; y
++)
99 for(int x
= 0; x
< 8; x
++)
101 int index
= x
+ 8 * y
;
102 newVal
= thread
->readIntReg(index
);
103 if(regs
[index
] != newVal
)
105 sprintf(buf
, " %s%d = 0x%016llx", prefixes
[y
], x
, newVal
);
107 regs
[index
] = newVal
;
111 for(int y
= 0; y
< 32; y
++)
113 newVal
= thread
->readFloatRegBits(2 * y
, 64);
114 if(floats
[y
] != newVal
)
116 sprintf(buf
, " F%d = 0x%016llx", 2 * y
, newVal
);
125 else if (flags
[INTEL_FORMAT
]) {
127 bool is_trace_system
= (thread
->getCpuPtr()->system
->name() == trace_system
);
129 bool is_trace_system
= true;
131 if (is_trace_system
) {
132 ccprintf(outs
, "%7d ) ", cycle
);
133 outs
<< "0x" << hex
<< PC
<< ":\t";
134 if (staticInst
->isLoad()) {
135 outs
<< "<RD 0x" << hex
<< addr
;
137 } else if (staticInst
->isStore()) {
138 outs
<< "<WR 0x" << hex
<< addr
;
144 if (flags
[PRINT_CYCLE
])
145 ccprintf(outs
, "%7d: ", cycle
);
147 outs
<< thread
->getCpuPtr()->name() << " ";
149 if (flags
[TRACE_MISSPEC
])
150 outs
<< (misspeculating
? "-" : "+") << " ";
152 if (flags
[PRINT_THREAD_NUM
])
153 outs
<< "T" << thread
->getThreadNum() << " : ";
159 && debugSymbolTable
->findNearestSymbol(PC
, sym_str
, sym_addr
)
160 && flags
[PC_SYMBOL
]) {
162 sym_str
+= csprintf("+%d", PC
- sym_addr
);
163 outs
<< "@" << sym_str
<< " : ";
166 outs
<< "0x" << hex
<< PC
<< " : ";
170 // Print decoded instruction
173 #if defined(__GNUC__) && (__GNUC__ < 3)
174 // There's a bug in gcc 2.x library that prevents setw()
175 // from working properly on strings
176 string
mc(staticInst
->disassemble(PC
, debugSymbolTable
));
177 while (mc
.length() < 26)
181 outs
<< setw(26) << left
<< staticInst
->disassemble(PC
, debugSymbolTable
);
186 if (flags
[PRINT_OP_CLASS
]) {
187 outs
<< opClassStrings
[staticInst
->opClass()] << " : ";
190 if (flags
[PRINT_RESULT_DATA
] && data_status
!= DataInvalid
) {
193 if (data_status
== DataDouble
)
194 ccprintf(outs
, "%f", data
.as_double
);
196 ccprintf(outs
, "%#018x", data
.as_int
);
198 ccprintf(outs
, "%#018x", data
.as_int
);
202 if (flags
[PRINT_EFF_ADDR
] && addr_valid
)
203 outs
<< " A=0x" << hex
<< addr
;
205 if (flags
[PRINT_INT_REGS
] && regs_valid
) {
206 for (int i
= 0; i
< TheISA::NumIntRegs
;)
207 for (int j
= i
+ 1; i
<= j
; i
++)
208 ccprintf(outs
, "r%02d = %#018x%s", i
,
209 iregs
->regs
.readReg(i
),
210 ((i
== j
) ? "\n" : " "));
214 if (flags
[PRINT_FETCH_SEQ
] && fetch_seq_valid
)
215 outs
<< " FetchSeq=" << dec
<< fetch_seq
;
217 if (flags
[PRINT_CP_SEQ
] && cp_seq_valid
)
218 outs
<< " CPSeq=" << dec
<< cp_seq
;
228 vector
<bool> Trace::InstRecord::flags(NUM_BITS
);
229 string
Trace::InstRecord::trace_system
;
231 ////////////////////////////////////////////////////////////////////////
233 // Parameter space for per-cycle execution address tracing options.
234 // Derive from ParamContext so we can override checkParams() function.
236 class ExecutionTraceParamContext
: public ParamContext
239 ExecutionTraceParamContext(const string
&_iniSection
)
240 : ParamContext(_iniSection
)
244 void checkParams(); // defined at bottom of file
247 ExecutionTraceParamContext
exeTraceParams("exetrace");
249 Param
<bool> exe_trace_spec(&exeTraceParams
, "speculative",
250 "capture speculative instructions", true);
252 Param
<bool> exe_trace_print_cycle(&exeTraceParams
, "print_cycle",
253 "print cycle number", true);
254 Param
<bool> exe_trace_print_opclass(&exeTraceParams
, "print_opclass",
255 "print op class", true);
256 Param
<bool> exe_trace_print_thread(&exeTraceParams
, "print_thread",
257 "print thread number", true);
258 Param
<bool> exe_trace_print_effaddr(&exeTraceParams
, "print_effaddr",
259 "print effective address", true);
260 Param
<bool> exe_trace_print_data(&exeTraceParams
, "print_data",
261 "print result data", true);
262 Param
<bool> exe_trace_print_iregs(&exeTraceParams
, "print_iregs",
263 "print all integer regs", false);
264 Param
<bool> exe_trace_print_fetchseq(&exeTraceParams
, "print_fetchseq",
265 "print fetch sequence number", false);
266 Param
<bool> exe_trace_print_cp_seq(&exeTraceParams
, "print_cpseq",
267 "print correct-path sequence number", false);
268 Param
<bool> exe_trace_print_reg_delta(&exeTraceParams
, "print_reg_delta",
269 "print which registers changed to what", false);
270 Param
<bool> exe_trace_pc_symbol(&exeTraceParams
, "pc_symbol",
271 "Use symbols for the PC if available", true);
272 Param
<bool> exe_trace_intel_format(&exeTraceParams
, "intel_format",
273 "print trace in intel compatible format", false);
274 Param
<string
> exe_trace_system(&exeTraceParams
, "trace_system",
275 "print trace of which system (client or server)",
280 // Helper function for ExecutionTraceParamContext::checkParams() just
281 // to get us into the InstRecord namespace
284 Trace::InstRecord::setParams()
286 flags
[TRACE_MISSPEC
] = exe_trace_spec
;
288 flags
[PRINT_CYCLE
] = exe_trace_print_cycle
;
289 flags
[PRINT_OP_CLASS
] = exe_trace_print_opclass
;
290 flags
[PRINT_THREAD_NUM
] = exe_trace_print_thread
;
291 flags
[PRINT_RESULT_DATA
] = exe_trace_print_effaddr
;
292 flags
[PRINT_EFF_ADDR
] = exe_trace_print_data
;
293 flags
[PRINT_INT_REGS
] = exe_trace_print_iregs
;
294 flags
[PRINT_FETCH_SEQ
] = exe_trace_print_fetchseq
;
295 flags
[PRINT_CP_SEQ
] = exe_trace_print_cp_seq
;
296 flags
[PRINT_REG_DELTA
] = exe_trace_print_reg_delta
;
297 flags
[PC_SYMBOL
] = exe_trace_pc_symbol
;
298 flags
[INTEL_FORMAT
] = exe_trace_intel_format
;
299 trace_system
= exe_trace_system
;
303 ExecutionTraceParamContext::checkParams()
305 Trace::InstRecord::setParams();