gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
remote_gdb.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2015 LabWare
3  * Copyright 2014 Google, Inc.
4  * Copyright (c) 2007 The Hewlett-Packard Development Company
5  * All rights reserved.
6  *
7  * The license below extends only to copyright in the software and shall
8  * not be construed as granting a license to any other intellectual
9  * property including but not limited to intellectual property relating
10  * to a hardware implementation of the functionality of the software
11  * licensed hereunder. You may use the software subject to the license
12  * terms below provided that you ensure that this notice is replicated
13  * unmodified and in its entirety in all distributions of the software,
14  * modified or unmodified, in source code or in binary form.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions are
18  * met: redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer;
20  * redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in the
22  * documentation and/or other materials provided with the distribution;
23  * neither the name of the copyright holders nor the names of its
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * Authors: Gabe Black
40  * Boris Shingarov
41  */
42 
43 #include "arch/x86/remote_gdb.hh"
44 
45 #include <sys/signal.h>
46 #include <unistd.h>
47 
48 #include <string>
49 
50 #include "arch/vtophys.hh"
52 #include "arch/x86/process.hh"
53 #include "arch/x86/regs/int.hh"
54 #include "arch/x86/regs/misc.hh"
55 #include "base/remote_gdb.hh"
56 #include "base/socket.hh"
57 #include "base/trace.hh"
58 #include "cpu/base.hh"
59 #include "cpu/thread_context.hh"
60 #include "debug/GDBAcc.hh"
61 #include "mem/page_table.hh"
62 #include "sim/full_system.hh"
63 
64 using namespace std;
65 using namespace X86ISA;
66 
67 RemoteGDB::RemoteGDB(System *_system, ThreadContext *c) :
68  BaseRemoteGDB(_system, c), regCache32(this), regCache64(this)
69 {}
70 
71 bool
73 {
74  if (FullSystem) {
75  Walker *walker = context->getDTBPtr()->getWalker();
76  unsigned logBytes;
77  Fault fault = walker->startFunctional(context, va, logBytes,
79  if (fault != NoFault)
80  return false;
81 
82  Addr endVa = va + len - 1;
83  if ((va & ~mask(logBytes)) == (endVa & ~mask(logBytes)))
84  return true;
85 
86  fault = walker->startFunctional(context, endVa, logBytes,
88  return fault == NoFault;
89  } else {
90  TlbEntry entry;
91  return context->getProcessPtr()->pTable->lookup(va, entry);
92  }
93 }
94 
97 {
98  HandyM5Reg m5reg = context->readMiscRegNoEffect(MISCREG_M5_REG);
99  if (m5reg.submode == SixtyFourBitMode)
100  return &regCache64;
101  else
102  return &regCache32;
103 }
104 
105 
106 
107 void
109 {
110  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
111  r.rax = context->readIntReg(INTREG_RAX);
112  r.rbx = context->readIntReg(INTREG_RBX);
113  r.rcx = context->readIntReg(INTREG_RCX);
114  r.rdx = context->readIntReg(INTREG_RDX);
115  r.rsi = context->readIntReg(INTREG_RSI);
116  r.rdi = context->readIntReg(INTREG_RDI);
117  r.rbp = context->readIntReg(INTREG_RBP);
118  r.rsp = context->readIntReg(INTREG_RSP);
119  r.r8 = context->readIntReg(INTREG_R8);
120  r.r9 = context->readIntReg(INTREG_R9);
121  r.r10 = context->readIntReg(INTREG_R10);
122  r.r11 = context->readIntReg(INTREG_R11);
123  r.r12 = context->readIntReg(INTREG_R12);
124  r.r13 = context->readIntReg(INTREG_R13);
125  r.r14 = context->readIntReg(INTREG_R14);
126  r.r15 = context->readIntReg(INTREG_R15);
127  r.rip = context->pcState().pc();
128  r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS);
129  r.cs = context->readMiscRegNoEffect(MISCREG_CS);
130  r.ss = context->readMiscRegNoEffect(MISCREG_SS);
131  r.ds = context->readMiscRegNoEffect(MISCREG_DS);
132  r.es = context->readMiscRegNoEffect(MISCREG_ES);
133  r.fs = context->readMiscRegNoEffect(MISCREG_FS);
134  r.gs = context->readMiscRegNoEffect(MISCREG_GS);
135 }
136 
137 void
139 {
140  DPRINTF(GDBAcc, "getRegs in remotegdb \n");
141  r.eax = context->readIntReg(INTREG_RAX);
142  r.ecx = context->readIntReg(INTREG_RCX);
143  r.edx = context->readIntReg(INTREG_RDX);
144  r.ebx = context->readIntReg(INTREG_RBX);
145  r.esp = context->readIntReg(INTREG_RSP);
146  r.ebp = context->readIntReg(INTREG_RBP);
147  r.esi = context->readIntReg(INTREG_RSI);
148  r.edi = context->readIntReg(INTREG_RDI);
149  r.eip = context->pcState().pc();
150  r.eflags = context->readMiscRegNoEffect(MISCREG_RFLAGS);
151  r.cs = context->readMiscRegNoEffect(MISCREG_CS);
152  r.ss = context->readMiscRegNoEffect(MISCREG_SS);
153  r.ds = context->readMiscRegNoEffect(MISCREG_DS);
154  r.es = context->readMiscRegNoEffect(MISCREG_ES);
155  r.fs = context->readMiscRegNoEffect(MISCREG_FS);
156  r.gs = context->readMiscRegNoEffect(MISCREG_GS);
157 }
158 
159 void
161 {
162  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
163  context->setIntReg(INTREG_RAX, r.rax);
164  context->setIntReg(INTREG_RBX, r.rbx);
165  context->setIntReg(INTREG_RCX, r.rcx);
166  context->setIntReg(INTREG_RDX, r.rdx);
167  context->setIntReg(INTREG_RSI, r.rsi);
168  context->setIntReg(INTREG_RDI, r.rdi);
169  context->setIntReg(INTREG_RBP, r.rbp);
170  context->setIntReg(INTREG_RSP, r.rsp);
171  context->setIntReg(INTREG_R8, r.r8);
172  context->setIntReg(INTREG_R9, r.r9);
173  context->setIntReg(INTREG_R10, r.r10);
174  context->setIntReg(INTREG_R11, r.r11);
175  context->setIntReg(INTREG_R12, r.r12);
176  context->setIntReg(INTREG_R13, r.r13);
177  context->setIntReg(INTREG_R14, r.r14);
178  context->setIntReg(INTREG_R15, r.r15);
179  context->pcState(r.rip);
180  context->setMiscReg(MISCREG_RFLAGS, r.eflags);
181  if (r.cs != context->readMiscRegNoEffect(MISCREG_CS))
182  warn("Remote gdb: Ignoring update to CS.\n");
183  if (r.ss != context->readMiscRegNoEffect(MISCREG_SS))
184  warn("Remote gdb: Ignoring update to SS.\n");
185  if (r.ds != context->readMiscRegNoEffect(MISCREG_DS))
186  warn("Remote gdb: Ignoring update to DS.\n");
187  if (r.es != context->readMiscRegNoEffect(MISCREG_ES))
188  warn("Remote gdb: Ignoring update to ES.\n");
189  if (r.fs != context->readMiscRegNoEffect(MISCREG_FS))
190  warn("Remote gdb: Ignoring update to FS.\n");
191  if (r.gs != context->readMiscRegNoEffect(MISCREG_GS))
192  warn("Remote gdb: Ignoring update to GS.\n");
193 }
194 
195 void
197 {
198  DPRINTF(GDBAcc, "setRegs in remotegdb \n");
199  context->setIntReg(INTREG_RAX, r.eax);
200  context->setIntReg(INTREG_RCX, r.ecx);
201  context->setIntReg(INTREG_RDX, r.edx);
202  context->setIntReg(INTREG_RBX, r.ebx);
203  context->setIntReg(INTREG_RSP, r.esp);
204  context->setIntReg(INTREG_RBP, r.ebp);
205  context->setIntReg(INTREG_RSI, r.esi);
206  context->setIntReg(INTREG_RDI, r.edi);
207  context->pcState(r.eip);
208  context->setMiscReg(MISCREG_RFLAGS, r.eflags);
209  if (r.cs != context->readMiscRegNoEffect(MISCREG_CS))
210  warn("Remote gdb: Ignoring update to CS.\n");
211  if (r.ss != context->readMiscRegNoEffect(MISCREG_SS))
212  warn("Remote gdb: Ignoring update to SS.\n");
213  if (r.ds != context->readMiscRegNoEffect(MISCREG_DS))
214  warn("Remote gdb: Ignoring update to DS.\n");
215  if (r.es != context->readMiscRegNoEffect(MISCREG_ES))
216  warn("Remote gdb: Ignoring update to ES.\n");
217  if (r.fs != context->readMiscRegNoEffect(MISCREG_FS))
218  warn("Remote gdb: Ignoring update to FS.\n");
219  if (r.gs != context->readMiscRegNoEffect(MISCREG_GS))
220  warn("Remote gdb: Ignoring update to GS.\n");
221 }
#define DPRINTF(x,...)
Definition: trace.hh:212
unsigned logBytes
Definition: pagetable.hh:107
decltype(nullptr) constexpr NoFault
Definition: types.hh:189
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:160
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:138
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
virtual Process * getProcessPtr()=0
Definition: system.hh:83
virtual void setIntReg(int reg_idx, uint64_t val)=0
virtual TheISA::PCState pcState()=0
BaseGdbRegCache * gdbRegs()
Definition: remote_gdb.cc:96
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Concrete subclasses of this abstract class represent how the register values are transmitted on the w...
Definition: remote_gdb.hh:183
bool acc(Addr addr, size_t len)
Definition: remote_gdb.cc:72
void setRegs(ThreadContext *) const
Set the ThreadContext's registers from the values in the raw buffer.
Definition: remote_gdb.cc:196
#define warn(...)
Definition: misc.hh:219
ThreadContext * context
Definition: remote_gdb.hh:173
Bitfield< 41 > r
Definition: misc.hh:889
void getRegs(ThreadContext *)
Fill the raw buffer from the registers in the ThreadContext.
Definition: remote_gdb.cc:108
virtual uint64_t readIntReg(int reg_idx)=0
Fault startFunctional(ThreadContext *_tc, Addr &addr, unsigned &logBytes, BaseTLB::Mode mode)
X86GdbRegCache regCache32
Definition: remote_gdb.hh:142
virtual TheISA::TLB * getDTBPtr()=0
mask
Definition: misc.hh:797
TlbEntry(Addr asn, Addr _vaddr, Addr _paddr, bool uncacheable, bool read_only)
struct X86ISA::RemoteGDB::AMD64GdbRegCache::@24 r
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Bitfield< 8 > va
Definition: miscregs.hh:1473
PageTableBase * pTable
Definition: process.hh:178
AMD64GdbRegCache regCache64
Definition: remote_gdb.hh:143
Bitfield< 29 > c
Definition: miscregs.hh:1365
Declarations of a non-full system Page Table.
virtual bool lookup(Addr vaddr, TheISA::TlbEntry &entry)=0
Lookup function.
Bitfield< 18, 16 > len
Definition: miscregs.hh:1626
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184

Generated on Fri Jun 9 2017 13:03:36 for gem5 by doxygen 1.8.6