8750e56e51671778be8c55e1ecdd28a8f4dca708
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
34 #include "config/the_isa.hh"
35 #if THE_ISA != SPARC_ISA
36 #error Legion tracing only works with SPARC simulations!
39 #include "config/full_system.hh"
41 #error Legion tracing only works in full system!
50 #include "arch/sparc/predecoder.hh"
51 #include "arch/sparc/registers.hh"
52 #include "arch/sparc/utility.hh"
53 #include "base/socket.hh"
54 #include "cpu/base.hh"
55 #include "cpu/legiontrace.hh"
56 #include "cpu/static_inst.hh"
57 #include "cpu/thread_context.hh"
58 #include "sim/system.hh"
61 #include "arch/tlb.hh"
64 //XXX This is temporary
65 #include "cpu/m5legion_interface.h"
68 using namespace TheISA
;
71 static int diffcount
= 0;
72 static bool wasMicro
= false;
76 SharedData
*shared_data
= NULL
;
81 int shmfd
= shmget('M' << 24 | getuid(), sizeof(SharedData
), 0777);
83 fatal("Couldn't get shared memory fd. Is Legion running?");
85 shared_data
= (SharedData
*)shmat(shmfd
, NULL
, SHM_RND
);
86 if (shared_data
== (SharedData
*)-1)
87 fatal("Couldn't allocate shared memory");
89 if (shared_data
->flags
!= OWN_M5
)
90 fatal("Shared memory has invalid owner");
92 if (shared_data
->version
!= VERSION
)
93 fatal("Shared Data is wrong version! M5: %d Legion: %d", VERSION
,
94 shared_data
->version
);
96 // step legion forward one cycle so we can get register values
97 shared_data
->flags
= OWN_LEGION
;
100 ////////////////////////////////////////////////////////////////////////
102 // Utility methods for pretty printing a report about a difference
105 inline char * genCenteredLabel(int length
, char * buffer
, const char * label
)
107 int labelLength
= strlen(label
);
108 assert(labelLength
<= length
);
109 int leftPad
= (length
- labelLength
) / 2;
110 int rightPad
= length
- leftPad
- labelLength
;
112 sprintf(format
, "%%%ds%%s%%%ds", leftPad
, rightPad
);
113 sprintf(buffer
, format
, "", label
, "");
117 inline void printRegPair(ostream
& os
, char const * title
, uint64_t a
, uint64_t b
)
119 ccprintf(os
, " %16s | %#018x %s %#-018x \n",
120 title
, a
, (a
== b
) ? "|" : "X", b
);
123 inline void printColumnLabels(ostream
& os
)
125 static char * regLabel
= genCenteredLabel(16, new char[17], "Register");
126 static char * m5Label
= genCenteredLabel(18, new char[18], "M5");
127 static char * legionLabel
= genCenteredLabel(18, new char[18], "Legion");
128 ccprintf(os
, " %s | %s | %s \n", regLabel
, m5Label
, legionLabel
);
129 ccprintf(os
, "--------------------+-----------------------+-----------------------\n");
132 inline void printSectionHeader(ostream
& os
, const char * name
)
134 char sectionString
[70];
135 genCenteredLabel(69, sectionString
, name
);
136 ccprintf(os
, "====================================================================\n");
137 ccprintf(os
, "%69s\n", sectionString
);
138 ccprintf(os
, "====================================================================\n");
141 inline void printLevelHeader(ostream
& os
, int level
)
143 char sectionString
[70];
145 sprintf(levelName
, "Trap stack level %d", level
);
146 genCenteredLabel(69, sectionString
, levelName
);
147 ccprintf(os
, "====================================================================\n");
148 ccprintf(os
, "%69s\n", sectionString
);
149 ccprintf(os
, "====================================================================\n");
153 Trace::LegionTraceRecord::dump()
155 ostream
&outs
= Trace::output();
157 static TheISA::Predecoder
predecoder(NULL
);
159 bool compared
= false;
162 bool diffInst
= false;
163 bool diffIntRegs
= false;
164 bool diffFpRegs
= false;
165 bool diffTpc
= false;
166 bool diffTnpc
= false;
167 bool diffTstate
= false;
169 bool diffTba
= false;
170 bool diffHpstate
= false;
171 bool diffHtstate
= false;
172 bool diffHtba
= false;
173 bool diffPstate
= false;
175 bool diffFsr
= false;
176 bool diffCcr
= false;
179 bool diffAsi
= false;
180 bool diffPil
= false;
181 bool diffCwp
= false;
182 bool diffCansave
= false;
183 bool diffCanrestore
= false;
184 bool diffOtherwin
= false;
185 bool diffCleanwin
= false;
186 bool diffTlb
= false;
192 // We took a trap on a micro-op...
193 if (wasMicro
&& !staticInst
->isMicroop())
195 // let's skip comparing this tick
197 if (shared_data
->flags
== OWN_M5
) {
198 shared_data
->flags
= OWN_LEGION
;
205 if (staticInst
->isLastMicroop())
207 else if (staticInst
->isMicroop())
211 if(!staticInst
->isMicroop() || staticInst
->isLastMicroop()) {
213 if (shared_data
->flags
== OWN_M5
) {
214 m5Pc
= pc
.instAddr() & SparcISA::PAddrImplMask
;
215 if (bits(shared_data
->pstate
,3,3)) {
218 lgnPc
= shared_data
->pc
& SparcISA::PAddrImplMask
;
222 if (shared_data
->cycle_count
!=
223 thread
->getCpuPtr()->instCount())
226 if (shared_data
->instruction
!=
227 (SparcISA::MachInst
)staticInst
->machInst
) {
230 // assume we have %g0 working correctly
231 for (int i
= 1; i
< TheISA::NumIntArchRegs
; i
++) {
232 if (thread
->readIntReg(i
) != shared_data
->intregs
[i
]) {
236 for (int i
= 0; i
< TheISA::NumFloatRegs
/2; i
++) {
237 if (thread
->readFloatRegBits(i
*2) !=
238 shared_data
->fpregs
[i
]) {
243 thread
->readMiscRegNoEffect(MISCREG_TL
);
244 if (oldTl
!= shared_data
->tl
)
246 for (int i
= 1; i
<= MaxTL
; i
++) {
247 thread
->setMiscRegNoEffect(MISCREG_TL
, i
);
248 if (thread
->readMiscRegNoEffect(MISCREG_TPC
) !=
249 shared_data
->tpc
[i
-1])
251 if (thread
->readMiscRegNoEffect(MISCREG_TNPC
) !=
252 shared_data
->tnpc
[i
-1])
254 if (thread
->readMiscRegNoEffect(MISCREG_TSTATE
) !=
255 shared_data
->tstate
[i
-1])
257 if (thread
->readMiscRegNoEffect(MISCREG_TT
) !=
258 shared_data
->tt
[i
-1])
260 if (thread
->readMiscRegNoEffect(MISCREG_HTSTATE
) !=
261 shared_data
->htstate
[i
-1])
264 thread
->setMiscRegNoEffect(MISCREG_TL
, oldTl
);
266 if(shared_data
->tba
!= thread
->readMiscRegNoEffect(MISCREG_TBA
))
268 //When the hpstate register is read by an instruction,
269 //legion has bit 11 set. When it's in storage, it doesn't.
270 //Since we don't directly support seperate interpretations
271 //of the registers like that, the bit is always set to 1 and
272 //we just don't compare it. It's not supposed to matter
274 if((shared_data
->hpstate
| (1 << 11)) !=
275 thread
->readMiscRegNoEffect(MISCREG_HPSTATE
))
277 if(shared_data
->htba
!=
278 thread
->readMiscRegNoEffect(MISCREG_HTBA
))
280 if(shared_data
->pstate
!=
281 thread
->readMiscRegNoEffect(MISCREG_PSTATE
))
283 //if(shared_data->y !=
284 // thread->readMiscRegNoEffect(MISCREG_Y))
286 thread
->readIntReg(NumIntArchRegs
+ 1))
288 if(shared_data
->fsr
!=
289 thread
->readMiscRegNoEffect(MISCREG_FSR
)) {
291 if (mbits(shared_data
->fsr
, 63,10) ==
292 mbits(thread
->readMiscRegNoEffect(MISCREG_FSR
),
294 thread
->setMiscRegNoEffect(MISCREG_FSR
,
299 //if(shared_data->ccr !=
300 // thread->readMiscRegNoEffect(MISCREG_CCR))
301 if(shared_data
->ccr
!=
302 thread
->readIntReg(NumIntArchRegs
+ 2))
304 if(shared_data
->gl
!=
305 thread
->readMiscRegNoEffect(MISCREG_GL
))
307 if(shared_data
->asi
!=
308 thread
->readMiscRegNoEffect(MISCREG_ASI
))
310 if(shared_data
->pil
!=
311 thread
->readMiscRegNoEffect(MISCREG_PIL
))
313 if(shared_data
->cwp
!=
314 thread
->readMiscRegNoEffect(MISCREG_CWP
))
316 //if(shared_data->cansave !=
317 // thread->readMiscRegNoEffect(MISCREG_CANSAVE))
318 if(shared_data
->cansave
!=
319 thread
->readIntReg(NumIntArchRegs
+ 3))
321 //if(shared_data->canrestore !=
322 // thread->readMiscRegNoEffect(MISCREG_CANRESTORE))
323 if(shared_data
->canrestore
!=
324 thread
->readIntReg(NumIntArchRegs
+ 4))
325 diffCanrestore
= true;
326 //if(shared_data->otherwin !=
327 // thread->readMiscRegNoEffect(MISCREG_OTHERWIN))
328 if(shared_data
->otherwin
!=
329 thread
->readIntReg(NumIntArchRegs
+ 6))
331 //if(shared_data->cleanwin !=
332 // thread->readMiscRegNoEffect(MISCREG_CLEANWIN))
333 if(shared_data
->cleanwin
!=
334 thread
->readIntReg(NumIntArchRegs
+ 5))
337 for (int i
= 0; i
< 64; i
++) {
338 if (shared_data
->itb
[i
] !=
339 thread
->getITBPtr()->TteRead(i
))
341 if (shared_data
->dtb
[i
] !=
342 thread
->getDTBPtr()->TteRead(i
))
346 if (diffPC
|| diffCC
|| diffInst
||
347 diffIntRegs
|| diffFpRegs
||
348 diffTpc
|| diffTnpc
|| diffTstate
|| diffTt
||
349 diffHpstate
|| diffHtstate
|| diffHtba
||
350 diffPstate
|| diffY
|| diffCcr
|| diffTl
|| diffFsr
||
351 diffGl
|| diffAsi
|| diffPil
|| diffCwp
||
352 diffCansave
|| diffCanrestore
||
353 diffOtherwin
|| diffCleanwin
|| diffTlb
) {
355 outs
<< "Differences found between M5 and Legion:";
361 outs
<< " [Instruction]";
363 outs
<< " [IntRegs]";
375 outs
<< " [Hpstate]";
377 outs
<< " [Htstate]";
399 outs
<< " [Cansave]";
401 outs
<< " [Canrestore]";
403 outs
<< " [Otherwin]";
405 outs
<< " [Cleanwin]";
408 outs
<< endl
<< endl
;
410 outs
<< right
<< setfill(' ') << setw(15)
411 << "M5 PC: " << "0x"<< setw(16) << setfill('0')
412 << hex
<< m5Pc
<< endl
;
413 outs
<< setfill(' ') << setw(15)
414 << "Legion PC: " << "0x"
415 << setw(16) << setfill('0') << hex
416 << lgnPc
<< endl
<< endl
;
418 outs
<< right
<< setfill(' ') << setw(15)
420 << setw(16) << setfill('0') << hex
421 << thread
->getCpuPtr()->instCount() << endl
;
422 outs
<< setfill(' ') << setw(15)
423 << "Legion CC: " << "0x"
424 << setw(16) << setfill('0') << hex
425 << shared_data
->cycle_count
<< endl
<< endl
;
427 outs
<< setfill(' ') << setw(15)
428 << "M5 Inst: " << "0x"
429 << setw(8) << setfill('0') << hex
430 << staticInst
->machInst
431 << staticInst
->disassemble(m5Pc
, debugSymbolTable
)
434 predecoder
.setTC(thread
);
435 predecoder
.moreBytes(m5Pc
, m5Pc
, shared_data
->instruction
);
437 assert(predecoder
.extMachInstReady());
440 StaticInstPtr legionInst
=
441 StaticInst::decode(predecoder
.getExtMachInst(tempPC
),
443 outs
<< setfill(' ') << setw(15)
445 << "0x" << setw(8) << setfill('0') << hex
446 << shared_data
->instruction
447 << legionInst
->disassemble(lgnPc
, debugSymbolTable
)
450 printSectionHeader(outs
, "General State");
451 printColumnLabels(outs
);
452 printRegPair(outs
, "HPstate",
453 thread
->readMiscRegNoEffect(MISCREG_HPSTATE
),
454 shared_data
->hpstate
| (1 << 11));
455 printRegPair(outs
, "Htba",
456 thread
->readMiscRegNoEffect(MISCREG_HTBA
),
458 printRegPair(outs
, "Pstate",
459 thread
->readMiscRegNoEffect(MISCREG_PSTATE
),
460 shared_data
->pstate
);
461 printRegPair(outs
, "Y",
462 //thread->readMiscRegNoEffect(MISCREG_Y),
463 thread
->readIntReg(NumIntArchRegs
+ 1),
465 printRegPair(outs
, "FSR",
466 thread
->readMiscRegNoEffect(MISCREG_FSR
),
468 printRegPair(outs
, "Ccr",
469 //thread->readMiscRegNoEffect(MISCREG_CCR),
470 thread
->readIntReg(NumIntArchRegs
+ 2),
472 printRegPair(outs
, "Tl",
473 thread
->readMiscRegNoEffect(MISCREG_TL
),
475 printRegPair(outs
, "Gl",
476 thread
->readMiscRegNoEffect(MISCREG_GL
),
478 printRegPair(outs
, "Asi",
479 thread
->readMiscRegNoEffect(MISCREG_ASI
),
481 printRegPair(outs
, "Pil",
482 thread
->readMiscRegNoEffect(MISCREG_PIL
),
484 printRegPair(outs
, "Cwp",
485 thread
->readMiscRegNoEffect(MISCREG_CWP
),
487 printRegPair(outs
, "Cansave",
488 //thread->readMiscRegNoEffect(MISCREG_CANSAVE),
489 thread
->readIntReg(NumIntArchRegs
+ 3),
490 shared_data
->cansave
);
491 printRegPair(outs
, "Canrestore",
492 //thread->readMiscRegNoEffect(MISCREG_CANRESTORE),
493 thread
->readIntReg(NumIntArchRegs
+ 4),
494 shared_data
->canrestore
);
495 printRegPair(outs
, "Otherwin",
496 //thread->readMiscRegNoEffect(MISCREG_OTHERWIN),
497 thread
->readIntReg(NumIntArchRegs
+ 6),
498 shared_data
->otherwin
);
499 printRegPair(outs
, "Cleanwin",
500 //thread->readMiscRegNoEffect(MISCREG_CLEANWIN),
501 thread
->readIntReg(NumIntArchRegs
+ 5),
502 shared_data
->cleanwin
);
504 for (int i
= 1; i
<= MaxTL
; i
++) {
505 printLevelHeader(outs
, i
);
506 printColumnLabels(outs
);
507 thread
->setMiscRegNoEffect(MISCREG_TL
, i
);
508 printRegPair(outs
, "Tpc",
509 thread
->readMiscRegNoEffect(MISCREG_TPC
),
510 shared_data
->tpc
[i
-1]);
511 printRegPair(outs
, "Tnpc",
512 thread
->readMiscRegNoEffect(MISCREG_TNPC
),
513 shared_data
->tnpc
[i
-1]);
514 printRegPair(outs
, "Tstate",
515 thread
->readMiscRegNoEffect(MISCREG_TSTATE
),
516 shared_data
->tstate
[i
-1]);
517 printRegPair(outs
, "Tt",
518 thread
->readMiscRegNoEffect(MISCREG_TT
),
519 shared_data
->tt
[i
-1]);
520 printRegPair(outs
, "Htstate",
521 thread
->readMiscRegNoEffect(MISCREG_HTSTATE
),
522 shared_data
->htstate
[i
-1]);
524 thread
->setMiscRegNoEffect(MISCREG_TL
, oldTl
);
527 printSectionHeader(outs
, "General Purpose Registers");
528 static const char * regtypes
[4] =
529 {"%g", "%o", "%l", "%i"};
530 for(int y
= 0; y
< 4; y
++) {
531 for(int x
= 0; x
< 8; x
++) {
533 sprintf(label
, "%s%d", regtypes
[y
], x
);
534 printRegPair(outs
, label
,
535 thread
->readIntReg(y
*8+x
),
536 shared_data
->intregs
[y
*8+x
]);
540 for (int x
= 0; x
< 32; x
++) {
542 sprintf(label
, "%%f%d", x
);
543 printRegPair(outs
, label
,
544 thread
->readFloatRegBits(x
*2),
545 shared_data
->fpregs
[x
]);
549 printColumnLabels(outs
);
551 for (int x
= 0; x
< 64; x
++) {
552 if (shared_data
->itb
[x
] !=
553 ULL(0xFFFFFFFFFFFFFFFF) ||
554 thread
->getITBPtr()->TteRead(x
) !=
555 ULL(0xFFFFFFFFFFFFFFFF)) {
556 sprintf(label
, "I-TLB:%02d", x
);
557 printRegPair(outs
, label
,
558 thread
->getITBPtr()->TteRead(x
),
559 shared_data
->itb
[x
]);
562 for (int x
= 0; x
< 64; x
++) {
563 if (shared_data
->dtb
[x
] !=
564 ULL(0xFFFFFFFFFFFFFFFF) ||
565 thread
->getDTBPtr()->TteRead(x
) !=
566 ULL(0xFFFFFFFFFFFFFFFF)) {
567 sprintf(label
, "D-TLB:%02d", x
);
568 printRegPair(outs
, label
,
569 thread
->getDTBPtr()->TteRead(x
),
570 shared_data
->dtb
[x
]);
573 thread
->getITBPtr()->dumpAll();
574 thread
->getDTBPtr()->dumpAll();
579 fatal("Differences found between Legion and M5\n");
584 shared_data
->flags
= OWN_LEGION
;
590 /* namespace Trace */ }
592 ////////////////////////////////////////////////////////////////////////
594 // ExeTracer Simulation Object
597 LegionTraceParams::create()
599 return new Trace::LegionTrace(this);