nativetrace.cc revision 4776
15222Sksewell@umich.edu/* 25222Sksewell@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan 35222Sksewell@umich.edu * All rights reserved. 45222Sksewell@umich.edu * 55222Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 65222Sksewell@umich.edu * modification, are permitted provided that the following conditions are 75222Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 85222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 95222Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 105222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 115222Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 125222Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 135222Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 145222Sksewell@umich.edu * this software without specific prior written permission. 155222Sksewell@umich.edu * 165222Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175222Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185222Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195222Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205222Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215222Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225222Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235222Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245222Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255222Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265222Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275222Sksewell@umich.edu * 285222Sksewell@umich.edu * Authors: Steve Reinhardt 295222Sksewell@umich.edu * Lisa Hsu 305222Sksewell@umich.edu * Nathan Binkert 315222Sksewell@umich.edu * Steve Raasch 325222Sksewell@umich.edu */ 335222Sksewell@umich.edu 345222Sksewell@umich.edu#include <errno.h> 355222Sksewell@umich.edu 365222Sksewell@umich.edu#include "arch/regfile.hh" 375222Sksewell@umich.edu#include "arch/utility.hh" 385222Sksewell@umich.edu#include "base/loader/symtab.hh" 395222Sksewell@umich.edu#include "base/socket.hh" 405222Sksewell@umich.edu#include "cpu/nativetrace.hh" 415222Sksewell@umich.edu#include "cpu/static_inst.hh" 425222Sksewell@umich.edu#include "cpu/thread_context.hh" 435222Sksewell@umich.edu#include "params/NativeTrace.hh" 445222Sksewell@umich.edu 455222Sksewell@umich.edu//XXX This is temporary 465222Sksewell@umich.edu#include "arch/isa_specific.hh" 475222Sksewell@umich.edu 485222Sksewell@umich.eduusing namespace std; 495222Sksewell@umich.eduusing namespace TheISA; 505222Sksewell@umich.edu 515222Sksewell@umich.edunamespace Trace { 525222Sksewell@umich.edu 535222Sksewell@umich.eduNativeTrace::NativeTrace(const std::string & _name) : InstTracer(_name) 545222Sksewell@umich.edu{ 555222Sksewell@umich.edu int port = 8000; 565222Sksewell@umich.edu while(!native_listener.listen(port, true)) 575222Sksewell@umich.edu { 585222Sksewell@umich.edu DPRINTF(GDBMisc, "Can't bind port %d\n", port); 595222Sksewell@umich.edu port++; 605222Sksewell@umich.edu } 615222Sksewell@umich.edu ccprintf(cerr, "Listening for native process on port %d\n", port); 625222Sksewell@umich.edu fd = native_listener.accept(); 635222Sksewell@umich.edu} 645222Sksewell@umich.edu 655222Sksewell@umich.edubool 665222Sksewell@umich.eduNativeTraceRecord::checkIntReg(const char * regName, int index, int size) 675222Sksewell@umich.edu{ 685222Sksewell@umich.edu uint64_t regVal; 695222Sksewell@umich.edu int res = read(parent->fd, ®Val, size); 705222Sksewell@umich.edu if(res < 0) 715222Sksewell@umich.edu panic("Read call failed! %s\n", strerror(errno)); 725222Sksewell@umich.edu regVal = TheISA::gtoh(regVal); 735222Sksewell@umich.edu uint64_t realRegVal = thread->readIntReg(index); 745222Sksewell@umich.edu if(regVal != realRegVal) 755222Sksewell@umich.edu { 765222Sksewell@umich.edu DPRINTFN("Register %s should be %#x but is %#x.\n", 775222Sksewell@umich.edu regName, regVal, realRegVal); 785222Sksewell@umich.edu return false; 795222Sksewell@umich.edu } 805222Sksewell@umich.edu return true; 815222Sksewell@umich.edu} 825222Sksewell@umich.edu 835222Sksewell@umich.edubool NativeTraceRecord::checkPC(const char * regName, int size) 845222Sksewell@umich.edu{ 855222Sksewell@umich.edu uint64_t regVal; 865222Sksewell@umich.edu int res = read(parent->fd, ®Val, size); 875222Sksewell@umich.edu if(res < 0) 885222Sksewell@umich.edu panic("Read call failed! %s\n", strerror(errno)); 895222Sksewell@umich.edu regVal = TheISA::gtoh(regVal); 905222Sksewell@umich.edu uint64_t realRegVal = thread->readNextPC(); 915222Sksewell@umich.edu if(regVal != realRegVal) 925222Sksewell@umich.edu { 935222Sksewell@umich.edu DPRINTFN("%s should be %#x but is %#x.\n", 945222Sksewell@umich.edu regName, regVal, realRegVal); 955222Sksewell@umich.edu return false; 965222Sksewell@umich.edu } 975222Sksewell@umich.edu return true; 985222Sksewell@umich.edu} 995222Sksewell@umich.edu 1005222Sksewell@umich.eduvoid 1015222Sksewell@umich.eduTrace::NativeTraceRecord::dump() 1025222Sksewell@umich.edu{ 1035222Sksewell@umich.edu// ostream &outs = Trace::output(); 1045222Sksewell@umich.edu 1055222Sksewell@umich.edu //Don't print what happens for each micro-op, just print out 1065222Sksewell@umich.edu //once at the last op, and for regular instructions. 1075222Sksewell@umich.edu if(!staticInst->isMicroop() || staticInst->isLastMicroop()) 1085222Sksewell@umich.edu { 1095222Sksewell@umich.edu checkIntReg("rax", INTREG_RAX, sizeof(uint64_t)); 1105222Sksewell@umich.edu checkIntReg("rbx", INTREG_RBX, sizeof(uint64_t)); 1115222Sksewell@umich.edu checkIntReg("rcx", INTREG_RCX, sizeof(uint64_t)); 1125222Sksewell@umich.edu checkIntReg("rdx", INTREG_RDX, sizeof(uint64_t)); 1135222Sksewell@umich.edu checkIntReg("rsp", INTREG_RSP, sizeof(uint64_t)); 1145222Sksewell@umich.edu checkIntReg("rbp", INTREG_RBP, sizeof(uint64_t)); 1155222Sksewell@umich.edu checkIntReg("rsi", INTREG_RSI, sizeof(uint64_t)); 1165222Sksewell@umich.edu checkIntReg("rdi", INTREG_RDI, sizeof(uint64_t)); 1175222Sksewell@umich.edu checkIntReg("r8", INTREG_R8, sizeof(uint64_t)); 1185222Sksewell@umich.edu checkIntReg("r9", INTREG_R9, sizeof(uint64_t)); 1195222Sksewell@umich.edu checkIntReg("r10", INTREG_R10, sizeof(uint64_t)); 1205222Sksewell@umich.edu checkIntReg("r11", INTREG_R11, sizeof(uint64_t)); 1215222Sksewell@umich.edu checkIntReg("r12", INTREG_R12, sizeof(uint64_t)); 1225222Sksewell@umich.edu checkIntReg("r13", INTREG_R13, sizeof(uint64_t)); 1235222Sksewell@umich.edu checkIntReg("r14", INTREG_R14, sizeof(uint64_t)); 1245222Sksewell@umich.edu checkIntReg("r15", INTREG_R15, sizeof(uint64_t)); 1255222Sksewell@umich.edu checkPC("rip", sizeof(uint64_t)); 1265222Sksewell@umich.edu#if THE_ISA == SPARC_ISA 1275222Sksewell@umich.edu /*for(int f = 0; f <= 62; f+=2) 1285222Sksewell@umich.edu { 1295222Sksewell@umich.edu uint64_t regVal; 1305222Sksewell@umich.edu int res = read(fd, ®Val, sizeof(regVal)); 1315222Sksewell@umich.edu if(res < 0) 1325222Sksewell@umich.edu panic("First read call failed! %s\n", strerror(errno)); 1335222Sksewell@umich.edu regVal = TheISA::gtoh(regVal); 1345222Sksewell@umich.edu uint64_t realRegVal = thread->readFloatRegBits(f, 64); 1355222Sksewell@umich.edu if(regVal != realRegVal) 1365222Sksewell@umich.edu { 1375222Sksewell@umich.edu DPRINTF(ExecRegDelta, "Register f%d should be %#x but is %#x.\n", f, regVal, realRegVal); 1385222Sksewell@umich.edu } 1395222Sksewell@umich.edu }*/ 1405222Sksewell@umich.edu uint64_t regVal; 1415222Sksewell@umich.edu int res = read(fd, ®Val, sizeof(regVal)); 1425222Sksewell@umich.edu if(res < 0) 1435222Sksewell@umich.edu panic("First read call failed! %s\n", strerror(errno)); 1445222Sksewell@umich.edu regVal = TheISA::gtoh(regVal); 1455222Sksewell@umich.edu uint64_t realRegVal = thread->readNextPC(); 1465222Sksewell@umich.edu if(regVal != realRegVal) 147 { 148 DPRINTF(ExecRegDelta, 149 "Register pc should be %#x but is %#x.\n", 150 regVal, realRegVal); 151 } 152 res = read(fd, ®Val, sizeof(regVal)); 153 if(res < 0) 154 panic("First read call failed! %s\n", strerror(errno)); 155 regVal = TheISA::gtoh(regVal); 156 realRegVal = thread->readNextNPC(); 157 if(regVal != realRegVal) 158 { 159 DPRINTF(ExecRegDelta, 160 "Register npc should be %#x but is %#x.\n", 161 regVal, realRegVal); 162 } 163 res = read(fd, ®Val, sizeof(regVal)); 164 if(res < 0) 165 panic("First read call failed! %s\n", strerror(errno)); 166 regVal = TheISA::gtoh(regVal); 167 realRegVal = thread->readIntReg(SparcISA::NumIntArchRegs + 2); 168 if((regVal & 0xF) != (realRegVal & 0xF)) 169 { 170 DPRINTF(ExecRegDelta, 171 "Register ccr should be %#x but is %#x.\n", 172 regVal, realRegVal); 173 } 174#endif 175 } 176} 177 178/* namespace Trace */ } 179 180//////////////////////////////////////////////////////////////////////// 181// 182// ExeTracer Simulation Object 183// 184Trace::NativeTrace * 185NativeTraceParams::create() 186{ 187 return new Trace::NativeTrace(name); 188}; 189