nativetrace.cc revision 7629:0f0c231e3e97
12139SN/A/*
22139SN/A * Copyright (c) 2007-2009 The Regents of The University of Michigan
312109SRekai.GonzalezAlberquilla@arm.com * All rights reserved.
412109SRekai.GonzalezAlberquilla@arm.com *
512109SRekai.GonzalezAlberquilla@arm.com * Redistribution and use in source and binary forms, with or without
612109SRekai.GonzalezAlberquilla@arm.com * modification, are permitted provided that the following conditions are
712109SRekai.GonzalezAlberquilla@arm.com * met: redistributions of source code must retain the above copyright
812109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer;
912109SRekai.GonzalezAlberquilla@arm.com * redistributions in binary form must reproduce the above copyright
1012109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer in the
1112109SRekai.GonzalezAlberquilla@arm.com * documentation and/or other materials provided with the distribution;
1212109SRekai.GonzalezAlberquilla@arm.com * neither the name of the copyright holders nor the names of its
1312109SRekai.GonzalezAlberquilla@arm.com * contributors may be used to endorse or promote products derived from
1412109SRekai.GonzalezAlberquilla@arm.com * this software without specific prior written permission.
152139SN/A *
162139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272139SN/A *
282139SN/A * Authors: Gabe Black
292139SN/A */
302139SN/A
312139SN/A#include "arch/x86/isa_traits.hh"
322139SN/A#include "arch/x86/nativetrace.hh"
332139SN/A#include "arch/x86/regs/float.hh"
342139SN/A#include "arch/x86/regs/int.hh"
352139SN/A#include "cpu/thread_context.hh"
362139SN/A#include "params/X86NativeTrace.hh"
372139SN/A
382139SN/Anamespace Trace {
392139SN/A
402665Ssaidi@eecs.umich.eduvoid
412665Ssaidi@eecs.umich.eduX86NativeTrace::ThreadState::update(NativeTrace *parent)
422139SN/A{
434202Sbinkertn@umich.edu    parent->read(this, sizeof(*this));
448961Sgblack@eecs.umich.edu    rax = X86ISA::gtoh(rax);
4510196SCurtis.Dunham@arm.com    rcx = X86ISA::gtoh(rcx);
462139SN/A    rdx = X86ISA::gtoh(rdx);
474202Sbinkertn@umich.edu    rbx = X86ISA::gtoh(rbx);
482152SN/A    rsp = X86ISA::gtoh(rsp);
492152SN/A    rbp = X86ISA::gtoh(rbp);
502139SN/A    rsi = X86ISA::gtoh(rsi);
512139SN/A    rdi = X86ISA::gtoh(rdi);
522139SN/A    r8 = X86ISA::gtoh(r8);
532139SN/A    r9 = X86ISA::gtoh(r9);
542139SN/A    r10 = X86ISA::gtoh(r10);
552152SN/A    r11 = X86ISA::gtoh(r11);
562152SN/A    r12 = X86ISA::gtoh(r12);
572139SN/A    r13 = X86ISA::gtoh(r13);
5812015Sgabeblack@google.com    r14 = X86ISA::gtoh(r14);
5912015Sgabeblack@google.com    r15 = X86ISA::gtoh(r15);
609020Sgblack@eecs.umich.edu    rip = X86ISA::gtoh(rip);
614781Snate@binkert.org    //This should be expanded if x87 registers are considered
627799Sgblack@eecs.umich.edu    for (int i = 0; i < 8; i++)
634781Snate@binkert.org        mmx[i] = X86ISA::gtoh(mmx[i]);
644781Snate@binkert.org    for (int i = 0; i < 32; i++)
653170Sstever@eecs.umich.edu        xmm[i] = X86ISA::gtoh(xmm[i]);
665664Sgblack@eecs.umich.edu}
678105Sgblack@eecs.umich.edu
686179Sksewell@umich.eduvoid
694781Snate@binkert.orgX86NativeTrace::ThreadState::update(ThreadContext *tc)
7010553Salexandru.dutu@amd.com{
716329Sgblack@eecs.umich.edu    rax = tc->readIntReg(X86ISA::INTREG_RAX);
724781Snate@binkert.org    rcx = tc->readIntReg(X86ISA::INTREG_RCX);
734781Snate@binkert.org    rdx = tc->readIntReg(X86ISA::INTREG_RDX);
744781Snate@binkert.org    rbx = tc->readIntReg(X86ISA::INTREG_RBX);
754781Snate@binkert.org    rsp = tc->readIntReg(X86ISA::INTREG_RSP);
764781Snate@binkert.org    rbp = tc->readIntReg(X86ISA::INTREG_RBP);
774781Snate@binkert.org    rsi = tc->readIntReg(X86ISA::INTREG_RSI);
7812015Sgabeblack@google.com    rdi = tc->readIntReg(X86ISA::INTREG_RDI);
7912015Sgabeblack@google.com    r8 = tc->readIntReg(X86ISA::INTREG_R8);
802152SN/A    r9 = tc->readIntReg(X86ISA::INTREG_R9);
8111308Santhony.gutierrez@amd.com    r10 = tc->readIntReg(X86ISA::INTREG_R10);
8212016Sgabeblack@google.com    r11 = tc->readIntReg(X86ISA::INTREG_R11);
8312016Sgabeblack@google.com    r12 = tc->readIntReg(X86ISA::INTREG_R12);
8411308Santhony.gutierrez@amd.com    r13 = tc->readIntReg(X86ISA::INTREG_R13);
8511696Santhony.gutierrez@amd.com    r14 = tc->readIntReg(X86ISA::INTREG_R14);
8611308Santhony.gutierrez@amd.com    r15 = tc->readIntReg(X86ISA::INTREG_R15);
8712016Sgabeblack@google.com    rip = tc->readNextPC();
8812016Sgabeblack@google.com    //This should be expanded if x87 registers are considered
8911308Santhony.gutierrez@amd.com    for (int i = 0; i < 8; i++)
902152SN/A        mmx[i] = tc->readFloatRegBits(X86ISA::FLOATREG_MMX(i));
912152SN/A    for (int i = 0; i < 32; i++)
922152SN/A        xmm[i] = tc->readFloatRegBits(X86ISA::FLOATREG_XMM_BASE + i);
932152SN/A}
942152SN/A
952152SN/A
962152SN/AX86NativeTrace::X86NativeTrace(const Params *p)
972152SN/A    : NativeTrace(p)
982152SN/A{
992152SN/A    checkRcx = true;
10012222Sgabeblack@google.com    checkR11 = true;
1012152SN/A}
10212222Sgabeblack@google.com
10312222Sgabeblack@google.combool
10412222Sgabeblack@google.comX86NativeTrace::checkRcxReg(const char * name, uint64_t &mVal, uint64_t &nVal)
10512222Sgabeblack@google.com{
1062152SN/A    if(!checkRcx)
10712222Sgabeblack@google.com        checkRcx = (mVal != oldRcxVal || nVal != oldRealRcxVal);
10812222Sgabeblack@google.com    if(checkRcx)
10912222Sgabeblack@google.com        return checkReg(name, mVal, nVal);
11012222Sgabeblack@google.com    return true;
1112152SN/A}
1122152SN/A
1132152SN/Abool
1142152SN/AX86NativeTrace::checkR11Reg(const char * name, uint64_t &mVal, uint64_t &nVal)
1152152SN/A{
1162152SN/A    if(!checkR11)
11712222Sgabeblack@google.com        checkR11 = (mVal != oldR11Val || nVal != oldRealR11Val);
11812222Sgabeblack@google.com    if(checkR11)
1196993Snate@binkert.org        return checkReg(name, mVal, nVal);
1206998Snate@binkert.org    return true;
1216998Snate@binkert.org}
1226998Snate@binkert.org
12312222Sgabeblack@google.combool
12412222Sgabeblack@google.comX86NativeTrace::checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[])
12512222Sgabeblack@google.com{
1266993Snate@binkert.org    if (mXmmBuf[num * 2]     != nXmmBuf[num * 2] ||
1276993Snate@binkert.org        mXmmBuf[num * 2 + 1] != nXmmBuf[num * 2 + 1]) {
12810319SAndreas.Sandberg@ARM.com        DPRINTF(ExecRegDelta,
1296993Snate@binkert.org                "Register xmm%d should be 0x%016x%016x but is 0x%016x%016x.\n",
1302152SN/A                num, nXmmBuf[num * 2 + 1], nXmmBuf[num * 2],
13112222Sgabeblack@google.com                     mXmmBuf[num * 2 + 1], mXmmBuf[num * 2]);
1322152SN/A        return false;
13312222Sgabeblack@google.com    }
1345944Sgblack@eecs.umich.edu    return true;
13510196SCurtis.Dunham@arm.com}
13612222Sgabeblack@google.com
13712222Sgabeblack@google.comvoid
13812222Sgabeblack@google.comX86NativeTrace::check(NativeTraceRecord *record)
13912222Sgabeblack@google.com{
14010196SCurtis.Dunham@arm.com    nState.update(this);
14112222Sgabeblack@google.com    mState.update(record->getThread());
14212222Sgabeblack@google.com
14312222Sgabeblack@google.com    if(record->getStaticInst()->isSyscall())
14412222Sgabeblack@google.com    {
14510196SCurtis.Dunham@arm.com        checkRcx = false;
14612222Sgabeblack@google.com        checkR11 = false;
14712222Sgabeblack@google.com        oldRcxVal = mState.rcx;
14812222Sgabeblack@google.com        oldRealRcxVal = nState.rcx;
14912222Sgabeblack@google.com        oldR11Val = mState.r11;
15012222Sgabeblack@google.com        oldRealR11Val = nState.r11;
15112222Sgabeblack@google.com    }
15210196SCurtis.Dunham@arm.com
15312222Sgabeblack@google.com    checkReg("rax", mState.rax, nState.rax);
15412222Sgabeblack@google.com    checkRcxReg("rcx", mState.rcx, nState.rcx);
15512222Sgabeblack@google.com    checkReg("rdx", mState.rdx, nState.rdx);
15612222Sgabeblack@google.com    checkReg("rbx", mState.rbx, nState.rbx);
15712222Sgabeblack@google.com    checkReg("rsp", mState.rsp, nState.rsp);
15812222Sgabeblack@google.com    checkReg("rbp", mState.rbp, nState.rbp);
15912222Sgabeblack@google.com    checkReg("rsi", mState.rsi, nState.rsi);
16010196SCurtis.Dunham@arm.com    checkReg("rdi", mState.rdi, nState.rdi);
16112222Sgabeblack@google.com    checkReg("r8",  mState.r8,  nState.r8);
16212222Sgabeblack@google.com    checkReg("r9",  mState.r9,  nState.r9);
16312222Sgabeblack@google.com    checkReg("r10", mState.r10, nState.r10);
16412222Sgabeblack@google.com    checkR11Reg("r11", mState.r11, nState.r11);
16512222Sgabeblack@google.com    checkReg("r12", mState.r12, nState.r12);
16612222Sgabeblack@google.com    checkReg("r13", mState.r13, nState.r13);
16710196SCurtis.Dunham@arm.com    checkReg("r14", mState.r14, nState.r14);
16812222Sgabeblack@google.com    checkReg("r15", mState.r15, nState.r15);
16912222Sgabeblack@google.com    checkReg("rip", mState.rip, nState.rip);
17012222Sgabeblack@google.com    checkXMM(0, mState.xmm, nState.xmm);
17112222Sgabeblack@google.com    checkXMM(1, mState.xmm, nState.xmm);
17212222Sgabeblack@google.com    checkXMM(2, mState.xmm, nState.xmm);
17312222Sgabeblack@google.com    checkXMM(3, mState.xmm, nState.xmm);
17412222Sgabeblack@google.com    checkXMM(4, mState.xmm, nState.xmm);
17512222Sgabeblack@google.com    checkXMM(5, mState.xmm, nState.xmm);
17612222Sgabeblack@google.com    checkXMM(6, mState.xmm, nState.xmm);
17712222Sgabeblack@google.com    checkXMM(7, mState.xmm, nState.xmm);
17812222Sgabeblack@google.com    checkXMM(8, mState.xmm, nState.xmm);
17910196SCurtis.Dunham@arm.com    checkXMM(9, mState.xmm, nState.xmm);
18012222Sgabeblack@google.com    checkXMM(10, mState.xmm, nState.xmm);
18112222Sgabeblack@google.com    checkXMM(11, mState.xmm, nState.xmm);
18212222Sgabeblack@google.com    checkXMM(12, mState.xmm, nState.xmm);
18312222Sgabeblack@google.com    checkXMM(13, mState.xmm, nState.xmm);
18412222Sgabeblack@google.com    checkXMM(14, mState.xmm, nState.xmm);
18512222Sgabeblack@google.com    checkXMM(15, mState.xmm, nState.xmm);
18612222Sgabeblack@google.com}
18712222Sgabeblack@google.com
18812222Sgabeblack@google.com} /* namespace Trace */
18912222Sgabeblack@google.com
19012222Sgabeblack@google.com////////////////////////////////////////////////////////////////////////
19112222Sgabeblack@google.com//
19212222Sgabeblack@google.com//  ExeTracer Simulation Object
19312222Sgabeblack@google.com//
19412222Sgabeblack@google.comTrace::X86NativeTrace *
19512222Sgabeblack@google.comX86NativeTraceParams::create()
19612222Sgabeblack@google.com{
19712222Sgabeblack@google.com    return new Trace::X86NativeTrace(this);
19812222Sgabeblack@google.com};
19912222Sgabeblack@google.com