nativetrace.cc revision 7629:0f0c231e3e97
16145SN/A/*
26145SN/A * Copyright (c) 2007-2009 The Regents of The University of Michigan
36145SN/A * All rights reserved.
46145SN/A *
56145SN/A * Redistribution and use in source and binary forms, with or without
66145SN/A * modification, are permitted provided that the following conditions are
76145SN/A * met: redistributions of source code must retain the above copyright
86145SN/A * notice, this list of conditions and the following disclaimer;
96145SN/A * redistributions in binary form must reproduce the above copyright
106145SN/A * notice, this list of conditions and the following disclaimer in the
116145SN/A * documentation and/or other materials provided with the distribution;
126145SN/A * neither the name of the copyright holders nor the names of its
136145SN/A * contributors may be used to endorse or promote products derived from
146145SN/A * this software without specific prior written permission.
156145SN/A *
166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145SN/A *
286145SN/A * Authors: Gabe Black
296145SN/A */
307054SN/A
317054SN/A#include "arch/x86/isa_traits.hh"
327054SN/A#include "arch/x86/nativetrace.hh"
337054SN/A#include "arch/x86/regs/float.hh"
347054SN/A#include "arch/x86/regs/int.hh"
357054SN/A#include "cpu/thread_context.hh"
367054SN/A#include "params/X86NativeTrace.hh"
377054SN/A
387054SN/Anamespace Trace {
396145SN/A
407054SN/Avoid
417054SN/AX86NativeTrace::ThreadState::update(NativeTrace *parent)
426145SN/A{
437002SN/A    parent->read(this, sizeof(*this));
447002SN/A    rax = X86ISA::gtoh(rax);
457454SN/A    rcx = X86ISA::gtoh(rcx);
467002SN/A    rdx = X86ISA::gtoh(rdx);
478257SBrad.Beckmann@amd.com    rbx = X86ISA::gtoh(rbx);
488608Snilay@cs.wisc.edu    rsp = X86ISA::gtoh(rsp);
497054SN/A    rbp = X86ISA::gtoh(rbp);
507054SN/A    rsi = X86ISA::gtoh(rsi);
516145SN/A    rdi = X86ISA::gtoh(rdi);
528257SBrad.Beckmann@amd.com    r8 = X86ISA::gtoh(r8);
536145SN/A    r9 = X86ISA::gtoh(r9);
546145SN/A    r10 = X86ISA::gtoh(r10);
557454SN/A    r11 = X86ISA::gtoh(r11);
566145SN/A    r12 = X86ISA::gtoh(r12);
578257SBrad.Beckmann@amd.com    r13 = X86ISA::gtoh(r13);
587054SN/A    r14 = X86ISA::gtoh(r14);
598257SBrad.Beckmann@amd.com    r15 = X86ISA::gtoh(r15);
608257SBrad.Beckmann@amd.com    rip = X86ISA::gtoh(rip);
616879SN/A    //This should be expanded if x87 registers are considered
626879SN/A    for (int i = 0; i < 8; i++)
638257SBrad.Beckmann@amd.com        mmx[i] = X86ISA::gtoh(mmx[i]);
646879SN/A    for (int i = 0; i < 32; i++)
657054SN/A        xmm[i] = X86ISA::gtoh(xmm[i]);
667054SN/A}
677054SN/A
686876SN/Avoid
696876SN/AX86NativeTrace::ThreadState::update(ThreadContext *tc)
707054SN/A{
716879SN/A    rax = tc->readIntReg(X86ISA::INTREG_RAX);
726145SN/A    rcx = tc->readIntReg(X86ISA::INTREG_RCX);
738257SBrad.Beckmann@amd.com    rdx = tc->readIntReg(X86ISA::INTREG_RDX);
747054SN/A    rbx = tc->readIntReg(X86ISA::INTREG_RBX);
757054SN/A    rsp = tc->readIntReg(X86ISA::INTREG_RSP);
766285SN/A    rbp = tc->readIntReg(X86ISA::INTREG_RBP);
777054SN/A    rsi = tc->readIntReg(X86ISA::INTREG_RSI);
786145SN/A    rdi = tc->readIntReg(X86ISA::INTREG_RDI);
797054SN/A    r8 = tc->readIntReg(X86ISA::INTREG_R8);
807054SN/A    r9 = tc->readIntReg(X86ISA::INTREG_R9);
817054SN/A    r10 = tc->readIntReg(X86ISA::INTREG_R10);
827054SN/A    r11 = tc->readIntReg(X86ISA::INTREG_R11);
837054SN/A    r12 = tc->readIntReg(X86ISA::INTREG_R12);
846881SN/A    r13 = tc->readIntReg(X86ISA::INTREG_R13);
857054SN/A    r14 = tc->readIntReg(X86ISA::INTREG_R14);
868257SBrad.Beckmann@amd.com    r15 = tc->readIntReg(X86ISA::INTREG_R15);
878257SBrad.Beckmann@amd.com    rip = tc->readNextPC();
887054SN/A    //This should be expanded if x87 registers are considered
898257SBrad.Beckmann@amd.com    for (int i = 0; i < 8; i++)
908257SBrad.Beckmann@amd.com        mmx[i] = tc->readFloatRegBits(X86ISA::FLOATREG_MMX(i));
916145SN/A    for (int i = 0; i < 32; i++)
927054SN/A        xmm[i] = tc->readFloatRegBits(X86ISA::FLOATREG_XMM_BASE + i);
937054SN/A}
947054SN/A
957054SN/A
966145SN/AX86NativeTrace::X86NativeTrace(const Params *p)
977054SN/A    : NativeTrace(p)
987054SN/A{
997054SN/A    checkRcx = true;
1007054SN/A    checkR11 = true;
1016145SN/A}
1027454SN/A
1038257SBrad.Beckmann@amd.combool
1048257SBrad.Beckmann@amd.comX86NativeTrace::checkRcxReg(const char * name, uint64_t &mVal, uint64_t &nVal)
1056881SN/A{
1067054SN/A    if(!checkRcx)
1077054SN/A        checkRcx = (mVal != oldRcxVal || nVal != oldRealRcxVal);
1088257SBrad.Beckmann@amd.com    if(checkRcx)
1098257SBrad.Beckmann@amd.com        return checkReg(name, mVal, nVal);
1108257SBrad.Beckmann@amd.com    return true;
1116145SN/A}
1126145SN/A
1137054SN/Abool
1147054SN/AX86NativeTrace::checkR11Reg(const char * name, uint64_t &mVal, uint64_t &nVal)
1156145SN/A{
1167054SN/A    if(!checkR11)
1177054SN/A        checkR11 = (mVal != oldR11Val || nVal != oldRealR11Val);
1187054SN/A    if(checkR11)
1196145SN/A        return checkReg(name, mVal, nVal);
1206145SN/A    return true;
1217054SN/A}
122
123bool
124X86NativeTrace::checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[])
125{
126    if (mXmmBuf[num * 2]     != nXmmBuf[num * 2] ||
127        mXmmBuf[num * 2 + 1] != nXmmBuf[num * 2 + 1]) {
128        DPRINTF(ExecRegDelta,
129                "Register xmm%d should be 0x%016x%016x but is 0x%016x%016x.\n",
130                num, nXmmBuf[num * 2 + 1], nXmmBuf[num * 2],
131                     mXmmBuf[num * 2 + 1], mXmmBuf[num * 2]);
132        return false;
133    }
134    return true;
135}
136
137void
138X86NativeTrace::check(NativeTraceRecord *record)
139{
140    nState.update(this);
141    mState.update(record->getThread());
142
143    if(record->getStaticInst()->isSyscall())
144    {
145        checkRcx = false;
146        checkR11 = false;
147        oldRcxVal = mState.rcx;
148        oldRealRcxVal = nState.rcx;
149        oldR11Val = mState.r11;
150        oldRealR11Val = nState.r11;
151    }
152
153    checkReg("rax", mState.rax, nState.rax);
154    checkRcxReg("rcx", mState.rcx, nState.rcx);
155    checkReg("rdx", mState.rdx, nState.rdx);
156    checkReg("rbx", mState.rbx, nState.rbx);
157    checkReg("rsp", mState.rsp, nState.rsp);
158    checkReg("rbp", mState.rbp, nState.rbp);
159    checkReg("rsi", mState.rsi, nState.rsi);
160    checkReg("rdi", mState.rdi, nState.rdi);
161    checkReg("r8",  mState.r8,  nState.r8);
162    checkReg("r9",  mState.r9,  nState.r9);
163    checkReg("r10", mState.r10, nState.r10);
164    checkR11Reg("r11", mState.r11, nState.r11);
165    checkReg("r12", mState.r12, nState.r12);
166    checkReg("r13", mState.r13, nState.r13);
167    checkReg("r14", mState.r14, nState.r14);
168    checkReg("r15", mState.r15, nState.r15);
169    checkReg("rip", mState.rip, nState.rip);
170    checkXMM(0, mState.xmm, nState.xmm);
171    checkXMM(1, mState.xmm, nState.xmm);
172    checkXMM(2, mState.xmm, nState.xmm);
173    checkXMM(3, mState.xmm, nState.xmm);
174    checkXMM(4, mState.xmm, nState.xmm);
175    checkXMM(5, mState.xmm, nState.xmm);
176    checkXMM(6, mState.xmm, nState.xmm);
177    checkXMM(7, mState.xmm, nState.xmm);
178    checkXMM(8, mState.xmm, nState.xmm);
179    checkXMM(9, mState.xmm, nState.xmm);
180    checkXMM(10, mState.xmm, nState.xmm);
181    checkXMM(11, mState.xmm, nState.xmm);
182    checkXMM(12, mState.xmm, nState.xmm);
183    checkXMM(13, mState.xmm, nState.xmm);
184    checkXMM(14, mState.xmm, nState.xmm);
185    checkXMM(15, mState.xmm, nState.xmm);
186}
187
188} /* namespace Trace */
189
190////////////////////////////////////////////////////////////////////////
191//
192//  ExeTracer Simulation Object
193//
194Trace::X86NativeTrace *
195X86NativeTraceParams::create()
196{
197    return new Trace::X86NativeTrace(this);
198};
199