nativetrace.hh (6216:2f4020838149) nativetrace.hh (6365:a3037fa327a0)
1/*
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
2 * Copyright (c) 2006-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

--- 9 unchanged lines hidden (view full) ---

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 *
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

--- 9 unchanged lines hidden (view full) ---

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 * Authors: Steve Reinhardt
29 * Nathan Binkert
28 * Authors: Gabe Black
30 */
31
32#ifndef __CPU_NATIVETRACE_HH__
33#define __CPU_NATIVETRACE_HH__
34
29 */
30
31#ifndef __CPU_NATIVETRACE_HH__
32#define __CPU_NATIVETRACE_HH__
33
35#include "arch/x86/floatregs.hh"
36#include "arch/x86/intregs.hh"
34#include <errno.h>
35#include <unistd.h>
36
37#include "base/socket.hh"
37#include "base/trace.hh"
38#include "base/types.hh"
39#include "cpu/static_inst.hh"
40#include "sim/insttracer.hh"
41
42class ThreadContext;
43
44namespace Trace {

--- 21 unchanged lines hidden (view full) ---

66
67class NativeTrace : public InstTracer
68{
69 protected:
70 int fd;
71
72 ListenSocket native_listener;
73
38#include "base/trace.hh"
39#include "base/types.hh"
40#include "cpu/static_inst.hh"
41#include "sim/insttracer.hh"
42
43class ThreadContext;
44
45namespace Trace {

--- 21 unchanged lines hidden (view full) ---

67
68class NativeTrace : public InstTracer
69{
70 protected:
71 int fd;
72
73 ListenSocket native_listener;
74
74 bool checkRcx;
75 bool checkR11;
76 uint64_t oldRcxVal, oldR11Val;
77 uint64_t oldRealRcxVal, oldRealR11Val;
75 public:
78
76
79 struct ThreadState {
80 uint64_t rax;
81 uint64_t rcx;
82 uint64_t rdx;
83 uint64_t rbx;
84 uint64_t rsp;
85 uint64_t rbp;
86 uint64_t rsi;
87 uint64_t rdi;
88 uint64_t r8;
89 uint64_t r9;
90 uint64_t r10;
91 uint64_t r11;
92 uint64_t r12;
93 uint64_t r13;
94 uint64_t r14;
95 uint64_t r15;
96 uint64_t rip;
97 //This should be expanded to 16 if x87 registers are considered
98 uint64_t mmx[8];
99 uint64_t xmm[32];
77 NativeTrace(const Params *p);
78 virtual ~NativeTrace() {}
100
79
101 void update(int fd)
102 {
103 int bytesLeft = sizeof(ThreadState);
104 int bytesRead = 0;
105 do
106 {
107 int res = read(fd, ((char *)this) + bytesRead, bytesLeft);
108 if(res < 0)
109 panic("Read call failed! %s\n", strerror(errno));
110 bytesLeft -= res;
111 bytesRead += res;
112 } while(bytesLeft);
113 rax = TheISA::gtoh(rax);
114 rcx = TheISA::gtoh(rcx);
115 rdx = TheISA::gtoh(rdx);
116 rbx = TheISA::gtoh(rbx);
117 rsp = TheISA::gtoh(rsp);
118 rbp = TheISA::gtoh(rbp);
119 rsi = TheISA::gtoh(rsi);
120 rdi = TheISA::gtoh(rdi);
121 r8 = TheISA::gtoh(r8);
122 r9 = TheISA::gtoh(r9);
123 r10 = TheISA::gtoh(r10);
124 r11 = TheISA::gtoh(r11);
125 r12 = TheISA::gtoh(r12);
126 r13 = TheISA::gtoh(r13);
127 r14 = TheISA::gtoh(r14);
128 r15 = TheISA::gtoh(r15);
129 rip = TheISA::gtoh(rip);
130 //This should be expanded if x87 registers are considered
131 for (int i = 0; i < 8; i++)
132 mmx[i] = TheISA::gtoh(mmx[i]);
133 for (int i = 0; i < 32; i++)
134 xmm[i] = TheISA::gtoh(xmm[i]);
135 }
80 NativeTraceRecord *
81 getInstRecord(Tick when, ThreadContext *tc,
82 const StaticInstPtr staticInst, Addr pc,
83 const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0)
84 {
85 if (tc->misspeculating())
86 return NULL;
136
87
137 void update(ThreadContext * tc)
138 {
139 rax = tc->readIntReg(X86ISA::INTREG_RAX);
140 rcx = tc->readIntReg(X86ISA::INTREG_RCX);
141 rdx = tc->readIntReg(X86ISA::INTREG_RDX);
142 rbx = tc->readIntReg(X86ISA::INTREG_RBX);
143 rsp = tc->readIntReg(X86ISA::INTREG_RSP);
144 rbp = tc->readIntReg(X86ISA::INTREG_RBP);
145 rsi = tc->readIntReg(X86ISA::INTREG_RSI);
146 rdi = tc->readIntReg(X86ISA::INTREG_RDI);
147 r8 = tc->readIntReg(X86ISA::INTREG_R8);
148 r9 = tc->readIntReg(X86ISA::INTREG_R9);
149 r10 = tc->readIntReg(X86ISA::INTREG_R10);
150 r11 = tc->readIntReg(X86ISA::INTREG_R11);
151 r12 = tc->readIntReg(X86ISA::INTREG_R12);
152 r13 = tc->readIntReg(X86ISA::INTREG_R13);
153 r14 = tc->readIntReg(X86ISA::INTREG_R14);
154 r15 = tc->readIntReg(X86ISA::INTREG_R15);
155 rip = tc->readNextPC();
156 //This should be expanded if x87 registers are considered
157 for (int i = 0; i < 8; i++)
158 mmx[i] = tc->readFloatRegBits(X86ISA::FLOATREG_MMX(i));
159 for (int i = 0; i < 32; i++)
160 xmm[i] = tc->readFloatRegBits(X86ISA::FLOATREG_XMM_BASE + i);
161 }
88 return new NativeTraceRecord(this, when, tc,
89 staticInst, pc, tc->misspeculating(), macroStaticInst, upc);
90 }
162
91
163 };
164
165 ThreadState nState;
166 ThreadState mState;
167
168
169 public:
170
171 template<class T>
172 bool
173 checkReg(const char * regName, T &val, T &realVal)
174 {
175 if(val != realVal)
176 {
177 DPRINTFN("Register %s should be %#x but is %#x.\n",
178 regName, realVal, val);
179 return false;
180 }
181 return true;
182 }
183
92 template<class T>
93 bool
94 checkReg(const char * regName, T &val, T &realVal)
95 {
96 if(val != realVal)
97 {
98 DPRINTFN("Register %s should be %#x but is %#x.\n",
99 regName, realVal, val);
100 return false;
101 }
102 return true;
103 }
104
184 bool
185 checkRcxReg(const char * regName, uint64_t &, uint64_t &);
186
187 bool
188 checkR11Reg(const char * regName, uint64_t &, uint64_t &);
189
190 bool
191 checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[]);
192
193 NativeTrace(const Params *p);
194
195 NativeTraceRecord *
196 getInstRecord(Tick when, ThreadContext *tc,
197 const StaticInstPtr staticInst, Addr pc,
198 const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0)
105 void
106 read(void *ptr, size_t size)
199 {
107 {
200 if (tc->misspeculating())
201 return NULL;
202
203 return new NativeTraceRecord(this, when, tc,
204 staticInst, pc, tc->misspeculating(), macroStaticInst, upc);
108 size_t soFar = 0;
109 while (soFar < size) {
110 size_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
111 if (res < 0)
112 panic("Read call failed! %s\n", strerror(errno));
113 else
114 soFar += res;
115 }
205 }
206
116 }
117
207 void
208 check(ThreadContext *, bool syscall);
209
210 friend class NativeTraceRecord;
118 virtual void
119 check(NativeTraceRecord *record) = 0;
211};
212
120};
121
213/* namespace Trace */ }
122} /* namespace Trace */
214
215#endif // __CPU_NATIVETRACE_HH__
123
124#endif // __CPU_NATIVETRACE_HH__