2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Steve Reinhardt
32 #ifndef __NATIVETRACE_HH__
33 #define __NATIVETRACE_HH__
35 #include "base/trace.hh"
36 #include "cpu/static_inst.hh"
37 #include "sim/host.hh"
38 #include "sim/insttracer.hh"
39 #include "arch/x86/intregs.hh"
40 #include "arch/x86/floatregs.hh"
49 class NativeTraceRecord : public InstRecord
55 NativeTraceRecord(NativeTrace * _parent,
56 Tick _when, ThreadContext *_thread,
57 const StaticInstPtr _staticInst, Addr _pc, bool spec,
58 const StaticInstPtr _macroStaticInst = NULL, MicroPC _upc = 0)
59 : InstRecord(_when, _thread, _staticInst, _pc, spec,
60 _macroStaticInst, _upc),
68 class NativeTrace : public InstTracer
73 ListenSocket native_listener;
77 uint64_t oldRcxVal, oldR11Val;
78 uint64_t oldRealRcxVal, oldRealR11Val;
98 //This should be expanded to 16 if x87 registers are considered
104 int bytesLeft = sizeof(ThreadState);
108 int res = read(fd, ((char *)this) + bytesRead, bytesLeft);
110 panic("Read call failed! %s\n", strerror(errno));
114 rax = TheISA::gtoh(rax);
115 rcx = TheISA::gtoh(rcx);
116 rdx = TheISA::gtoh(rdx);
117 rbx = TheISA::gtoh(rbx);
118 rsp = TheISA::gtoh(rsp);
119 rbp = TheISA::gtoh(rbp);
120 rsi = TheISA::gtoh(rsi);
121 rdi = TheISA::gtoh(rdi);
122 r8 = TheISA::gtoh(r8);
123 r9 = TheISA::gtoh(r9);
124 r10 = TheISA::gtoh(r10);
125 r11 = TheISA::gtoh(r11);
126 r12 = TheISA::gtoh(r12);
127 r13 = TheISA::gtoh(r13);
128 r14 = TheISA::gtoh(r14);
129 r15 = TheISA::gtoh(r15);
130 rip = TheISA::gtoh(rip);
131 //This should be expanded if x87 registers are considered
132 for (int i = 0; i < 8; i++)
133 mmx[i] = TheISA::gtoh(mmx[i]);
134 for (int i = 0; i < 32; i++)
135 xmm[i] = TheISA::gtoh(xmm[i]);
138 void update(ThreadContext * tc)
140 rax = tc->readIntReg(X86ISA::INTREG_RAX);
141 rcx = tc->readIntReg(X86ISA::INTREG_RCX);
142 rdx = tc->readIntReg(X86ISA::INTREG_RDX);
143 rbx = tc->readIntReg(X86ISA::INTREG_RBX);
144 rsp = tc->readIntReg(X86ISA::INTREG_RSP);
145 rbp = tc->readIntReg(X86ISA::INTREG_RBP);
146 rsi = tc->readIntReg(X86ISA::INTREG_RSI);
147 rdi = tc->readIntReg(X86ISA::INTREG_RDI);
148 r8 = tc->readIntReg(X86ISA::INTREG_R8);
149 r9 = tc->readIntReg(X86ISA::INTREG_R9);
150 r10 = tc->readIntReg(X86ISA::INTREG_R10);
151 r11 = tc->readIntReg(X86ISA::INTREG_R11);
152 r12 = tc->readIntReg(X86ISA::INTREG_R12);
153 r13 = tc->readIntReg(X86ISA::INTREG_R13);
154 r14 = tc->readIntReg(X86ISA::INTREG_R14);
155 r15 = tc->readIntReg(X86ISA::INTREG_R15);
156 rip = tc->readNextPC();
157 //This should be expanded if x87 registers are considered
158 for (int i = 0; i < 8; i++)
159 mmx[i] = tc->readFloatRegBits(X86ISA::FLOATREG_MMX(i));
160 for (int i = 0; i < 32; i++)
161 xmm[i] = tc->readFloatRegBits(X86ISA::FLOATREG_XMM_BASE + i);
174 checkReg(const char * regName, T &val, T &realVal)
178 DPRINTFN("Register %s should be %#x but is %#x.\n",
179 regName, realVal, val);
186 checkRcxReg(const char * regName, uint64_t &, uint64_t &);
189 checkR11Reg(const char * regName, uint64_t &, uint64_t &);
192 checkXMM(int num, uint64_t mXmmBuf[], uint64_t nXmmBuf[]);
194 NativeTrace(const Params *p);
197 getInstRecord(Tick when, ThreadContext *tc,
198 const StaticInstPtr staticInst, Addr pc,
199 const StaticInstPtr macroStaticInst = NULL, MicroPC upc = 0)
201 if (tc->misspeculating())
204 return new NativeTraceRecord(this, when, tc,
205 staticInst, pc, tc->misspeculating(), macroStaticInst, upc);
209 check(ThreadContext *, bool syscall);
211 friend class NativeTraceRecord;
214 /* namespace Trace */ }
216 #endif // __EXETRACE_HH__