gem5 v24.0.0.0
Loading...
Searching...
No Matches
nativetrace.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
30
31#include "arch/x86/pcstate.hh"
33#include "arch/x86/regs/int.hh"
34#include "cpu/thread_context.hh"
35#include "debug/ExecRegDelta.hh"
36#include "params/X86NativeTrace.hh"
37#include "sim/byteswap.hh"
38
39namespace gem5
40{
41
42namespace trace {
43
44void
46{
47 parent->read(this, sizeof(*this));
48 rax = letoh(rax);
49 rcx = letoh(rcx);
50 rdx = letoh(rdx);
51 rbx = letoh(rbx);
52 rsp = letoh(rsp);
53 rbp = letoh(rbp);
54 rsi = letoh(rsi);
55 rdi = letoh(rdi);
56 r8 = letoh(r8);
57 r9 = letoh(r9);
58 r10 = letoh(r10);
59 r11 = letoh(r11);
60 r12 = letoh(r12);
61 r13 = letoh(r13);
62 r14 = letoh(r14);
63 r15 = letoh(r15);
64 rip = letoh(rip);
65 //This should be expanded if x87 registers are considered
66 for (int i = 0; i < 8; i++)
67 mmx[i] = letoh(mmx[i]);
68 for (int i = 0; i < 32; i++)
69 xmm[i] = letoh(xmm[i]);
70}
71
72void
74{
91 rip = tc->pcState().as<X86ISA::PCState>().npc();
92 //This should be expanded if x87 registers are considered
93 for (int i = 0; i < 8; i++)
94 mmx[i] = tc->getReg(X86ISA::float_reg::mmx(i));
95 for (int i = 0; i < 32; i++)
96 xmm[i] = tc->getReg(X86ISA::float_reg::xmm(i));
97}
98
99
101{
102 checkRcx = true;
103 checkR11 = true;
104}
105
106bool
107X86NativeTrace::checkRcxReg(const char * name, uint64_t &mVal, uint64_t &nVal)
108{
109 if (!checkRcx)
110 checkRcx = (mVal != oldRcxVal || nVal != oldRealRcxVal);
111 if (checkRcx)
112 return checkReg(name, mVal, nVal);
113 return true;
114}
115
116bool
117X86NativeTrace::checkR11Reg(const char * name, uint64_t &mVal, uint64_t &nVal)
118{
119 if (!checkR11)
120 checkR11 = (mVal != oldR11Val || nVal != oldRealR11Val);
121 if (checkR11)
122 return checkReg(name, mVal, nVal);
123 return true;
124}
125
126bool
127X86NativeTrace::checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[])
128{
129 if (mXmmBuf[num * 2] != nXmmBuf[num * 2] ||
130 mXmmBuf[num * 2 + 1] != nXmmBuf[num * 2 + 1]) {
131 DPRINTF(ExecRegDelta,
132 "Register xmm%d should be 0x%016x%016x but is 0x%016x%016x.\n",
133 num, nXmmBuf[num * 2 + 1], nXmmBuf[num * 2],
134 mXmmBuf[num * 2 + 1], mXmmBuf[num * 2]);
135 return false;
136 }
137 return true;
138}
139
140void
142{
143 nState.update(this);
144 mState.update(record->getThread());
145
146 if (record->getStaticInst()->isSyscall())
147 {
148 checkRcx = false;
149 checkR11 = false;
154 }
155
156 checkReg("rax", mState.rax, nState.rax);
158 checkReg("rdx", mState.rdx, nState.rdx);
159 checkReg("rbx", mState.rbx, nState.rbx);
160 checkReg("rsp", mState.rsp, nState.rsp);
161 checkReg("rbp", mState.rbp, nState.rbp);
162 checkReg("rsi", mState.rsi, nState.rsi);
163 checkReg("rdi", mState.rdi, nState.rdi);
164 checkReg("r8", mState.r8, nState.r8);
165 checkReg("r9", mState.r9, nState.r9);
166 checkReg("r10", mState.r10, nState.r10);
168 checkReg("r12", mState.r12, nState.r12);
169 checkReg("r13", mState.r13, nState.r13);
170 checkReg("r14", mState.r14, nState.r14);
171 checkReg("r15", mState.r15, nState.r15);
172 checkReg("rip", mState.rip, nState.rip);
189}
190
191} // namespace trace
192} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
virtual std::string name() const
Definition named.hh:47
Target & as()
Definition pcstate.hh:73
bool isSyscall() const
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId &reg) const
virtual const PCStateBase & pcState() const =0
ExeTracerParams Params
Definition exetrace.hh:84
ThreadContext * getThread() const
StaticInstPtr getStaticInst() const
bool checkReg(const char *regName, T &val, T &realVal)
void read(void *ptr, size_t size)
bool checkR11Reg(const char *regName, uint64_t &, uint64_t &)
bool checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[])
X86NativeTrace(const Params &p)
bool checkRcxReg(const char *regName, uint64_t &, uint64_t &)
void check(NativeTraceRecord *record)
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
static RegId xmm(int index)
Definition float.hh:165
static RegId mmx(int index)
Definition float.hh:153
constexpr RegId R12
Definition int.hh:144
constexpr RegId R9
Definition int.hh:141
constexpr RegId R8
Definition int.hh:140
constexpr RegId R14
Definition int.hh:146
constexpr RegId Rbx
Definition int.hh:135
constexpr RegId Rsi
Definition int.hh:138
constexpr RegId R15
Definition int.hh:147
constexpr RegId Rax
Definition int.hh:132
constexpr RegId Rdx
Definition int.hh:134
constexpr RegId Rsp
Definition int.hh:136
constexpr RegId Rdi
Definition int.hh:139
constexpr RegId R13
Definition int.hh:145
constexpr RegId Rbp
Definition int.hh:137
constexpr RegId R11
Definition int.hh:143
constexpr RegId R10
Definition int.hh:142
constexpr RegId Rcx
Definition int.hh:133
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
T letoh(T value)
Definition byteswap.hh:173
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0